diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2024-07-05 22:55:09 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2024-07-05 22:59:10 +0000 |
| commit | b97f83b27fb23a0930630f23e3c113b8b542a43d (patch) | |
| tree | 36e1ff2d827cac18afe462520f34ded61d99c694 | |
| parent | 6aebb2cfec13f42e6dbae95416074f3040054b0d (diff) | |
| download | rust-b97f83b27fb23a0930630f23e3c113b8b542a43d.tar.gz rust-b97f83b27fb23a0930630f23e3c113b8b542a43d.zip | |
Verify that allocations output by GVN are sufficiently aligned.
| -rw-r--r-- | compiler/rustc_mir_transform/src/gvn.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 2b7d9be6d35..2c20c75df1f 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -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 alignement of the + // allocation is noe enough, fallback to copying into a properly aligned value. + && alloc.inner().align >= op.layout.align.abi + { return Some(ConstValue::Indirect { alloc_id, offset }); } } |
