diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-02-26 18:03:06 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-12 05:53:46 +0000 |
| commit | d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af (patch) | |
| tree | 95685bb9f89cc23836f86c958b346447e8fd5356 /compiler/rustc_codegen_llvm/src/mono_item.rs | |
| parent | 92414ab25d5b9ddbee37d458e53e70ee4813d5ca (diff) | |
| download | rust-d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af.tar.gz rust-d3514a036dc65c1d31ee5b1b4bd58b9be1edf5af.zip | |
Ensure nested allocations in statics do not get deduplicated
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/mono_item.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/mono_item.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index f7630719368..81ac9571885 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -5,7 +5,9 @@ use crate::errors::SymbolAlreadyDefined; use crate::llvm; use crate::type_of::LayoutLlvmExt; use rustc_codegen_ssa::traits::*; +use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_middle::bug; use rustc_middle::mir::mono::{Linkage, Visibility}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf}; use rustc_middle::ty::{self, Instance, TypeVisitableExt}; @@ -21,7 +23,14 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> { symbol_name: &str, ) { let instance = Instance::mono(self.tcx, def_id); - let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all()); + let DefKind::Static { nested, .. } = self.tcx.def_kind(def_id) else { bug!() }; + // Nested statics do not have a type, so pick a random type and let `define_static` figure out + // the llvm type from the actual evaluated initializer. + let ty = if nested { + self.tcx.types.unit + } else { + instance.ty(self.tcx, ty::ParamEnv::reveal_all()) + }; let llty = self.layout_of(ty).llvm_type(self); let g = self.define_global(symbol_name, llty).unwrap_or_else(|| { |
