Skip to content

Sync from rust 2025/07/21 #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0e3d408
Remove LtoModuleCodegen
bjorn3 Jul 3, 2025
d9f9bcf
Move dcx creation into WriteBackendMethods::codegen
bjorn3 Jul 3, 2025
9404a11
Remove unused config param from WriteBackendMethods::autodiff
bjorn3 Jul 3, 2025
bf4daef
Merge run_fat_lto, optimize_fat and autodiff into run_and_optimize_fa…
bjorn3 Jul 3, 2025
7cce6af
Make __rust_alloc_error_handler_should_panic a function
dpaoliello Jul 3, 2025
7b1674d
Use `object` crate from crates.io to fix windows build error
Diggsey Jul 5, 2025
214311b
Make tempfile a normal dependency
Diggsey Jul 5, 2025
303a795
compiler: Parse `p-` specs in datalayout string, allow definition of …
xdoardo Jun 29, 2025
dffe77d
Remove unused allow attrs
yotamofek Jun 28, 2025
8e50ef3
Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee
bors Jul 7, 2025
981dda8
Auto merge of #143601 - matthiaskrgr:rollup-9iw2sqk, r=matthiaskrgr
bors Jul 7, 2025
46836c3
Remove support for dynamic allocas
mejrs Jun 24, 2025
3d5b177
Add opaque TypeId handles for CTFE
oli-obk Mar 12, 2025
48117e8
Auto merge of #142911 - mejrs:unsized, r=compiler-errors
bors Jul 11, 2025
e55baf9
use `codegen_instance_attrs` where an instance is (easily) available
folkertdev Jul 2, 2025
7ff6135
Rollup merge of #143388 - bjorn3:lto_refactors, r=compiler-errors
fmease Jul 17, 2025
2396109
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-…
matthiaskrgr Jul 18, 2025
d088fb7
Merge commit 'f682d09eefc6700b9e5851ef193847959acf4fac' into subtree-…
GuillaumeGomez Jul 18, 2025
4475b1c
Remove forgotten git annotations
GuillaumeGomez Jul 18, 2025
da63add
Merge branch 'master' into sync_from_rust_2025_07_21
antoyo Jul 21, 2025
c1be95c
Add missing inline attribute
antoyo Jul 21, 2025
cf80eee
Fix clippy warnings
antoyo Jul 21, 2025
18cc4f0
Fix spelling mistakes
antoyo Jul 21, 2025
d466953
Fix failing UI tests
antoyo Jul 22, 2025
a4fb579
Fix compilation of overflow addition
antoyo Jul 22, 2025
27f3a97
Use a bitcast in Builder::ret to support non-native integers
antoyo Jul 22, 2025
a5bd9d6
Fix spelling mistake
antoyo Jul 22, 2025
9ea1827
Fix sysroot compilation in release mode
antoyo Jul 22, 2025
de5cf68
Remove failing UI test
antoyo Jul 22, 2025
ba18e20
Remove failing run-make test
antoyo Jul 22, 2025
041be62
Add failing UI tests
antoyo Jul 22, 2025
3c35d9b
Add missing cast in gcc_checked_binop
antoyo Jul 22, 2025
d3a61f8
Remove failing UI test
antoyo Jul 22, 2025
d05542a
Add missing cast in gcc_checked_binop
antoyo Jul 22, 2025
2b64021
Fix gcc_icmp with non-native integers
antoyo Jul 23, 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
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ dependencies = [
"libc",
]

[[package]]
name = "object"
version = "0.37.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a"
dependencies = [
"memchr",
]

[[package]]
name = "once_cell"
version = "1.20.2"
Expand Down Expand Up @@ -179,6 +188,7 @@ dependencies = [
"boml",
"gccjit",
"lang_tester",
"object",
"tempfile",
]

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ master = ["gccjit/master"]
default = ["master"]

[dependencies]
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
tempfile = "3.20"
gccjit = "2.7"
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }

Expand All @@ -31,7 +33,6 @@ gccjit = "2.7"
[dev-dependencies]
boml = "0.3.1"
lang_tester = "0.8.0"
tempfile = "3.20"

[profile.dev]
# By compiling dependencies with optimizations, performing tests gets much faster.
Expand Down
2 changes: 1 addition & 1 deletion build_system/src/abi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn run() -> Result<(), String> {
Some("clones/abi-cafe".as_ref()),
true,
)
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;
// Configure abi-cafe to use the exact same rustc version we use - this is crucial.
// Otherwise, the concept of ABI compatibility becomes meanignless.
std::fs::copy("rust-toolchain", "clones/abi-cafe/rust-toolchain")
Expand Down
8 changes: 4 additions & 4 deletions build_system/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ pub fn run() -> Result<(), String> {
"--start" => {
start =
str::parse(&args.next().ok_or_else(|| "Fuzz start not provided!".to_string())?)
.map_err(|err| (format!("Fuzz start not a number {err:?}!")))?;
.map_err(|err| format!("Fuzz start not a number {err:?}!"))?;
}
"--count" => {
count =
str::parse(&args.next().ok_or_else(|| "Fuzz count not provided!".to_string())?)
.map_err(|err| (format!("Fuzz count not a number {err:?}!")))?;
.map_err(|err| format!("Fuzz count not a number {err:?}!"))?;
}
"-j" | "--jobs" => {
threads = str::parse(
&args.next().ok_or_else(|| "Fuzz thread count not provided!".to_string())?,
)
.map_err(|err| (format!("Fuzz thread count not a number {err:?}!")))?;
.map_err(|err| format!("Fuzz thread count not a number {err:?}!"))?;
}
_ => return Err(format!("Unknown option {arg}")),
}
Expand All @@ -66,7 +66,7 @@ pub fn run() -> Result<(), String> {
Some("clones/rustlantis".as_ref()),
true,
)
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;

// Ensure that we are on the newest rustlantis commit.
let cmd: &[&dyn AsRef<OsStr>] = &[&"git", &"pull", &"origin"];
Expand Down
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-07-04"
channel = "nightly-2025-07-21"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
47 changes: 36 additions & 11 deletions src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
#[cfg(feature = "master")]
use gccjit::{FnAttribute, VarAttribute};
use gccjit::FnAttribute;
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
use rustc_ast::expand::allocator::{
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
alloc_error_handler_name, default_fn_name, global_fn_name,
Expand Down Expand Up @@ -71,15 +71,13 @@ pub(crate) unsafe fn codegen(
None,
);

let name = mangle_internal_symbol(tcx, OomStrategy::SYMBOL);
let global = context.new_global(None, GlobalKind::Exported, i8, name);
#[cfg(feature = "master")]
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
tcx.sess.default_visibility(),
)));
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
let value = context.new_rvalue_from_int(i8, value as i32);
global.global_set_initializer_rvalue(value);
create_const_value_function(
tcx,
context,
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
i8,
context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
);

create_wrapper_function(
tcx,
Expand All @@ -91,6 +89,33 @@ pub(crate) unsafe fn codegen(
);
}

fn create_const_value_function(
tcx: TyCtxt<'_>,
context: &Context<'_>,
name: &str,
output: Type<'_>,
value: RValue<'_>,
) {
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);

#[cfg(feature = "master")]
{
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
tcx.sess.default_visibility(),
)));

func.add_attribute(FnAttribute::AlwaysInline);
func.add_attribute(FnAttribute::Inline);
}

if tcx.sess.must_emit_unwind_tables() {
// TODO(antoyo): emit unwind tables.
}

let block = func.new_block("entry");
block.end_with_return(None, value);
}

fn create_wrapper_function(
tcx: TyCtxt<'_>,
context: &Context<'_>,
Expand Down
2 changes: 1 addition & 1 deletion src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
#[cfg_attr(not(feature = "master"), allow(unused_variables))] func: Function<'gcc>,
instance: ty::Instance<'tcx>,
) {
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
let codegen_fn_attrs = cx.tcx.codegen_instance_attrs(instance.def);

#[cfg(feature = "master")]
{
Expand Down
15 changes: 7 additions & 8 deletions src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::sync::Arc;

use gccjit::{Context, OutputKind};
use object::read::archive::ArchiveFile;
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
use rustc_codegen_ssa::back::symbol_export;
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -176,7 +176,7 @@ pub(crate) fn run_fat(
cgcx: &CodegenContext<GccCodegenBackend>,
modules: Vec<FatLtoInput<GccCodegenBackend>>,
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
) -> Result<ModuleCodegen<GccContext>, FatalError> {
let dcx = cgcx.create_dcx();
let dcx = dcx.handle();
let lto_data = prepare_lto(cgcx, dcx)?;
Expand All @@ -201,7 +201,7 @@ fn fat_lto(
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
tmp_path: TempDir,
//symbols_below_threshold: &[String],
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
) -> Result<ModuleCodegen<GccContext>, FatalError> {
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
info!("going for a fat lto");

Expand Down Expand Up @@ -334,7 +334,7 @@ fn fat_lto(
// of now.
module.module_llvm.temp_dir = Some(tmp_path);

Ok(LtoModuleCodegen::Fat(module))
Ok(module)
}

pub struct ModuleBuffer(PathBuf);
Expand All @@ -358,7 +358,7 @@ pub(crate) fn run_thin(
cgcx: &CodegenContext<GccCodegenBackend>,
modules: Vec<(String, ThinBuffer)>,
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
let dcx = cgcx.create_dcx();
let dcx = dcx.handle();
let lto_data = prepare_lto(cgcx, dcx)?;
Expand Down Expand Up @@ -427,7 +427,7 @@ fn thin_lto(
tmp_path: TempDir,
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
//_symbols_below_threshold: &[String],
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
info!("going for that thin, thin LTO");

Expand Down Expand Up @@ -573,8 +573,7 @@ fn thin_lto(
}*/

info!(" - {}: re-compiled", module_name);
opt_jobs
.push(LtoModuleCodegen::Thin(ThinModule { shared: shared.clone(), idx: module_index }));
opt_jobs.push(ThinModule { shared: shared.clone(), idx: module_index });
}

// Save the current ThinLTO import information for the next compilation
Expand Down
4 changes: 3 additions & 1 deletion src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use crate::{GccCodegenBackend, GccContext};

pub(crate) fn codegen(
cgcx: &CodegenContext<GccCodegenBackend>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<GccContext>,
config: &ModuleConfig,
) -> Result<CompiledModule, FatalError> {
let dcx = cgcx.create_dcx();
let dcx = dcx.handle();

let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
{
let context = &module.module_llvm.context;
Expand Down
8 changes: 2 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
fn ret(&mut self, mut value: RValue<'gcc>) {
let expected_return_type = self.current_func().get_return_type();
if !expected_return_type.is_compatible_with(value.get_type()) {
// NOTE: due to opaque pointers now being used, we need to cast here.
value = self.context.new_cast(self.location, value, expected_return_type);
// NOTE: due to opaque pointers now being used, we need to bitcast here.
value = self.context.new_bitcast(self.location, value, expected_return_type);
}
self.llbb().end_with_return(self.location, value);
}
Expand Down Expand Up @@ -926,10 +926,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
.get_address(self.location)
}

fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
unimplemented!();
}

fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
let block = self.llbb();
let function = block.get_function();
Expand Down
2 changes: 1 addition & 1 deletion src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
let is_hidden = if is_generic {
// This is a monomorphization of a generic function.
if !(cx.tcx.sess.opts.share_generics()
|| tcx.codegen_fn_attrs(instance_def_id).inline
|| tcx.codegen_instance_attrs(instance.def).inline
== rustc_attr_data_structures::InlineAttr::Never)
{
// When not sharing generics, all instances are in the same
Expand Down
12 changes: 9 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use gccjit::{LValue, RValue, ToRValue, Type};
use rustc_abi as abi;
use rustc_abi::HasDataLayout;
use rustc_abi::Primitive::Pointer;
use rustc_abi::{self as abi, HasDataLayout};
use rustc_codegen_ssa::traits::{
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods,
};
Expand Down Expand Up @@ -162,7 +161,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
}

fn const_usize(&self, i: u64) -> RValue<'gcc> {
let bit_size = self.data_layout().pointer_size.bits();
let bit_size = self.data_layout().pointer_size().bits();
if bit_size < 64 {
// make sure it doesn't overflow
assert!(i < (1 << bit_size));
Expand Down Expand Up @@ -282,6 +281,13 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
let init = self.const_data_from_alloc(alloc);
self.static_addr_of(init, alloc.inner().align, None)
}
GlobalAlloc::TypeId { .. } => {
let val = self.const_usize(offset.bytes());
// This is still a variable of pointer type, even though we only use the provenance
// of that pointer in CTFE and Miri. But to make LLVM's type system happy,
// we need an int-to-ptr cast here (it doesn't matter at all which provenance that picks).
return self.context.new_cast(None, val, ty);
}
GlobalAlloc::Static(def_id) => {
assert!(self.tcx.is_static(def_id));
self.get_static(def_id).get_address(None)
Expand Down
4 changes: 2 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
let alloc = alloc.inner();
let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);
let dl = cx.data_layout();
let pointer_size = dl.pointer_size.bytes() as usize;
let pointer_size = dl.pointer_size().bytes() as usize;

let mut next_offset = 0;
for &(offset, prov) in alloc.provenance().ptrs().iter() {
Expand Down Expand Up @@ -331,7 +331,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
),
abi::Scalar::Initialized {
value: Primitive::Pointer(address_space),
valid_range: WrappingRange::full(dl.pointer_size),
valid_range: WrappingRange::full(dl.pointer_size()),
},
cx.type_i8p_ext(address_space),
));
Expand Down
Loading
Loading