Rollup merge of #127399 - cjgillot:issue-127396, r=oli-obk

Verify that allocations output by GVN are sufficiently aligned.

Fixes #127396

r? `@oli-obk`
This commit is contained in:
Matthias Krüger 2024-07-08 16:28:16 +02:00 committed by GitHub
commit 3e8e8df7c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -1391,11 +1391,15 @@ fn op_to_prop_const<'tcx>(
let (prov, offset) = pointer.into_parts();
let alloc_id = prov.alloc_id();
intern_const_alloc_for_constprop(ecx, alloc_id).ok()?;
if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) {
// `alloc_id` may point to a static. Codegen will choke on an `Indirect` with anything
// by `GlobalAlloc::Memory`, so do fall through to copying if needed.
// FIXME: find a way to treat this more uniformly
// (probably by fixing codegen)
// `alloc_id` may point to a static. Codegen will choke on an `Indirect` with anything
// by `GlobalAlloc::Memory`, so do fall through to copying if needed.
// FIXME: find a way to treat this more uniformly (probably by fixing codegen)
if let GlobalAlloc::Memory(alloc) = ecx.tcx.global_alloc(alloc_id)
// Transmuting a constant is just an offset in the allocation. If the alignment of the
// allocation is not enough, fallback to copying into a properly aligned value.
&& alloc.inner().align >= op.layout.align.abi
{
return Some(ConstValue::Indirect { alloc_id, offset });
}
}