https://gcc.gnu.org/g:50a90f12af84ba2d203a0510bbeb41a383981303

commit 50a90f12af84ba2d203a0510bbeb41a383981303
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Wed Apr 16 17:13:04 2025 +0100

    gccrs: Fix ICE when checking shift's which are behind array refs
    
    I copied a bad form of this check from the c front-end this updates it
    to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first
    place.
    
    Fixes Rust-GCC#3664
    
    gcc/rust/ChangeLog:
    
            * rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an 
integer
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-3664.rs: New test.
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/rust-gcc.cc                     | 1 +
 gcc/testsuite/rust/compile/issue-3664.rs | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 524cee71a6e8..990c78675487 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1109,6 +1109,7 @@ arithmetic_or_logical_expression 
(ArithmeticOrLogicalOperator op, tree left,
       rust_error_at (location, "division by zero");
     }
   else if (op == ArithmeticOrLogicalOperator::LEFT_SHIFT
+          && TREE_CODE (right) == INTEGER_CST
           && (compare_tree_int (right, TYPE_PRECISION (TREE_TYPE (ret))) >= 0))
     {
       rust_error_at (location, "left shift count >= width of type");
diff --git a/gcc/testsuite/rust/compile/issue-3664.rs 
b/gcc/testsuite/rust/compile/issue-3664.rs
new file mode 100644
index 000000000000..c52a75805afd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3664.rs
@@ -0,0 +1,5 @@
+const ARR: [usize; 1] = [2];
+
+pub fn l8() {
+    let _ = 5 << ARR[0];
+}

Reply via email to