Skip to content

Commit 7e244d9

Browse files
committed
Update Rust toolchain to nightly-2025-06-23
1 parent 61bb7a5 commit 7e244d9

20 files changed

Lines changed: 133 additions & 121 deletions

File tree

crates/cust/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ unsafe impl Send for Function<'_> {}
213213
unsafe impl Sync for Function<'_> {}
214214

215215
impl Function<'_> {
216-
pub(crate) fn new(inner: CUfunction, _module: &Module) -> Function {
216+
pub(crate) fn new(inner: CUfunction, _module: &Module) -> Function<'_> {
217217
Function {
218218
inner,
219219
module: PhantomData,

crates/rustc_codegen_nvvm/src/abi.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cmp;
22

33
use libc::c_uint;
44
use rustc_abi::BackendRepr::Scalar;
5+
use rustc_abi::CanonAbi;
56
use rustc_abi::Size;
67
use rustc_abi::{HasDataLayout, Primitive, Reg, RegKind};
78
use rustc_codegen_ssa::mir::operand::OperandRef;
@@ -13,7 +14,7 @@ use rustc_middle::ty::layout::LayoutOf;
1314
pub use rustc_middle::ty::layout::{WIDE_PTR_ADDR, WIDE_PTR_EXTRA};
1415
use rustc_middle::ty::{Ty, TyCtxt, TyKind};
1516
use rustc_target::callconv::{
16-
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, Conv, FnAbi, PassMode,
17+
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, PassMode,
1718
};
1819
use tracing::trace;
1920

@@ -28,7 +29,7 @@ pub(crate) fn readjust_fn_abi<'tcx>(
2829
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
2930
) -> &'tcx FnAbi<'tcx, Ty<'tcx>> {
3031
// dont override anything in the rust abi for now
31-
if fn_abi.conv == Conv::Rust {
32+
if fn_abi.conv == CanonAbi::Rust {
3233
return fn_abi;
3334
}
3435
let readjust_arg_abi = |arg: &ArgAbi<'tcx, Ty<'tcx>>| {
@@ -260,9 +261,6 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
260261
) {
261262
arg_abi.store(self, val, dst)
262263
}
263-
fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> &'ll Type {
264-
arg_abi.memory_ty(self)
265-
}
266264
}
267265

268266
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
@@ -541,7 +539,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
541539
}
542540
}
543541

544-
impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
542+
impl<'tcx> AbiBuilderMethods for Builder<'_, '_, 'tcx> {
545543
fn get_param(&mut self, index: usize) -> Self::Value {
546544
let val = llvm::get_param(self.llfn(), index as c_uint);
547545
// trace!("Get param `{:?}`", val);
@@ -551,7 +549,7 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
551549
// destructure so rustc doesnt complain in the call to transmute_llval
552550
let Self { cx, llbuilder } = self;
553551
let map = cx.remapped_integer_args.borrow();
554-
if let Some((_, key)) = map.get(llfnty) {
552+
if let Some((_, key)) = map.get(&llfnty) {
555553
if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) {
556554
trace!("Casting irregular param {:?} to {:?}", val, new_ty);
557555
return transmute_llval(llbuilder, cx, val, new_ty);

crates/rustc_codegen_nvvm/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'tcx> AsmBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
224224

225225
impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
226226
fn codegen_global_asm(
227-
&self,
227+
&mut self,
228228
template: &[InlineAsmTemplatePiece],
229229
operands: &[GlobalAsmOperandRef],
230230
_options: InlineAsmOptions,

crates/rustc_codegen_nvvm/src/attributes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::llvm::{self, AttributePlace::*, Value};
22
use rustc_ast::{LitKind, MetaItemInner, MetaItemLit};
3-
use rustc_attr_parsing::{InlineAttr, OptimizeAttr};
3+
use rustc_attr_data_structures::{InlineAttr, OptimizeAttr};
44
use rustc_hir::Attribute;
5-
use rustc_middle::{bug, middle::codegen_fn_attrs::CodegenFnAttrFlags, ty};
5+
use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, ty};
66
use rustc_session::{Session, config::OptLevel};
77
use rustc_span::{Symbol, sym};
88

@@ -16,7 +16,7 @@ fn inline(val: &'_ Value, inline: InlineAttr) {
1616
Always => llvm::Attribute::AlwaysInline.apply_llfn(Function, val),
1717
Never => llvm::Attribute::NoInline.apply_llfn(Function, val),
1818
None => {}
19-
Force { .. } => bug!("Force inline should have been inlined away by now"), // TODO: Verify this
19+
Force { .. } => llvm::Attribute::AlwaysInline.apply_llfn(Function, val),
2020
}
2121
}
2222

crates/rustc_codegen_nvvm/src/back.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ pub(crate) unsafe fn codegen(
176176

177177
let llmod = unsafe { module.module_llvm.llmod.as_ref().unwrap() };
178178
let mod_name = module.name.clone();
179-
let module_name = Some(&mod_name[..]);
179+
let module_name = &mod_name[..];
180180

181181
let out = cgcx
182182
.output_filenames
183-
.temp_path(OutputType::Object, module_name);
183+
.temp_path_for_cgu(OutputType::Object, module_name, None);
184184

185185
// nvvm ir *is* llvm ir so emit_ir fits the expectation of llvm ir which is why we
186186
// implement this. this is copy and pasted straight from rustc_codegen_llvm
@@ -189,9 +189,9 @@ pub(crate) unsafe fn codegen(
189189
let _timer = cgcx
190190
.prof
191191
.generic_activity_with_arg("NVVM_module_codegen_emit_ir", &module.name[..]);
192-
let out = cgcx
193-
.output_filenames
194-
.temp_path(OutputType::LlvmAssembly, module_name);
192+
let out =
193+
cgcx.output_filenames
194+
.temp_path_for_cgu(OutputType::LlvmAssembly, module_name, None);
195195
let out = out.to_str().unwrap();
196196

197197
let result = unsafe {
@@ -229,6 +229,7 @@ pub(crate) unsafe fn codegen(
229229
bytecode: None,
230230
assembly: None,
231231
llvm_ir: None,
232+
links_from_incr_cache: vec![],
232233
})
233234
}
234235

@@ -254,7 +255,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
254255
// Instantiate monomorphizations without filling out definitions yet...
255256
let llvm_module = LlvmMod::new(cgu_name.as_str());
256257
{
257-
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
258+
let mut cx = CodegenCx::new(tcx, cgu, &llvm_module);
258259

259260
let mono_items = cx.codegen_unit.items_in_deterministic_order(cx.tcx);
260261

@@ -267,22 +268,27 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
267268
},
268269
) in &mono_items
269270
{
270-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, linkage, visibility);
271+
mono_item.predefine::<Builder<'_, '_, '_>>(
272+
&mut cx,
273+
"mono_item",
274+
linkage,
275+
visibility,
276+
);
271277
}
272278

273279
// ... and now that we have everything pre-defined, fill out those definitions.
274-
for &(mono_item, _) in &mono_items {
280+
for &(mono_item, mono_item_data) in &mono_items {
275281
if let MonoItem::Fn(func) = mono_item {
276-
define_or_override_fn(func, &cx);
282+
define_or_override_fn(func, &mut cx);
277283
} else {
278-
mono_item.define::<Builder<'_, '_, '_>>(&cx);
284+
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, "mono_item", mono_item_data);
279285
}
280286
}
281287

282288
// a main function for gpu kernels really makes no sense but
283289
// codegen it anyways.
284290
// sanitize attrs are not allowed in nvvm so do nothing further.
285-
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx);
291+
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&mut cx, cgu);
286292

287293
// Run replace-all-uses-with for statics that need it
288294
for &(old_g, new_g) in cx.statics_to_rauw.borrow().iter() {
@@ -333,13 +339,8 @@ pub(crate) unsafe fn optimize(
333339

334340
let llmod = unsafe { &*module.module_llvm.llmod };
335341

336-
let module_name = module.name.clone();
337-
let module_name = Some(&module_name[..]);
338-
339342
if config.emit_no_opt_bc {
340-
let out = cgcx
341-
.output_filenames
342-
.temp_path_ext("no-opt.bc", module_name);
343+
let out = cgcx.output_filenames.with_extension("no-opt.bc");
343344
let out = path_to_c_string(&out);
344345
unsafe { llvm::LLVMWriteBitcodeToFile(llmod, out.as_ptr()) };
345346
}

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use libc::{c_char, c_uint};
66
use rustc_abi as abi;
77
use rustc_abi::{AddressSpace, Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
88
use rustc_codegen_ssa::MemFlags;
9-
use rustc_codegen_ssa::common::{AtomicOrdering, IntPredicate, RealPredicate, TypeKind};
9+
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind};
1010
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1111
use rustc_codegen_ssa::mir::place::PlaceRef;
1212
use rustc_codegen_ssa::traits::*;
1313
use rustc_data_structures::small_c_str::SmallCStr;
1414
use rustc_hir::def_id::DefId;
1515
use rustc_middle::bug;
1616
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
17+
use rustc_middle::ty::AtomicOrdering;
1718
use rustc_middle::ty::layout::{
1819
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
1920
TyAndLayout,
@@ -704,7 +705,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
704705
&mut self,
705706
_val: &'ll Value,
706707
ptr: &'ll Value,
707-
_order: rustc_codegen_ssa::common::AtomicOrdering,
708+
_order: AtomicOrdering,
708709
_size: Size,
709710
) {
710711
// see comment in atomic_load
@@ -1042,8 +1043,8 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10421043
_dst: &'ll Value,
10431044
_cmp: &'ll Value,
10441045
_src: &'ll Value,
1045-
_order: rustc_codegen_ssa::common::AtomicOrdering,
1046-
_failure_order: rustc_codegen_ssa::common::AtomicOrdering,
1046+
_order: AtomicOrdering,
1047+
_failure_order: AtomicOrdering,
10471048
_weak: bool,
10481049
) -> (&'ll Value, &'ll Value) {
10491050
// allowed but only for some things and with restrictions
@@ -1055,15 +1056,15 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10551056
_op: rustc_codegen_ssa::common::AtomicRmwBinOp,
10561057
_dst: &'ll Value,
10571058
_src: &'ll Value,
1058-
_order: rustc_codegen_ssa::common::AtomicOrdering,
1059+
_order: AtomicOrdering,
10591060
) -> &'ll Value {
10601061
// see cmpxchg comment
10611062
self.fatal("atomic rmw is not supported")
10621063
}
10631064

10641065
fn atomic_fence(
10651066
&mut self,
1066-
_order: rustc_codegen_ssa::common::AtomicOrdering,
1067+
_order: AtomicOrdering,
10671068
_scope: rustc_codegen_ssa::common::SynchronizationScope,
10681069
) {
10691070
self.fatal("atomic fence is not supported, use cuda_std intrinsics instead")
@@ -1120,7 +1121,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11201121
while self.cx.type_kind(fn_ty) == TypeKind::Pointer {
11211122
fn_ty = self.cx.element_type(fn_ty);
11221123
}
1123-
if let Some((Some(ret_ty), _)) = map.get(fn_ty) {
1124+
if let Some((Some(ret_ty), _)) = map.get(&fn_ty) {
11241125
self.cx.last_call_llfn.set(Some(call));
11251126
call = transmute_llval(self.llbuilder, self.cx, call, ret_ty);
11261127
}

crates/rustc_codegen_nvvm/src/const_ty.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
1414
use rustc_middle::ty::layout::LayoutOf;
1515
use tracing::trace;
1616

17-
impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
17+
impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
1818
fn const_data_from_alloc(&self, alloc: ConstAllocation) -> &'ll Value {
1919
const_alloc_to_llvm(self, alloc, /*static*/ false)
2020
}
@@ -82,8 +82,7 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
8282
let val = *self
8383
.const_cstr_cache
8484
.borrow_mut()
85-
.raw_entry_mut()
86-
.from_key(s)
85+
.entry(s.to_string())
8786
.or_insert_with(|| {
8887
let sc = self.const_bytes(s.as_bytes());
8988
let sym = self.generate_local_symbol_name("str");
@@ -97,9 +96,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
9796
llvm::LLVMSetGlobalConstant(g, True);
9897
llvm::LLVMRustSetLinkage(g, llvm::Linkage::InternalLinkage);
9998
}
100-
(s.to_owned(), g)
101-
})
102-
.1;
99+
g
100+
});
103101
let len = s.len();
104102
let ty = self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self));
105103
let cs = unsafe { llvm::LLVMConstPointerCast(val, ty) };
@@ -247,10 +245,6 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
247245
val
248246
}
249247

250-
fn is_undef(&self, v: Self::Value) -> bool {
251-
unsafe { llvm::LLVMIsUndef(v) == True }
252-
}
253-
254248
fn const_poison(&self, t: Self::Type) -> Self::Value {
255249
// FIXME: Use LLVMGetPoision when possible.
256250
self.const_undef(t)

crates/rustc_codegen_nvvm/src/consts.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> {
336336
gv
337337
}
338338

339-
fn codegen_static(&self, def_id: DefId) {
339+
fn codegen_static(&mut self, def_id: DefId) {
340340
unsafe {
341341
assert!(
342342
llvm::LLVMGetInitializer(
@@ -422,23 +422,36 @@ impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> {
422422
self.unsupported("thread locals");
423423
}
424424

425-
if attrs.flags.contains(CodegenFnAttrFlags::USED) {
425+
if attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER) {
426+
// `USED` and `USED_LINKER` can't be used together.
427+
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER));
428+
429+
// The semantics of #[used] in Rust only require the symbol to make it into the
430+
// object file. It is explicitly allowed for the linker to strip the symbol if it
431+
// is dead, which means we are allowed to use `llvm.compiler.used` instead of
432+
// `llvm.used` here.
433+
//
434+
// Additionally, https://reviews.llvm.org/D97448 in LLVM 13 started emitting unique
435+
// sections with SHF_GNU_RETAIN flag for llvm.used symbols, which may trigger bugs
436+
// in the handling of `.init_array` (the static constructor list) in versions of
437+
// the gold linker (prior to the one released with binutils 2.36).
438+
//
439+
// That said, we only ever emit these when `#[used(compiler)]` is explicitly
440+
// requested. This is to avoid similar breakage on other targets, in particular
441+
// MachO targets have *their* static constructor lists broken if `llvm.compiler.used`
442+
// is emitted rather than `llvm.used`. However, that check happens when assigning
443+
// the `CodegenFnAttrFlags` in the `codegen_fn_attrs` query, so we don't need to
444+
// take care of it here.
445+
self.add_compiler_used_global(g);
446+
}
447+
if attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) {
448+
// `USED` and `USED_LINKER` can't be used together.
449+
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER));
450+
426451
self.add_used_global(g);
427452
}
453+
428454
trace!("Codegen static `{:?}`", g);
429455
}
430456
}
431-
432-
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
433-
fn add_used_global(&self, global: &'ll Value) {
434-
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
435-
self.used_statics.borrow_mut().push(cast);
436-
}
437-
438-
/// Add a global value to a list to be stored in the `llvm.compiler.used` variable,
439-
/// an array of i8*.
440-
fn add_compiler_used_global(&self, global: &'ll Value) {
441-
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
442-
self.compiler_used_statics.borrow_mut().push(cast);
443-
}
444457
}

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
232232
self.tcx.sess
233233
}
234234

235-
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
236-
self.codegen_unit
237-
}
238-
239235
fn declare_c_main(
240236
&self,
241237
_fn_type: <CodegenCx<'ll, 'tcx> as rustc_codegen_ssa::traits::BackendTypes>::Type,
@@ -541,6 +537,19 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
541537

542538
llfn
543539
}
540+
541+
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
542+
pub fn add_used_global(&self, global: &'ll Value) {
543+
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
544+
self.used_statics.borrow_mut().push(cast);
545+
}
546+
547+
/// Add a global value to a list to be stored in the `llvm.compiler.used` variable,
548+
/// an array of i8*.
549+
pub fn add_compiler_used_global(&self, global: &'ll Value) {
550+
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
551+
self.compiler_used_statics.borrow_mut().push(cast);
552+
}
544553
}
545554

546555
#[derive(Default, Clone)]

crates/rustc_codegen_nvvm/src/debug_info/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
814814
&& let Some(f) = output_filenames.split_dwarf_path(
815815
tcx.sess.split_debuginfo(),
816816
tcx.sess.opts.unstable_opts.split_dwarf_kind,
817-
Some(codegen_unit_name),
817+
codegen_unit_name,
818+
None,
818819
) {
819820
// We get a path relative to the working directory from split_dwarf_path
820821
Some(tcx.sess.source_map().path_mapping().to_real_filename(f))

0 commit comments

Comments
 (0)