Skip to content

Commit efc8815

Browse files
committed
Fix to make the test zst_no_llvm_alloc pass
1 parent 3f1e473 commit efc8815

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/common.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
265265
let alloc_id = prov.alloc_id();
266266
let base_addr = match self.tcx.global_alloc(alloc_id) {
267267
GlobalAlloc::Memory(alloc) => {
268+
// For ZSTs directly codegen an aligned pointer.
269+
// This avoids generating a zero-sized constant value and actually needing a
270+
// real address at runtime.
271+
if alloc.inner().len() == 0 {
272+
assert_eq!(offset.bytes(), 0);
273+
let val = self.const_usize(alloc.inner().align.bytes());
274+
return if matches!(layout.primitive(), Pointer(_)) {
275+
self.context.new_cast(None, val, ty)
276+
} else {
277+
self.const_bitcast(val, ty)
278+
};
279+
}
280+
268281
let init = self.const_data_from_alloc(alloc);
269282
let alloc = alloc.inner();
270283
let value = match alloc.mutability {

src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
330330
// and we properly interpret the provenance as a relocation pointer offset.
331331
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
332332
)
333-
.expect("const_alloc_to_llvm: could not read relocation pointer")
333+
.expect("const_alloc_to_gcc_uncached: could not read relocation pointer")
334334
as u64;
335335

336336
let address_space = cx.tcx.global_alloc(alloc_id).address_space(cx);

tests/failing-ui-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ tests/ui/sanitizer/kcfi-mangling.rs
5656
tests/ui/statics/const_generics.rs
5757
tests/ui/backtrace/dylib-dep.rs
5858
tests/ui/delegation/fn-header.rs
59-
tests/ui/consts/zst_no_llvm_alloc.rs
6059
tests/ui/consts/const-eval/parse_ints.rs
6160
tests/ui/simd/intrinsic/generic-as.rs
6261
tests/ui/runtime/rt-explody-panic-payloads.rs

0 commit comments

Comments
 (0)