Skip to content

Commit e785c50

Browse files
authored
Merge pull request #795 from rust-lang/sync_from_rust_2025_11_01
Sync from rust 2025/11/01
2 parents e7b5847 + 76a7e79 commit e785c50

File tree

12 files changed

+97
-70
lines changed

12 files changed

+97
-70
lines changed

example/mini_core.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> fo
603603
impl<T> Box<T> {
604604
pub fn new(val: T) -> Box<T> {
605605
unsafe {
606-
let size = intrinsics::size_of::<T>();
606+
let size = size_of::<T>();
607607
let ptr = libc::malloc(size);
608608
intrinsics::copy(&val as *const T as *const u8, ptr, size);
609609
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
@@ -657,11 +657,11 @@ pub mod intrinsics {
657657
#[rustc_intrinsic]
658658
pub fn abort() -> !;
659659
#[rustc_intrinsic]
660-
pub fn size_of<T>() -> usize;
660+
pub const fn size_of<T>() -> usize;
661661
#[rustc_intrinsic]
662662
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
663663
#[rustc_intrinsic]
664-
pub fn align_of<T>() -> usize;
664+
pub const fn align_of<T>() -> usize;
665665
#[rustc_intrinsic]
666666
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
667667
#[rustc_intrinsic]
@@ -699,6 +699,24 @@ pub mod libc {
699699
}
700700
}
701701

702+
pub const fn size_of<T>() -> usize {
703+
<T as SizedTypeProperties>::SIZE
704+
}
705+
706+
pub const fn align_of<T>() -> usize {
707+
<T as SizedTypeProperties>::ALIGN
708+
}
709+
710+
trait SizedTypeProperties: Sized {
711+
#[lang = "mem_size_const"]
712+
const SIZE: usize = intrinsics::size_of::<Self>();
713+
714+
#[lang = "mem_align_const"]
715+
const ALIGN: usize = intrinsics::align_of::<Self>();
716+
}
717+
718+
impl<T> SizedTypeProperties for T {}
719+
702720
#[lang = "index"]
703721
pub trait Index<Idx: ?Sized> {
704722
type Output: ?Sized;

example/mini_core_hello_world.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ fn start<T: Termination + 'static>(
9090
) -> isize {
9191
if argc == 3 {
9292
unsafe { puts(*argv); }
93-
unsafe { puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const u8)); }
94-
unsafe { puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const u8)); }
93+
unsafe { puts(*((argv as usize + size_of::<*const u8>()) as *const *const u8)); }
94+
unsafe { puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const u8)); }
9595
}
9696

9797
main().report();
@@ -154,7 +154,7 @@ fn main() {
154154
let slice = &[0, 1] as &[i32];
155155
let slice_ptr = slice as *const [i32] as *const i32;
156156

157-
let align = intrinsics::align_of::<*const i32>();
157+
let align = align_of::<*const i32>();
158158
assert_eq!(slice_ptr as usize % align, 0);
159159

160160
//return;
@@ -195,8 +195,8 @@ fn main() {
195195
assert_eq!(intrinsics::size_of_val(a) as u8, 8);
196196
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
197197

198-
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
199-
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
198+
assert_eq!(align_of::<u16>() as u8, 2);
199+
assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8);
200200

201201
let u8_needs_drop = const { intrinsics::needs_drop::<u8>() };
202202
assert!(!u8_needs_drop);

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2025-09-30"
2+
channel = "nightly-2025-11-04"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/allocator.rs

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
use gccjit::FnAttribute;
33
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
5-
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
6-
alloc_error_handler_name, default_fn_name, global_fn_name,
5+
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
76
};
87
use rustc_middle::bug;
98
use rustc_middle::ty::TyCtxt;
@@ -18,8 +17,7 @@ pub(crate) unsafe fn codegen(
1817
tcx: TyCtxt<'_>,
1918
mods: &mut GccContext,
2019
_module_name: &str,
21-
kind: AllocatorKind,
22-
alloc_error_handler_kind: AllocatorKind,
20+
methods: &[AllocatorMethod],
2321
) {
2422
let context = &mods.context;
2523
let usize = match tcx.sess.target.pointer_width {
@@ -31,45 +29,35 @@ pub(crate) unsafe fn codegen(
3129
let i8 = context.new_type::<i8>();
3230
let i8p = i8.make_pointer();
3331

34-
if kind == AllocatorKind::Default {
35-
for method in ALLOCATOR_METHODS {
36-
let mut types = Vec::with_capacity(method.inputs.len());
37-
for input in method.inputs.iter() {
38-
match input.ty {
39-
AllocatorTy::Layout => {
40-
types.push(usize);
41-
types.push(usize);
42-
}
43-
AllocatorTy::Ptr => types.push(i8p),
44-
AllocatorTy::Usize => types.push(usize),
45-
46-
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
32+
for method in methods {
33+
let mut types = Vec::with_capacity(method.inputs.len());
34+
for input in method.inputs.iter() {
35+
match input.ty {
36+
AllocatorTy::Layout => {
37+
types.push(usize);
38+
types.push(usize);
4739
}
48-
}
49-
let output = match method.output {
50-
AllocatorTy::ResultPtr => Some(i8p),
51-
AllocatorTy::Unit => None,
40+
AllocatorTy::Ptr => types.push(i8p),
41+
AllocatorTy::Usize => types.push(usize),
5242

53-
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
54-
panic!("invalid allocator output")
43+
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
44+
panic!("invalid allocator arg")
5545
}
56-
};
57-
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
58-
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
59-
60-
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
46+
}
6147
}
62-
}
48+
let output = match method.output {
49+
AllocatorTy::ResultPtr => Some(i8p),
50+
AllocatorTy::Never | AllocatorTy::Unit => None,
6351

64-
// FIXME(bjorn3): Add noreturn attribute
65-
create_wrapper_function(
66-
tcx,
67-
context,
68-
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
69-
Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))),
70-
&[usize, usize],
71-
None,
72-
);
52+
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
53+
panic!("invalid allocator output")
54+
}
55+
};
56+
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
57+
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
58+
59+
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
60+
}
7361

7462
create_const_value_function(
7563
tcx,

src/asm.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,16 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
546546
}
547547

548548
if !options.contains(InlineAsmOptions::PRESERVES_FLAGS) {
549-
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
550-
// on all architectures. For instance, what about FP stack?
551-
extended_asm.add_clobber("cc");
549+
match asm_arch {
550+
InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {
551+
// "cc" is cr0 on powerpc.
552+
}
553+
// TODO(@Commeownist): I'm not 100% sure this one clobber is sufficient
554+
// on all architectures. For instance, what about FP stack?
555+
_ => {
556+
extended_asm.add_clobber("cc");
557+
}
558+
}
552559
}
553560
if !options.contains(InlineAsmOptions::NOMEM) {
554561
extended_asm.add_clobber("memory");
@@ -698,6 +705,7 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
698705
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
699706
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
700707
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
708+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vsreg) => "wa",
701709
InlineAsmRegClass::PowerPC(
702710
PowerPCInlineAsmRegClass::cr
703711
| PowerPCInlineAsmRegClass::ctr
@@ -778,9 +786,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
778786
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
779787
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
780788
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
781-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
782-
cx.type_vector(cx.type_i32(), 4)
783-
}
789+
InlineAsmRegClass::PowerPC(
790+
PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg,
791+
) => cx.type_vector(cx.type_i32(), 4),
784792
InlineAsmRegClass::PowerPC(
785793
PowerPCInlineAsmRegClass::cr
786794
| PowerPCInlineAsmRegClass::ctr
@@ -957,6 +965,13 @@ fn modifier_to_gcc(
957965
InlineAsmRegClass::LoongArch(_) => None,
958966
InlineAsmRegClass::Mips(_) => None,
959967
InlineAsmRegClass::Nvptx(_) => None,
968+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vsreg) => {
969+
if modifier.is_none() {
970+
Some('x')
971+
} else {
972+
modifier
973+
}
974+
}
960975
InlineAsmRegClass::PowerPC(_) => None,
961976
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
962977
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,

src/back/lto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_codegen_ssa::traits::*;
3131
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
3232
use rustc_data_structures::memmap::Mmap;
3333
use rustc_errors::DiagCtxtHandle;
34+
use rustc_log::tracing::info;
3435
use rustc_middle::bug;
3536
use rustc_middle::dep_graph::WorkProduct;
3637
use rustc_session::config::Lto;

src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_codegen_ssa::back::link::ensure_removed;
55
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
66
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
77
use rustc_fs_util::link_or_copy;
8+
use rustc_log::tracing::debug;
89
use rustc_session::config::OutputType;
910
use rustc_target::spec::SplitDebuginfo;
1011

src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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, Scalar};
8+
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, PointerArithmetic, Scalar};
99
use rustc_middle::ty::layout::LayoutOf;
1010

1111
use crate::context::CodegenCx;
@@ -247,8 +247,8 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
247247
// This avoids generating a zero-sized constant value and actually needing a
248248
// real address at runtime.
249249
if alloc.inner().len() == 0 {
250-
assert_eq!(offset.bytes(), 0);
251-
let val = self.const_usize(alloc.inner().align.bytes());
250+
let val = alloc.inner().align.bytes().wrapping_add(offset.bytes());
251+
let val = self.const_usize(self.tcx.truncate_to_target_usize(val));
252252
return if matches!(layout.primitive(), Pointer(_)) {
253253
self.context.new_cast(None, val, ty)
254254
} else {

src/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_codegen_ssa::traits::{
88
use rustc_hir::attrs::Linkage;
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::LOCAL_CRATE;
11+
use rustc_log::tracing::trace;
1112
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1213
use rustc_middle::mir::interpret::{
1314
self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint,

src/debuginfo.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,24 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
2929
_variable_alloca: Self::Value,
3030
_direct_offset: Size,
3131
_indirect_offsets: &[Size],
32-
_fragment: Option<Range<Size>>,
32+
_fragment: &Option<Range<Size>>,
3333
) {
3434
// FIXME(tempdragon): Not sure if this is correct, probably wrong but still keep it here.
3535
#[cfg(feature = "master")]
3636
_variable_alloca.set_location(_dbg_loc);
3737
}
3838

39+
fn dbg_var_value(
40+
&mut self,
41+
_dbg_var: Self::DIVariable,
42+
_dbg_loc: Self::DILocation,
43+
_value: Self::Value,
44+
_direct_offset: Size,
45+
_indirect_offsets: &[Size],
46+
_fragment: &Option<Range<Size>>,
47+
) {
48+
}
49+
3950
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
4051
// TODO(antoyo): insert reference to gdb debug scripts section global.
4152
}

0 commit comments

Comments
 (0)