Skip to content

Commit 5b80814

Browse files
authored
Rollup merge of #101038 - RalfJung:interning-alignment, r=oli-obk
no alignment check during interning This should fix #101034 r? `@oli-obk` Unfortunately we don't have a self-contained testcase for this problem. I am not sure how it can be triggered...
2 parents c577021 + 468c617 commit 5b80814

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ fn eval_body_using_ecx<'mir, 'tcx>(
7474
None => InternKind::Constant,
7575
}
7676
};
77+
ecx.machine.check_alignment = false; // interning doesn't need to respect alignment
7778
intern_const_alloc_recursive(ecx, intern_kind, &ret)?;
79+
// we leave alignment checks off, since this `ecx` will not be used for further evaluation anyway
7880

7981
debug!("eval_body_using_ecx done: {:?}", *ret);
8082
Ok(ret)

compiler/rustc_const_eval/src/const_eval/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ pub struct CompileTimeInterpreter<'mir, 'tcx> {
8989
/// exhaustion error.
9090
///
9191
/// Setting this to `0` disables the limit and allows the interpreter to run forever.
92-
pub steps_remaining: usize,
92+
pub(super) steps_remaining: usize,
9393

9494
/// The virtual call stack.
95-
pub(crate) stack: Vec<Frame<'mir, 'tcx, AllocId, ()>>,
95+
pub(super) stack: Vec<Frame<'mir, 'tcx, AllocId, ()>>,
9696

9797
/// We need to make sure consts never point to anything mutable, even recursively. That is
9898
/// relied on for pattern matching on consts with references.
@@ -103,7 +103,7 @@ pub struct CompileTimeInterpreter<'mir, 'tcx> {
103103
pub(super) can_access_statics: bool,
104104

105105
/// Whether to check alignment during evaluation.
106-
check_alignment: bool,
106+
pub(super) check_alignment: bool,
107107
}
108108

109109
impl<'mir, 'tcx> CompileTimeInterpreter<'mir, 'tcx> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
// compile-flags: -Zextra-const-ub-checks
3+
4+
#[repr(packed)]
5+
pub struct Foo {
6+
bar: u8,
7+
baa: [u32; 1],
8+
}
9+
10+
const FOOMP: Foo = Foo {
11+
bar: 0,
12+
baa: [69; 1],
13+
};
14+
15+
fn main() {
16+
let _val = FOOMP;
17+
}

0 commit comments

Comments
 (0)