Skip to content

GCC backend subtree update #144893

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 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
8b8ffa8
Merge modules and cached_modules for fat LTO
bjorn3 Jul 4, 2025
803ada7
Move LTO symbol export calculation from backends to cg_ssa
bjorn3 Jul 4, 2025
df53678
Merge exported_symbols computation into exported_symbols_for_lto
bjorn3 Jul 6, 2025
ecab766
Move exported_symbols_for_lto out of CodegenContext
bjorn3 Jul 6, 2025
28ccfad
Remove each_linked_rlib_for_lto from CodegenContext
bjorn3 Jul 6, 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
af8cb1d
Rename `tests/assembly` into `tests/assembly-llvm`
GuillaumeGomez 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
a4ac1e4
Auto merge of #144062 - bjorn3:lto_refactors2, r=davidtwco
bors Jul 24, 2025
d852f7c
Implement support for explicit tail calls in the MIR block builders a…
xacrimon Jul 25, 2025
013b3eb
Remove support for -Zcombine-cgu
bjorn3 Jul 6, 2025
4f8d4ca
Update `codegen_{cranelift,gcc}` and `opt-dist` to use `build.compile…
jieyouxu Jul 30, 2025
9fb9910
Regenerate intrinsics mapping
GuillaumeGomez Jul 30, 2025
2e94f54
Merge pull request #745 from GuillaumeGomez/regen
antoyo Jul 30, 2025
dcd72a6
Rollup merge of #144232 - xacrimon:explicit-tail-call, r=WaffleLapkin
Zalathar Jul 31, 2025
f638ebc
remove rustc_attr_data_structures
jdonszelmann Jul 31, 2025
8a2a9db
Fix LTO errors by not adding AlwaysInline to __rust_alloc_error_handl…
antoyo Aug 1, 2025
071606b
Add failing LTO test
antoyo Aug 1, 2025
bc5c222
Fix issues in count_leading_zeroes
antoyo Aug 1, 2025
e3a6469
Implement SIMD funnel shifts
antoyo Aug 1, 2025
035ff85
Fix intcast to use the is_signed parameter
antoyo Aug 3, 2025
6816513
Only use bitcast in Builder::ret for non-native integers
antoyo Aug 3, 2025
566c9ae
Fix simd_funnel_shift
antoyo Aug 3, 2025
36a516d
Merge pull request #740 from rust-lang/sync_from_rust_2025_07_21
antoyo Aug 3, 2025
3f48eed
Merge branch 'master' into sync_from_rust_2025_08_03
antoyo Aug 3, 2025
6b363ae
Update to nightly-2025-08-03
antoyo Aug 3, 2025
24f1751
Add new failing test
antoyo Aug 3, 2025
dac1f34
Fix stdarch patch
antoyo Aug 3, 2025
482e854
Merge pull request #746 from rust-lang/sync_from_rust_2025_08_03
antoyo Aug 4, 2025
21bd677
Merge commit '482e8540a1b757ed7bccc2041c5400f051fdb01e' into subtree-…
GuillaumeGomez Aug 4, 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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/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 compiler/rustc_codegen_gcc/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
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
From b8f3eed3053c9333b5dfbeaeb2a6a65a4b3156df Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Tue, 29 Aug 2023 13:06:34 -0400
From 190e26c9274b3c93a9ee3516b395590e6bd9213b Mon Sep 17 00:00:00 2001
From: None <none@example.com>
Date: Sun, 3 Aug 2025 19:54:56 -0400
Subject: [PATCH] Patch 0001-Add-stdarch-Cargo.toml-for-testing.patch

---
library/stdarch/Cargo.toml | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
library/stdarch/Cargo.toml | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 library/stdarch/Cargo.toml

diff --git a/library/stdarch/Cargo.toml b/library/stdarch/Cargo.toml
new file mode 100644
index 0000000..4c63700
index 0000000..bd6725c
--- /dev/null
+++ b/library/stdarch/Cargo.toml
@@ -0,0 +1,21 @@
@@ -0,0 +1,20 @@
+[workspace]
+resolver = "1"
+members = [
+ "crates/core_arch",
+ "crates/std_detect",
+ "crates/stdarch-gen-arm",
+ "crates/*",
+ #"examples/"
+]
+exclude = [
+ "crates/wasm-assert-instr-tests"
+ "crates/wasm-assert-instr-tests",
+ "rust_programs",
+]
+
+[profile.release]
Expand All @@ -36,5 +35,5 @@ index 0000000..4c63700
+opt-level = 3
+incremental = true
--
2.42.0
2.50.1

2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/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-08-03"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
14 changes: 9 additions & 5 deletions compiler/rustc_codegen_gcc/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ fn create_const_value_function(
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::Visibility(symbol_visibility_to_gcc(
tcx.sess.default_visibility(),
)));

// FIXME(antoyo): cg_llvm sets AlwaysInline, but AlwaysInline is different in GCC and using
// it here will causes linking errors when using LTO.
func.add_attribute(FnAttribute::Inline);
}

if tcx.sess.must_emit_unwind_tables() {
// TODO(antoyo): emit unwind tables.
Expand Down
26 changes: 20 additions & 6 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,15 @@ 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);
let value_type = value.get_type();
if !expected_return_type.is_compatible_with(value_type) {
// NOTE: due to opaque pointers now being used, we need to (bit)cast here.
if self.is_native_int_type(value_type) && self.is_native_int_type(expected_return_type)
{
value = self.context.new_cast(self.___location, value, expected_return_type);
} else {
value = self.context.new_bitcast(self.___location, value, expected_return_type);
}
}
self.llbb().end_with_return(self.___location, value);
}
Expand Down Expand Up @@ -1279,11 +1285,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {

fn intcast(
&mut self,
value: RValue<'gcc>,
mut value: RValue<'gcc>,
dest_typ: Type<'gcc>,
_is_signed: bool,
is_signed: bool,
) -> RValue<'gcc> {
// NOTE: is_signed is for value, not dest_typ.
let value_type = value.get_type();
if is_signed && !value_type.is_signed(self.cx) {
let signed_type = value_type.to_signed(self.cx);
value = self.gcc_int_cast(value, signed_type);
} else if !is_signed && value_type.is_signed(self.cx) {
let unsigned_type = value_type.to_unsigned(self.cx);
value = self.gcc_int_cast(value, unsigned_type);
}

self.gcc_int_cast(value, dest_typ)
}

Expand Down
76 changes: 67 additions & 9 deletions compiler/rustc_codegen_gcc/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

// cSpell:words cmpti divti modti mulodi muloti udivti umodti

use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp};
use gccjit::{
BinaryOp, CType, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp,
};
use rustc_abi::{CanonAbi, Endian, ExternAbi};
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
use rustc_middle::ty::{self, Ty};
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use rustc_type_ir::{Interner, TyKind};

use crate::builder::{Builder, ToGccComp};
use crate::common::{SignType, TypeReflection};
Expand Down Expand Up @@ -167,9 +170,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
if a_type.is_vector() {
// Vector types need to be bitcast.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
b = self.context.new_bitcast(self.___location, b, a.get_type());
b = self.context.new_bitcast(self.___location, b, a_type);
} else {
b = self.context.new_cast(self.___location, b, a.get_type());
b = self.context.new_cast(self.___location, b, a_type);
}
}
self.context.new_binary_op(self.___location, operation, a_type, a, b)
Expand Down Expand Up @@ -216,13 +219,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
operation_name: &str,
signed: bool,
a: RValue<'gcc>,
b: RValue<'gcc>,
mut b: RValue<'gcc>,
) -> RValue<'gcc> {
let a_type = a.get_type();
let b_type = b.get_type();
if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type))
|| (a_type.is_vector() && b_type.is_vector())
{
if !a_type.is_compatible_with(b_type) {
if a_type.is_vector() {
// Vector types need to be bitcast.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
b = self.context.new_bitcast(self.___location, b, a_type);
} else {
b = self.context.new_cast(self.___location, b, a_type);
}
}
self.context.new_binary_op(self.___location, operation, a_type, a, b)
} else {
debug_assert!(a_type.dyncast_array().is_some());
Expand Down Expand Up @@ -351,6 +363,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// TODO(antoyo): is it correct to use rhs type instead of the parameter typ?
.new_local(self.___location, rhs.get_type(), "binopResult")
.get_address(self.___location);
let new_type = type_kind_to_gcc_type(new_kind);
let new_type = self.context.new_c_type(new_type);
let lhs = self.context.new_cast(self.___location, lhs, new_type);
let rhs = self.context.new_cast(self.___location, rhs, new_type);
let res = self.context.new_cast(self.___location, res, new_type.make_pointer());
let overflow = self.overflow_call(intrinsic, &[lhs, rhs, res], None);
(res.dereference(self.___location).to_rvalue(), overflow)
}
Expand Down Expand Up @@ -477,11 +494,27 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let lhs_low = self.context.new_cast(self.___location, self.low(lhs), unsigned_type);
let rhs_low = self.context.new_cast(self.___location, self.low(rhs), unsigned_type);

let mut lhs_high = self.high(lhs);
let mut rhs_high = self.high(rhs);

match op {
IntPredicate::IntUGT
| IntPredicate::IntUGE
| IntPredicate::IntULT
| IntPredicate::IntULE => {
lhs_high = self.context.new_cast(self.___location, lhs_high, unsigned_type);
rhs_high = self.context.new_cast(self.___location, rhs_high, unsigned_type);
}
// TODO(antoyo): we probably need to handle signed comparison for unsigned
// integers.
_ => (),
}

let condition = self.context.new_comparison(
self.___location,
ComparisonOp::LessThan,
self.high(lhs),
self.high(rhs),
lhs_high,
rhs_high,
);
self.llbb().end_with_conditional(self.___location, condition, block1, block2);

Expand All @@ -495,8 +528,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let condition = self.context.new_comparison(
self.___location,
ComparisonOp::GreaterThan,
self.high(lhs),
self.high(rhs),
lhs_high,
rhs_high,
);
block2.end_with_conditional(self.___location, condition, block3, block4);

Expand Down Expand Up @@ -620,14 +653,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
}
}

pub fn gcc_xor(&self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
pub fn gcc_xor(&self, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> {
let a_type = a.get_type();
let b_type = b.get_type();
if a_type.is_vector() && b_type.is_vector() {
let b = self.bitcast_if_needed(b, a_type);
a ^ b
} else if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)
{
if !a_type.is_compatible_with(b_type) {
b = self.context.new_cast(self.___location, b, a_type);
}
a ^ b
} else {
self.concat_low_high_rvalues(
Expand Down Expand Up @@ -1042,3 +1078,25 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
self.context.new_array_constructor(None, typ, &values)
}
}

fn type_kind_to_gcc_type<I: Interner>(kind: TyKind<I>) -> CType {
use rustc_middle::ty::IntTy::*;
use rustc_middle::ty::UintTy::*;
use rustc_middle::ty::{Int, Uint};

match kind {
Int(I8) => CType::Int8t,
Int(I16) => CType::Int16t,
Int(I32) => CType::Int32t,
Int(I64) => CType::Int64t,
Int(I128) => CType::Int128t,

Uint(U8) => CType::UInt8t,
Uint(U16) => CType::UInt16t,
Uint(U32) => CType::UInt32t,
Uint(U64) => CType::UInt64t,
Uint(U128) => CType::UInt128t,

_ => unimplemented!("Kind: {:?}", kind),
}
}
Loading
Loading