Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0060d5a

Browse files
committed
Auto merge of #144893 - GuillaumeGomez:subtree-update_cg_gcc_2025年08月04日, r=GuillaumeGomez
GCC backend subtree update cc `@antoyo`
2 parents e1b9081 + 21bd677 commit 0060d5a

File tree

15 files changed

+275
-45
lines changed

15 files changed

+275
-45
lines changed

‎compiler/rustc_codegen_gcc/build_system/src/abi_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn run() -> Result<(), String> {
3131
Some("clones/abi-cafe".as_ref()),
3232
true,
3333
)
34-
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
34+
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;
3535
// Configure abi-cafe to use the exact same rustc version we use - this is crucial.
3636
// Otherwise, the concept of ABI compatibility becomes meanignless.
3737
std::fs::copy("rust-toolchain", "clones/abi-cafe/rust-toolchain")

‎compiler/rustc_codegen_gcc/build_system/src/fuzz.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ pub fn run() -> Result<(), String> {
4343
"--start" => {
4444
start =
4545
str::parse(&args.next().ok_or_else(|| "Fuzz start not provided!".to_string())?)
46-
.map_err(|err| (format!("Fuzz start not a number {err:?}!")))?;
46+
.map_err(|err| format!("Fuzz start not a number {err:?}!"))?;
4747
}
4848
"--count" => {
4949
count =
5050
str::parse(&args.next().ok_or_else(|| "Fuzz count not provided!".to_string())?)
51-
.map_err(|err| (format!("Fuzz count not a number {err:?}!")))?;
51+
.map_err(|err| format!("Fuzz count not a number {err:?}!"))?;
5252
}
5353
"-j" | "--jobs" => {
5454
threads = str::parse(
5555
&args.next().ok_or_else(|| "Fuzz thread count not provided!".to_string())?,
5656
)
57-
.map_err(|err| (format!("Fuzz thread count not a number {err:?}!")))?;
57+
.map_err(|err| format!("Fuzz thread count not a number {err:?}!"))?;
5858
}
5959
_ => return Err(format!("Unknown option {arg}")),
6060
}
@@ -66,7 +66,7 @@ pub fn run() -> Result<(), String> {
6666
Some("clones/rustlantis".as_ref()),
6767
true,
6868
)
69-
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
69+
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;
7070

7171
// Ensure that we are on the newest rustlantis commit.
7272
let cmd: &[&dyn AsRef<OsStr>] = &[&"git", &"pull", &"origin"];
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
From b8f3eed3053c9333b5dfbeaeb2a6a65a4b3156df Mon Sep 17 00:00:00 2001
2-
From: Antoni Boucher <bouanto@zoho.com>
3-
Date: Tue, 29 Aug 2023 13:06:34 -0400
1+
From 190e26c9274b3c93a9ee3516b395590e6bd9213b Mon Sep 17 00:00:00 2001
2+
From: None <none@example.com>
3+
Date: Sun, 3 Aug 2025 19:54:56 -0400
44
Subject: [PATCH] Patch 0001-Add-stdarch-Cargo.toml-for-testing.patch
55

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

1111
diff --git a/library/stdarch/Cargo.toml b/library/stdarch/Cargo.toml
1212
new file mode 100644
13-
index 0000000..4c63700
13+
index 0000000..bd6725c
1414
--- /dev/null
1515
+++ b/library/stdarch/Cargo.toml
16-
@@ -0,0 +1,21 @@
16+
@@ -0,0 +1,20 @@
1717
+[workspace]
1818
+resolver = "1"
1919
+members = [
20-
+ "crates/core_arch",
21-
+ "crates/std_detect",
22-
+ "crates/stdarch-gen-arm",
20+
+ "crates/*",
2321
+ #"examples/"
2422
+]
2523
+exclude = [
26-
+ "crates/wasm-assert-instr-tests"
24+
+ "crates/wasm-assert-instr-tests",
25+
+ "rust_programs",
2726
+]
2827
+
2928
+[profile.release]
@@ -36,5 +35,5 @@ index 0000000..4c63700
3635
+opt-level = 3
3736
+incremental = true
3837
--
39-
2.42.0
38+
2.50.1
4039

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

‎compiler/rustc_codegen_gcc/src/allocator.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ fn create_const_value_function(
9999
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);
100100

101101
#[cfg(feature = "master")]
102-
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
103-
tcx.sess.default_visibility(),
104-
)));
105-
106-
func.add_attribute(FnAttribute::AlwaysInline);
102+
{
103+
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
104+
tcx.sess.default_visibility(),
105+
)));
106+
107+
// FIXME(antoyo): cg_llvm sets AlwaysInline, but AlwaysInline is different in GCC and using
108+
// it here will causes linking errors when using LTO.
109+
func.add_attribute(FnAttribute::Inline);
110+
}
107111

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

‎compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
540540

541541
fn ret(&mut self, mut value: RValue<'gcc>) {
542542
let expected_return_type = self.current_func().get_return_type();
543-
if !expected_return_type.is_compatible_with(value.get_type()) {
544-
// NOTE: due to opaque pointers now being used, we need to cast here.
545-
value = self.context.new_cast(self.location, value, expected_return_type);
543+
let value_type = value.get_type();
544+
if !expected_return_type.is_compatible_with(value_type) {
545+
// NOTE: due to opaque pointers now being used, we need to (bit)cast here.
546+
if self.is_native_int_type(value_type) && self.is_native_int_type(expected_return_type)
547+
{
548+
value = self.context.new_cast(self.location, value, expected_return_type);
549+
} else {
550+
value = self.context.new_bitcast(self.location, value, expected_return_type);
551+
}
546552
}
547553
self.llbb().end_with_return(self.location, value);
548554
}
@@ -1279,11 +1285,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12791285

12801286
fn intcast(
12811287
&mut self,
1282-
value: RValue<'gcc>,
1288+
mutvalue: RValue<'gcc>,
12831289
dest_typ: Type<'gcc>,
1284-
_is_signed: bool,
1290+
is_signed: bool,
12851291
) -> RValue<'gcc> {
1286-
// NOTE: is_signed is for value, not dest_typ.
1292+
let value_type = value.get_type();
1293+
if is_signed && !value_type.is_signed(self.cx) {
1294+
let signed_type = value_type.to_signed(self.cx);
1295+
value = self.gcc_int_cast(value, signed_type);
1296+
} else if !is_signed && value_type.is_signed(self.cx) {
1297+
let unsigned_type = value_type.to_unsigned(self.cx);
1298+
value = self.gcc_int_cast(value, unsigned_type);
1299+
}
1300+
12871301
self.gcc_int_cast(value, dest_typ)
12881302
}
12891303

‎compiler/rustc_codegen_gcc/src/int.rs

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
55
// cSpell:words cmpti divti modti mulodi muloti udivti umodti
66

7-
use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp};
7+
use gccjit::{
8+
BinaryOp, CType, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp,
9+
};
810
use rustc_abi::{CanonAbi, Endian, ExternAbi};
911
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
1012
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
1113
use rustc_middle::ty::{self, Ty};
1214
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
15+
use rustc_type_ir::{Interner, TyKind};
1316

1417
use crate::builder::{Builder, ToGccComp};
1518
use crate::common::{SignType, TypeReflection};
@@ -167,9 +170,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
167170
if a_type.is_vector() {
168171
// Vector types need to be bitcast.
169172
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
170-
b = self.context.new_bitcast(self.location, b, a.get_type());
173+
b = self.context.new_bitcast(self.location, b, a_type);
171174
} else {
172-
b = self.context.new_cast(self.location, b, a.get_type());
175+
b = self.context.new_cast(self.location, b, a_type);
173176
}
174177
}
175178
self.context.new_binary_op(self.location, operation, a_type, a, b)
@@ -216,13 +219,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
216219
operation_name: &str,
217220
signed: bool,
218221
a: RValue<'gcc>,
219-
b: RValue<'gcc>,
222+
mutb: RValue<'gcc>,
220223
) -> RValue<'gcc> {
221224
let a_type = a.get_type();
222225
let b_type = b.get_type();
223226
if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type))
224227
|| (a_type.is_vector() && b_type.is_vector())
225228
{
229+
if !a_type.is_compatible_with(b_type) {
230+
if a_type.is_vector() {
231+
// Vector types need to be bitcast.
232+
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
233+
b = self.context.new_bitcast(self.location, b, a_type);
234+
} else {
235+
b = self.context.new_cast(self.location, b, a_type);
236+
}
237+
}
226238
self.context.new_binary_op(self.location, operation, a_type, a, b)
227239
} else {
228240
debug_assert!(a_type.dyncast_array().is_some());
@@ -351,6 +363,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
351363
// TODO(antoyo): is it correct to use rhs type instead of the parameter typ?
352364
.new_local(self.location, rhs.get_type(), "binopResult")
353365
.get_address(self.location);
366+
let new_type = type_kind_to_gcc_type(new_kind);
367+
let new_type = self.context.new_c_type(new_type);
368+
let lhs = self.context.new_cast(self.location, lhs, new_type);
369+
let rhs = self.context.new_cast(self.location, rhs, new_type);
370+
let res = self.context.new_cast(self.location, res, new_type.make_pointer());
354371
let overflow = self.overflow_call(intrinsic, &[lhs, rhs, res], None);
355372
(res.dereference(self.location).to_rvalue(), overflow)
356373
}
@@ -477,11 +494,27 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
477494
let lhs_low = self.context.new_cast(self.location, self.low(lhs), unsigned_type);
478495
let rhs_low = self.context.new_cast(self.location, self.low(rhs), unsigned_type);
479496

497+
let mut lhs_high = self.high(lhs);
498+
let mut rhs_high = self.high(rhs);
499+
500+
match op {
501+
IntPredicate::IntUGT
502+
| IntPredicate::IntUGE
503+
| IntPredicate::IntULT
504+
| IntPredicate::IntULE => {
505+
lhs_high = self.context.new_cast(self.location, lhs_high, unsigned_type);
506+
rhs_high = self.context.new_cast(self.location, rhs_high, unsigned_type);
507+
}
508+
// TODO(antoyo): we probably need to handle signed comparison for unsigned
509+
// integers.
510+
_ => (),
511+
}
512+
480513
let condition = self.context.new_comparison(
481514
self.location,
482515
ComparisonOp::LessThan,
483-
self.high(lhs),
484-
self.high(rhs),
516+
lhs_high,
517+
rhs_high,
485518
);
486519
self.llbb().end_with_conditional(self.location, condition, block1, block2);
487520

@@ -495,8 +528,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
495528
let condition = self.context.new_comparison(
496529
self.location,
497530
ComparisonOp::GreaterThan,
498-
self.high(lhs),
499-
self.high(rhs),
531+
lhs_high,
532+
rhs_high,
500533
);
501534
block2.end_with_conditional(self.location, condition, block3, block4);
502535

@@ -620,14 +653,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
620653
}
621654
}
622655

623-
pub fn gcc_xor(&self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
656+
pub fn gcc_xor(&self, a: RValue<'gcc>, mutb: RValue<'gcc>) -> RValue<'gcc> {
624657
let a_type = a.get_type();
625658
let b_type = b.get_type();
626659
if a_type.is_vector() && b_type.is_vector() {
627660
let b = self.bitcast_if_needed(b, a_type);
628661
a ^ b
629662
} else if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)
630663
{
664+
if !a_type.is_compatible_with(b_type) {
665+
b = self.context.new_cast(self.location, b, a_type);
666+
}
631667
a ^ b
632668
} else {
633669
self.concat_low_high_rvalues(
@@ -1042,3 +1078,25 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
10421078
self.context.new_array_constructor(None, typ, &values)
10431079
}
10441080
}
1081+
1082+
fn type_kind_to_gcc_type<I: Interner>(kind: TyKind<I>) -> CType {
1083+
use rustc_middle::ty::IntTy::*;
1084+
use rustc_middle::ty::UintTy::*;
1085+
use rustc_middle::ty::{Int, Uint};
1086+
1087+
match kind {
1088+
Int(I8) => CType::Int8t,
1089+
Int(I16) => CType::Int16t,
1090+
Int(I32) => CType::Int32t,
1091+
Int(I64) => CType::Int64t,
1092+
Int(I128) => CType::Int128t,
1093+
1094+
Uint(U8) => CType::UInt8t,
1095+
Uint(U16) => CType::UInt16t,
1096+
Uint(U32) => CType::UInt32t,
1097+
Uint(U64) => CType::UInt64t,
1098+
Uint(U128) => CType::UInt128t,
1099+
1100+
_ => unimplemented!("Kind: {:?}", kind),
1101+
}
1102+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /