File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -1391,11 +1391,15 @@ fn op_to_prop_const<'tcx>(
13911391 let ( prov, offset) = pointer. into_parts ( ) ;
13921392 let alloc_id = prov. alloc_id ( ) ;
13931393 intern_const_alloc_for_constprop ( ecx, alloc_id) . ok ( ) ?;
1394- if matches ! ( ecx. tcx. global_alloc( alloc_id) , GlobalAlloc :: Memory ( _) ) {
1395- // `alloc_id` may point to a static. Codegen will choke on an `Indirect` with anything
1396- // by `GlobalAlloc::Memory`, so do fall through to copying if needed.
1397- // FIXME: find a way to treat this more uniformly
1398- // (probably by fixing codegen)
1394+
1395+ // `alloc_id` may point to a static. Codegen will choke on an `Indirect` with anything
1396+ // by `GlobalAlloc::Memory`, so do fall through to copying if needed.
1397+ // FIXME: find a way to treat this more uniformly (probably by fixing codegen)
1398+ if let GlobalAlloc :: Memory ( alloc) = ecx. tcx . global_alloc ( alloc_id)
1399+ // Transmuting a constant is just an offset in the allocation. If the alignement of the
1400+ // allocation is noe enough, fallback to copying into a properly aligned value.
1401+ && alloc. inner ( ) . align >= op. layout . align . abi
1402+ {
13991403 return Some ( ConstValue :: Indirect { alloc_id, offset } ) ;
14001404 }
14011405 }
You can’t perform that action at this time.
0 commit comments