Skip to content

Commit a0b21c9

Browse files
committed
gccrs: Fix ICE in array ref constexpr
Since 898d55a was fixed to remove the VIEW_CONVERT_EXPR from array expressions we can now turn on the array element access const expr. Fixes #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>
1 parent ebac3ab commit a0b21c9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

gcc/rust/backend/rust-constexpr.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,10 +2697,8 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, bool lval,
26972697
}
26982698
if (TREE_CODE (probe) == ARRAY_REF)
26992699
{
2700-
// TODO
2701-
rust_unreachable ();
2702-
// elt = eval_and_check_array_index (ctx, probe, false,
2703-
// non_constant_p, overflow_p);
2700+
elt = eval_and_check_array_index (ctx, probe, false,
2701+
non_constant_p, overflow_p);
27042702
if (*non_constant_p)
27052703
return t;
27062704
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub struct AA {
2+
pub data: [u8; 10],
3+
}
4+
5+
impl AA {
6+
pub const fn new() -> Self {
7+
let mut res: AA = AA { data: [0; 10] };
8+
res.data[0] = 5;
9+
res
10+
}
11+
}
12+
13+
static mut BB: AA = AA::new();
14+
15+
fn main() {
16+
let _ptr = unsafe { &mut BB };
17+
}

0 commit comments

Comments
 (0)