Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ad6957
Cleanup CodegenFnAttrFlags
Noratrieb May 24, 2025
0348509
Pass PlaceRef rather than Bx::Value to codegen_intrinsic_call
bjorn3 May 22, 2025
f994713
Remove usage of FnAbi in codegen_intrinsic_call
bjorn3 May 22, 2025
f6489c3
Remove codegen_unit from MiscCodegenMethods
bjorn3 Dec 13, 2024
4d47f6d
Remove a couple of uses of interior mutability around statics
bjorn3 Dec 13, 2024
f297400
Make predefine methods take &mut self
bjorn3 Jan 9, 2025
96be6ef
Remove methods from StaticCodegenMethods that are not called in cg_ss…
bjorn3 Jan 9, 2025
244ea12
Mark all optimize methods and the codegen method as safe
bjorn3 Jan 9, 2025
0c6f946
Remove unused arg_memory_ty method
bjorn3 Nov 7, 2024
dbbfb6e
get rid of rustc_codegen_ssa::common::AtomicOrdering
RalfJung May 28, 2025
acb2fcd
Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
matthiaskrgr May 30, 2025
5c4b797
Use layout field of OperandRef and PlaceRef in codegen_intrinsic_call
bjorn3 May 30, 2025
926c8c8
Use layout field of OperandRef in generic_simd_intrinsic
bjorn3 May 30, 2025
6c6c31d
Avoid computing function type for intrinsic instances
bjorn3 May 30, 2025
f383b17
Directly use from_immediate for handling bool
bjorn3 May 30, 2025
f69d8fc
Merge branch 'master' into sync_from_rust_2025_06_02
antoyo Jun 2, 2025
2d7d0ee
Update to nightly-2025-06-02
antoyo Jun 2, 2025
38f134c
Remove unneeded patch
antoyo Jun 2, 2025
2e89179
Make comment more specific
antoyo Jun 5, 2025
7c71c83
Fix type_name intrinsic
antoyo Jun 28, 2025
5735bb3
Merge branch 'master' into sync_from_rust_2025_06_02
antoyo Jun 28, 2025
1449894
Fix to use Function instead of RValue
antoyo Jun 28, 2025
eb4d429
Fix for libgccjit 12
antoyo Jun 28, 2025
c7c1622
Ignore failing test
antoyo Jun 28, 2025
49e65a0
Remove commented code
antoyo Jun 28, 2025
f876b18
Add TODOs
antoyo Jun 28, 2025
8385f3c
Stop skipping libcore's f16::test_total_cmp
antoyo Jun 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,7 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
let path = get_sysroot_dir().join("sysroot_src/library/coretests");
let _ = remove_dir_all(path.join("target"));
// TODO(antoyo): run in release mode when we fix the failures.
// TODO(antoyo): remove the --skip f16::test_total_cmp when this issue is fixed:
// https://github.com/rust-lang/rust/issues/141503
run_cargo_command(
&[&"test", &"--", &"--skip", &"f16::test_total_cmp"],
Some(&path),
env,
args,
)?;
run_cargo_command(&[&"test"], Some(&path), env, args)?;
Ok(())
}

Expand Down
39 changes: 0 additions & 39 deletions patches/0001-Pin-compiler_builtins-to-0.1.160.patch

This file was deleted.

2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2025-05-21"
channel = "nightly-2025-06-02"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
7 changes: 3 additions & 4 deletions src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_target::callconv::{Conv, RiscvInterruptKind};

use crate::builder::Builder;
use crate::context::CodegenCx;
use crate::intrinsic::ArgAbiExt;
use crate::type_of::LayoutGccExt;

impl AbiBuilderMethods for Builder<'_, '_, '_> {
Expand Down Expand Up @@ -125,7 +124,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
PassMode::Cast { ref cast, .. } => cast.gcc_type(cx),
PassMode::Indirect { .. } => {
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
argument_tys.push(cx.type_ptr_to(self.ret.layout.gcc_type(cx)));
cx.type_void()
}
};
Expand Down Expand Up @@ -176,13 +175,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: true } => {
// This is a "byval" argument, so we don't apply the `restrict` attribute on it.
on_stack_param_indices.insert(argument_tys.len());
arg.memory_ty(cx)
arg.layout.gcc_type(cx)
}
PassMode::Direct(attrs) => {
apply_attrs(arg.layout.immediate_gcc_type(cx), &attrs, argument_tys.len())
}
PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
apply_attrs(cx.type_ptr_to(arg.memory_ty(cx)), &attrs, argument_tys.len())
apply_attrs(cx.type_ptr_to(arg.layout.gcc_type(cx)), &attrs, argument_tys.len())
}
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
assert!(!on_stack);
Expand Down
11 changes: 8 additions & 3 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,22 @@ pub fn compile_codegen_unit(

let mono_items = cgu.items_in_deterministic_order(tcx);
for &(mono_item, data) in &mono_items {
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
mono_item.predefine::<Builder<'_, '_, '_>>(
&mut cx,
cgu_name.as_str(),
data.linkage,
data.visibility,
);
}

// ... and now that we have everything pre-defined, fill out those definitions.
for &(mono_item, item_data) in &mono_items {
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, item_data);
mono_item.define::<Builder<'_, '_, '_>>(&mut cx, cgu_name.as_str(), item_data);
}

// If this codegen unit contains the main function, also create the
// wrapper here
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx);
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cx.codegen_unit);

// Finalize debuginfo
if cx.sess().opts.debuginfo != DebugInfo::None {
Expand Down
32 changes: 18 additions & 14 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
use rustc_apfloat::{Float, Round, Status, ieee};
use rustc_codegen_ssa::MemFlags;
use rustc_codegen_ssa::common::{
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
};
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::PlaceRef;
Expand All @@ -26,7 +26,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::callconv::FnAbi;
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

let load_ordering = match order {
// TODO(antoyo): does this make sense?
AtomicOrdering::AcquireRelease | AtomicOrdering::Release => AtomicOrdering::Acquire,
AtomicOrdering::AcqRel | AtomicOrdering::Release => AtomicOrdering::Acquire,
_ => order,
};
let previous_value =
Expand Down Expand Up @@ -781,6 +781,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
return self.context.new_call(self.location, fmod, &[a, b]);
}
TypeKind::FP128 => {
// TODO(antoyo): use get_simple_function_f128_2args.
let f128_type = self.type_f128();
let fmodf128 = self.context.new_function(
None,
Expand Down Expand Up @@ -1118,7 +1119,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// TODO(antoyo)
}

fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
fn store(&mut self, mut val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
if self.structs_as_pointer.borrow().contains(&val) {
// NOTE: hack to workaround a limitation of the rustc API: see comment on
// CodegenCx.structs_as_pointer
val = val.dereference(self.location).to_rvalue();
}

self.store_with_flags(val, ptr, align, MemFlags::empty())
}

Expand Down Expand Up @@ -1564,16 +1571,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
aggregate_value
}

fn set_personality_fn(&mut self, _personality: RValue<'gcc>) {
fn set_personality_fn(&mut self, _personality: Function<'gcc>) {
#[cfg(feature = "master")]
{
let personality = self.rvalue_as_function(_personality);
self.current_func().set_personality_function(personality);
}
self.current_func().set_personality_function(_personality);
}

#[cfg(feature = "master")]
fn cleanup_landing_pad(&mut self, pers_fn: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
fn cleanup_landing_pad(&mut self, pers_fn: Function<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
self.set_personality_fn(pers_fn);

// NOTE: insert the current block in a variable so that a later call to invoke knows to
Expand All @@ -1594,7 +1598,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
}

#[cfg(not(feature = "master"))]
fn cleanup_landing_pad(&mut self, _pers_fn: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
fn cleanup_landing_pad(&mut self, _pers_fn: Function<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
let value1 = self
.current_func()
.new_local(self.location, self.u8_type.make_pointer(), "landing_pad0")
Expand All @@ -1604,7 +1608,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
(value1, value2)
}

fn filter_landing_pad(&mut self, pers_fn: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
fn filter_landing_pad(&mut self, pers_fn: Function<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
// TODO(antoyo): generate the correct landing pad
self.cleanup_landing_pad(pers_fn)
}
Expand Down Expand Up @@ -2511,8 +2515,8 @@ impl ToGccOrdering for AtomicOrdering {
AtomicOrdering::Relaxed => __ATOMIC_RELAXED, // TODO(antoyo): check if that's the same.
AtomicOrdering::Acquire => __ATOMIC_ACQUIRE,
AtomicOrdering::Release => __ATOMIC_RELEASE,
AtomicOrdering::AcquireRelease => __ATOMIC_ACQ_REL,
AtomicOrdering::SequentiallyConsistent => __ATOMIC_SEQ_CST,
AtomicOrdering::AcqRel => __ATOMIC_ACQ_REL,
AtomicOrdering::SeqCst => __ATOMIC_SEQ_CST,
};
ordering as i32
}
Expand Down
13 changes: 0 additions & 13 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,6 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
match cv {
Scalar::Int(int) => {
let data = int.to_bits(layout.size(self));

// FIXME(antoyo): there's some issues with using the u128 code that follows, so hard-code
// the paths for floating-point values.
// TODO: Remove this code?
/*if ty == self.float_type {
return self
.context
.new_rvalue_from_double(ty, f32::from_bits(data as u32) as f64);
}
if ty == self.double_type {
return self.context.new_rvalue_from_double(ty, f64::from_bits(data as u64));
}*/

let value = self.const_uint_big(self.type_ix(bitsize), data);
let bytesize = layout.size(self).bytes();
if bitsize > 1 && ty.is_integral() && bytesize as u32 == ty.get_size() {
Expand Down
15 changes: 5 additions & 10 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
}

#[cfg_attr(not(feature = "master"), allow(unused_mut))]
fn codegen_static(&self, def_id: DefId) {
fn codegen_static(&mut self, def_id: DefId) {
let attrs = self.tcx.codegen_fn_attrs(def_id);

let Ok((value, alloc)) = codegen_static_initializer(self, def_id) else {
Expand Down Expand Up @@ -150,25 +150,20 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
// TODO(antoyo): set link section.
}

if attrs.flags.contains(CodegenFnAttrFlags::USED)
if attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
|| attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
{
self.add_used_global(global.to_rvalue());
}
}
}

impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
fn add_used_global(&self, _global: RValue<'gcc>) {
pub fn add_used_global(&mut self, _global: RValue<'gcc>) {
// TODO(antoyo)
}

fn add_compiler_used_global(&self, global: RValue<'gcc>) {
// NOTE: seems like GCC does not make the distinction between compiler.used and used.
self.add_used_global(global);
}
}

impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
#[cfg_attr(not(feature = "master"), allow(unused_variables))]
pub fn add_used_function(&self, function: Function<'gcc>) {
#[cfg(feature = "master")]
Expand Down
18 changes: 6 additions & 12 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ pub struct CodegenCx<'gcc, 'tcx> {
/// A counter that is used for generating local symbol names
local_gen_sym_counter: Cell<usize>,

eh_personality: Cell<Option<RValue<'gcc>>>,
eh_personality: Cell<Option<Function<'gcc>>>,
#[cfg(feature = "master")]
pub rust_try_fn: Cell<Option<(Type<'gcc>, Function<'gcc>)>>,

pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,

/// NOTE: a hack is used because the rustc API is not suitable to libgccjit and as such,
/// `const_undef()` returns struct as pointer so that they can later be assigned a value.
/// `const_undef()` returns struct as pointer so that they can later be assigned a value (in
/// e.g. Builder::insert_value).
/// As such, this set remembers which of these pointers were returned by this function so that
/// they can be dereferenced later.
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
Expand Down Expand Up @@ -427,7 +428,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
ptr
}

fn eh_personality(&self) -> RValue<'gcc> {
fn eh_personality(&self) -> Function<'gcc> {
// The exception handling personality function.
//
// If our compilation unit has the `eh_personality` lang item somewhere
Expand Down Expand Up @@ -465,18 +466,15 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let symbol_name = tcx.symbol_name(instance).name;
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
self.linkage.set(FunctionType::Extern);
let func = self.declare_fn(symbol_name, fn_abi);
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
func
self.declare_fn(symbol_name, fn_abi)
}
_ => {
let name = if wants_msvc_seh(self.sess()) {
"__CxxFrameHandler3"
} else {
"rust_eh_personality"
};
let func = self.declare_func(name, self.type_i32(), &[], true);
unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) }
self.declare_func(name, self.type_i32(), &[], true)
}
};
// TODO(antoyo): apply target cpu attributes.
Expand All @@ -488,10 +486,6 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.tcx.sess
}

fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
self.codegen_unit
}

fn set_frame_pointer_type(&self, _llfn: Function<'gcc>) {
// TODO(antoyo)
}
Expand Down
Loading