diff options
| -rw-r--r-- | src/common.rs | 13 | ||||
| -rw-r--r-- | src/consts.rs | 2 | ||||
| -rw-r--r-- | tests/failing-ui-tests.txt | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/common.rs b/src/common.rs index 65f4788d902..58ff2f1f8f0 100644 --- a/src/common.rs +++ b/src/common.rs @@ -265,6 +265,19 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> { let alloc_id = prov.alloc_id(); let base_addr = match self.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { + // For ZSTs directly codegen an aligned pointer. + // This avoids generating a zero-sized constant value and actually needing a + // real address at runtime. + if alloc.inner().len() == 0 { + assert_eq!(offset.bytes(), 0); + let val = self.const_usize(alloc.inner().align.bytes()); + return if matches!(layout.primitive(), Pointer(_)) { + self.context.new_cast(None, val, ty) + } else { + self.const_bitcast(val, ty) + }; + } + let init = self.const_data_from_alloc(alloc); let alloc = alloc.inner(); let value = match alloc.mutability { diff --git a/src/consts.rs b/src/consts.rs index 73d3beede7f..b52a1f782cb 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -330,7 +330,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>( // and we properly interpret the provenance as a relocation pointer offset. alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)), ) - .expect("const_alloc_to_llvm: could not read relocation pointer") + .expect("const_alloc_to_gcc_uncached: could not read relocation pointer") as u64; let address_space = cx.tcx.global_alloc(alloc_id).address_space(cx); diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index 2baec427ce5..d931f0d3b5e 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -56,7 +56,6 @@ tests/ui/sanitizer/kcfi-mangling.rs tests/ui/statics/const_generics.rs tests/ui/backtrace/dylib-dep.rs tests/ui/delegation/fn-header.rs -tests/ui/consts/zst_no_llvm_alloc.rs tests/ui/consts/const-eval/parse_ints.rs tests/ui/simd/intrinsic/generic-as.rs tests/ui/runtime/rt-explody-panic-payloads.rs |
