Skip to content

Commit 8ddf4ef

Browse files
committed
Auto merge of rust-lang#153278 - JonathanBrouwer:rollup-k88jgqQ, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - rust-lang#153169 (Various small query cleanups) - rust-lang#152304 (stabilize new RangeToInclusive type) - rust-lang#153046 (Couple of cg_ssa refactorings) - rust-lang#153090 (elf-raw-dylib: set type for functions) - rust-lang#153225 (tests/ui/asm: add annotations for reference rules) - rust-lang#153233 (test: add regression test for fuzzy_provenance_casts lint ICE)
2 parents 8d50bcc + 80a9870 commit 8ddf4ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+598
-427
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,14 @@ impl<'a, 'gcc, 'tcx> Deref for Builder<'a, 'gcc, 'tcx> {
485485
}
486486

487487
impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
488-
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
489-
type Metadata = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Metadata;
490488
type Function = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Function;
491489
type BasicBlock = <CodegenCx<'gcc, 'tcx> as BackendTypes>::BasicBlock;
492-
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;
493490
type Funclet = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Funclet;
494491

492+
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
493+
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;
494+
type FunctionSignature = <CodegenCx<'gcc, 'tcx> as BackendTypes>::FunctionSignature;
495+
495496
type DIScope = <CodegenCx<'gcc, 'tcx> as BackendTypes>::DIScope;
496497
type DILocation = <CodegenCx<'gcc, 'tcx> as BackendTypes>::DILocation;
497498
type DIVariable = <CodegenCx<'gcc, 'tcx> as BackendTypes>::DIVariable;

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use rustc_codegen_ssa::traits::{
55
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods,
66
};
77
use rustc_middle::mir::Mutability;
8-
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, PointerArithmetic, Scalar};
8+
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
99
use rustc_middle::ty::layout::LayoutOf;
1010

11+
use crate::consts::const_alloc_to_gcc;
1112
use crate::context::{CodegenCx, new_array_type};
1213
use crate::type_of::LayoutGccExt;
1314

@@ -260,11 +261,13 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
260261
};
261262
}
262263

263-
let init = self.const_data_from_alloc(alloc);
264-
let alloc = alloc.inner();
265-
let value = match alloc.mutability {
266-
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
267-
_ => self.static_addr_of(init, alloc.align, None),
264+
let value = match alloc.inner().mutability {
265+
Mutability::Mut => self.static_addr_of_mut(
266+
const_alloc_to_gcc(self, alloc),
267+
alloc.inner().align,
268+
None,
269+
),
270+
_ => self.static_addr_of(alloc, None),
268271
};
269272
if !self.sess().fewer_names() {
270273
// TODO(antoyo): set value name.
@@ -282,8 +285,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
282285
}),
283286
)))
284287
.unwrap_memory();
285-
let init = self.const_data_from_alloc(alloc);
286-
self.static_addr_of(init, alloc.inner().align, None)
288+
self.static_addr_of(alloc, None)
287289
}
288290
GlobalAlloc::TypeId { .. } => {
289291
let val = self.const_usize(offset.bytes());
@@ -311,22 +313,6 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
311313
}
312314
}
313315

314-
fn const_data_from_alloc(&self, alloc: ConstAllocation<'_>) -> Self::Value {
315-
// We ignore the alignment for the purpose of deduping RValues
316-
// The alignment is not handled / used in any way by `const_alloc_to_gcc`,
317-
// so it is OK to overwrite it here.
318-
let mut mock_alloc = alloc.inner().clone();
319-
mock_alloc.align = rustc_abi::Align::MAX;
320-
// Check if the rvalue is already in the cache - if so, just return it directly.
321-
if let Some(res) = self.const_cache.borrow().get(&mock_alloc) {
322-
return *res;
323-
}
324-
// Rvalue not in the cache - convert and add it.
325-
let res = crate::consts::const_alloc_to_gcc_uncached(self, alloc);
326-
self.const_cache.borrow_mut().insert(mock_alloc, res);
327-
res
328-
}
329-
330316
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
331317
self.context
332318
.new_array_access(None, base_addr, self.const_usize(offset.bytes()))

compiler/rustc_codegen_gcc/src/consts.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ use crate::base;
2222
use crate::context::CodegenCx;
2323
use crate::type_of::LayoutGccExt;
2424

25+
pub(crate) fn const_alloc_to_gcc<'gcc, 'tcx>(
26+
cx: &CodegenCx<'gcc, 'tcx>,
27+
alloc: ConstAllocation<'_>,
28+
) -> RValue<'gcc> {
29+
// We ignore the alignment for the purpose of deduping RValues
30+
// The alignment is not handled / used in any way by `const_alloc_to_gcc`,
31+
// so it is OK to overwrite it here.
32+
let mut mock_alloc = alloc.inner().clone();
33+
mock_alloc.align = rustc_abi::Align::MAX;
34+
// Check if the rvalue is already in the cache - if so, just return it directly.
35+
if let Some(res) = cx.const_cache.borrow().get(&mock_alloc) {
36+
return *res;
37+
}
38+
// Rvalue not in the cache - convert and add it.
39+
let res = crate::consts::const_alloc_to_gcc_uncached(cx, alloc);
40+
cx.const_cache.borrow_mut().insert(mock_alloc, res);
41+
res
42+
}
43+
2544
fn set_global_alignment<'gcc, 'tcx>(
2645
cx: &CodegenCx<'gcc, 'tcx>,
2746
gv: LValue<'gcc>,
@@ -37,7 +56,10 @@ fn set_global_alignment<'gcc, 'tcx>(
3756
}
3857

3958
impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
40-
fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
59+
fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> RValue<'gcc> {
60+
let cv = const_alloc_to_gcc(self, alloc);
61+
let align = alloc.inner().align;
62+
4163
if let Some(variable) = self.const_globals.borrow().get(&cv) {
4264
if let Some(global_variable) = self.global_lvalues.borrow().get(variable) {
4365
let alignment = align.bits() as i32;
@@ -361,7 +383,7 @@ fn codegen_static_initializer<'gcc, 'tcx>(
361383
def_id: DefId,
362384
) -> Result<(RValue<'gcc>, ConstAllocation<'tcx>), ErrorHandled> {
363385
let alloc = cx.tcx.eval_static_initializer(def_id)?;
364-
Ok((cx.const_data_from_alloc(alloc), alloc))
386+
Ok((const_alloc_to_gcc(cx, alloc), alloc))
365387
}
366388

367389
fn check_and_apply_linkage<'gcc, 'tcx>(

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
380380
}
381381

382382
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
383-
type Value = RValue<'gcc>;
384-
type Metadata = RValue<'gcc>;
385383
type Function = Function<'gcc>;
386-
387384
type BasicBlock = Block<'gcc>;
388-
type Type = Type<'gcc>;
389385
type Funclet = (); // TODO(antoyo)
390386

387+
type Value = RValue<'gcc>;
388+
type Type = Type<'gcc>;
389+
type FunctionSignature = Type<'gcc>;
390+
391391
type DIScope = (); // TODO(antoyo)
392392
type DILocation = Location<'gcc>;
393393
type DIVariable = (); // TODO(antoyo)

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
712712
&mut self,
713713
_vtable: Self::Value,
714714
_vtable_byte_offset: u64,
715-
_typeid: Self::Value,
715+
_typeid: &[u8],
716716
) -> Self::Value {
717717
// Unsupported.
718718
self.context.new_rvalue_from_int(self.int_type, 0)

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
196196
pub(crate) const UNNAMED: *const c_char = c"".as_ptr();
197197

198198
impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericBuilder<'_, 'll, CX> {
199-
type Value = <GenericCx<'ll, CX> as BackendTypes>::Value;
200-
type Metadata = <GenericCx<'ll, CX> as BackendTypes>::Metadata;
201199
type Function = <GenericCx<'ll, CX> as BackendTypes>::Function;
202200
type BasicBlock = <GenericCx<'ll, CX> as BackendTypes>::BasicBlock;
203-
type Type = <GenericCx<'ll, CX> as BackendTypes>::Type;
204201
type Funclet = <GenericCx<'ll, CX> as BackendTypes>::Funclet;
205202

203+
type Value = <GenericCx<'ll, CX> as BackendTypes>::Value;
204+
type Type = <GenericCx<'ll, CX> as BackendTypes>::Type;
205+
type FunctionSignature = <GenericCx<'ll, CX> as BackendTypes>::FunctionSignature;
206+
206207
type DIScope = <GenericCx<'ll, CX> as BackendTypes>::DIScope;
207208
type DILocation = <GenericCx<'ll, CX> as BackendTypes>::DILocation;
208209
type DIVariable = <GenericCx<'ll, CX> as BackendTypes>::DIVariable;

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_hashes::Hash128;
1313
use rustc_hir::def_id::DefId;
1414
use rustc_middle::bug;
15-
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, PointerArithmetic, Scalar};
15+
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
1616
use rustc_middle::ty::TyCtxt;
1717
use rustc_session::cstore::DllImport;
1818
use tracing::debug;
1919

2020
use crate::consts::const_alloc_to_llvm;
2121
pub(crate) use crate::context::CodegenCx;
2222
use crate::context::{GenericCx, SCx};
23-
use crate::llvm::{self, BasicBlock, ConstantInt, FALSE, Metadata, TRUE, ToLlvmBool, Type, Value};
23+
use crate::llvm::{self, BasicBlock, ConstantInt, FALSE, TRUE, ToLlvmBool, Type, Value};
2424

2525
/*
2626
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
@@ -82,15 +82,15 @@ impl<'ll> Funclet<'ll> {
8282
}
8383

8484
impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericCx<'ll, CX> {
85-
type Value = &'ll Value;
86-
type Metadata = &'ll Metadata;
8785
// FIXME(eddyb) replace this with a `Function` "subclass" of `Value`.
8886
type Function = &'ll Value;
89-
9087
type BasicBlock = &'ll BasicBlock;
91-
type Type = &'ll Type;
9288
type Funclet = Funclet<'ll>;
9389

90+
type Value = &'ll Value;
91+
type Type = &'ll Type;
92+
type FunctionSignature = &'ll Type;
93+
9494
type DIScope = &'ll llvm::debuginfo::DIScope;
9595
type DILocation = &'ll llvm::debuginfo::DILocation;
9696
type DIVariable = &'ll llvm::debuginfo::DIVariable;
@@ -359,10 +359,6 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
359359
}
360360
}
361361

362-
fn const_data_from_alloc(&self, alloc: ConstAllocation<'_>) -> Self::Value {
363-
const_alloc_to_llvm(self, alloc.inner(), /*static*/ false)
364-
}
365-
366362
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
367363
unsafe {
368364
llvm::LLVMConstInBoundsGEP2(

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,12 @@ impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> {
772772
///
773773
/// The pointer will always be in the default address space. If global variables default to a
774774
/// different address space, an addrspacecast is inserted.
775-
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
776-
let gv = self.static_addr_of_impl(cv, align, kind);
775+
fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> &'ll Value {
776+
// FIXME: should we cache `const_alloc_to_llvm` to avoid repeating this for the
777+
// same `ConstAllocation`?
778+
let cv = const_alloc_to_llvm(self, alloc.inner(), /*static*/ false);
779+
780+
let gv = self.static_addr_of_impl(cv, alloc.inner().align, kind);
777781
// static_addr_of_impl returns the bare global variable, which might not be in the default
778782
// address space. Cast to the default address space if necessary.
779783
self.const_pointercast(gv, self.type_ptr())

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::declare::declare_raw_fn;
3838
use crate::errors::{
3939
AutoDiffWithoutEnable, AutoDiffWithoutLto, OffloadWithoutEnable, OffloadWithoutFatLTO,
4040
};
41-
use crate::llvm::{self, Metadata, Type, Value};
41+
use crate::llvm::{self, Type, Value};
4242
use crate::type_of::LayoutLlvmExt;
4343
use crate::va_arg::emit_va_arg;
4444

@@ -799,8 +799,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
799799
&mut self,
800800
llvtable: &'ll Value,
801801
vtable_byte_offset: u64,
802-
typeid: &'ll Metadata,
802+
typeid: &[u8],
803803
) -> Self::Value {
804+
let typeid = self.create_metadata(typeid);
804805
let typeid = self.get_metadata_value(typeid);
805806
let vtable_byte_offset = self.const_i32(vtable_byte_offset as i32);
806807
let type_checked_load = self.call_intrinsic(

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_target::callconv::{CastTarget, FnAbi};
1515
use crate::abi::{FnAbiLlvmExt, LlvmType};
1616
use crate::common;
1717
use crate::context::{CodegenCx, GenericCx, SCx};
18-
use crate::llvm::{self, FALSE, Metadata, TRUE, ToGeneric, ToLlvmBool, Type, Value};
18+
use crate::llvm::{self, FALSE, TRUE, ToGeneric, ToLlvmBool, Type, Value};
1919
use crate::type_of::LayoutLlvmExt;
2020

2121
impl PartialEq for Type {
@@ -319,10 +319,6 @@ impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
319319
self.global_set_metadata_node(function, llvm::MD_type, &v);
320320
}
321321

322-
fn typeid_metadata(&self, typeid: &[u8]) -> Option<&'ll Metadata> {
323-
Some(self.create_metadata(typeid))
324-
}
325-
326322
fn add_kcfi_type_metadata(&self, function: &'ll Value, kcfi_typeid: u32) {
327323
let kcfi_type_metadata = [llvm::LLVMValueAsMetadata(self.const_u32(kcfi_typeid))];
328324
self.global_add_metadata_node(function, llvm::MD_kcfi_type, &kcfi_type_metadata);

0 commit comments

Comments
 (0)