]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE when checking shift's which are behind array refs
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 16 Apr 2025 16:13:04 +0000 (17:13 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 28 Apr 2025 14:18:53 +0000 (16:18 +0200)
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.philip@googlemail.com>
gcc/rust/rust-gcc.cc
gcc/testsuite/rust/compile/issue-3664.rs [new file with mode: 0644]

index 234721c585fd6f9b9c165accd31a48f7de205534..e5319d320800743360a9186f7a1842a37c40d541 100644 (file)
@@ -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 (file)
index 0000000..c52a758
--- /dev/null
@@ -0,0 +1,5 @@
+const ARR: [usize; 1] = [2];
+
+pub fn l8() {
+    let _ = 5 << ARR[0];
+}