]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE in array ref constexpr
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 28 Mar 2025 16:59:33 +0000 (16:59 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 31 Mar 2025 19:07:24 +0000 (21:07 +0200)
Since 898d55ad7e2 was fixed to remove the VIEW_CONVERT_EXPR from
array expressions we can now turn on the array element access
const expr.

Fixes Rust-GCC#3563

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_store_expression): turn this back on

gcc/testsuite/ChangeLog:

* rust/compile/issue-3563.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-constexpr.cc
gcc/testsuite/rust/compile/issue-3563.rs [new file with mode: 0644]

index 2f2bbbd921d170072b5ae1760011c729ec5301ba..dc2d6b1066becb6a62b55466e6878b52769c0673 100644 (file)
@@ -2697,10 +2697,8 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, bool lval,
              }
            if (TREE_CODE (probe) == ARRAY_REF)
              {
-               // TODO
-               rust_unreachable ();
-               // elt = eval_and_check_array_index (ctx, probe, false,
-               //                                non_constant_p, overflow_p);
+               elt = eval_and_check_array_index (ctx, probe, false,
+                                                 non_constant_p, overflow_p);
                if (*non_constant_p)
                  return t;
              }
diff --git a/gcc/testsuite/rust/compile/issue-3563.rs b/gcc/testsuite/rust/compile/issue-3563.rs
new file mode 100644 (file)
index 0000000..46e7624
--- /dev/null
@@ -0,0 +1,17 @@
+pub struct AA {
+    pub data: [u8; 10],
+}
+
+impl AA {
+    pub const fn new() -> Self {
+        let mut res: AA = AA { data: [0; 10] };
+        res.data[0] = 5;
+        res
+    }
+}
+
+static mut BB: AA = AA::new();
+
+fn main() {
+    let _ptr = unsafe { &mut BB };
+}