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 f26e580

Browse files
committed
Auto merge of #143239 - GuillaumeGomez:subtree-update_cg_gcc_2025年06月30日, r=GuillaumeGomez
GCC backend subtree update cc `@antoyo` r? ghost
2 parents c65dcca + 666934a commit f26e580

File tree

12 files changed

+131
-171
lines changed

12 files changed

+131
-171
lines changed

‎compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resolver = "2"
66

77
[dependencies]
88
core = { path = "./sysroot_src/library/core" }
9+
compiler_builtins = { path = "./sysroot_src/library/compiler-builtins/compiler-builtins" }
910
alloc = { path = "./sysroot_src/library/alloc" }
1011
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1112
test = { path = "./sysroot_src/library/test" }

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::build;
99
use crate::config::{Channel, ConfigInfo};
1010
use crate::utils::{
1111
create_dir, get_sysroot_dir, get_toolchain, git_clone, git_clone_root_dir, remove_file,
12-
run_command, run_command_with_env, run_command_with_output, run_command_with_output_and_env,
13-
rustc_version_info,split_args, walk_dir,
12+
run_command, run_command_with_env, run_command_with_output_and_env, rustc_version_info,
13+
split_args, walk_dir,
1414
};
1515

1616
type Env = HashMap<String, String>;
@@ -485,30 +485,6 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
485485
run_command_with_output_and_env(&[&"git", &"checkout"], rust_dir, Some(env))?;
486486
}
487487

488-
let mut patches = Vec::new();
489-
walk_dir(
490-
"patches/tests",
491-
&mut |_| Ok(()),
492-
&mut |file_path: &Path| {
493-
patches.push(file_path.to_path_buf());
494-
Ok(())
495-
},
496-
false,
497-
)?;
498-
patches.sort();
499-
// TODO: remove duplication with prepare.rs by creating a apply_patch function in the utils
500-
// module.
501-
for file_path in patches {
502-
println!("[GIT] apply `{}`", file_path.display());
503-
let path = Path::new("../..").join(file_path);
504-
run_command_with_output(&[&"git", &"apply", &path], rust_dir)?;
505-
run_command_with_output(&[&"git", &"add", &"-A"], rust_dir)?;
506-
run_command_with_output(
507-
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
508-
rust_dir,
509-
)?;
510-
}
511-
512488
let cargo = String::from_utf8(
513489
run_command_with_env(&[&"rustup", &"which", &"cargo"], rust_dir, Some(env))?.stdout,
514490
)

‎compiler/rustc_codegen_gcc/patches/tests/0001-Workaround-to-make-a-run-make-test-pass.patch‎

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2025-06-02"
2+
channel = "nightly-2025-06-28"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

‎compiler/rustc_codegen_gcc/src/abi.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
33
use gccjit::{ToLValue, ToRValue, Type};
4-
use rustc_abi::{ArmCall, CanonAbi, InterruptKind, Reg, RegKind, X86Call};
4+
#[cfg(feature = "master")]
5+
use rustc_abi::{ArmCall, CanonAbi, InterruptKind, X86Call};
6+
use rustc_abi::{Reg, RegKind};
57
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods};
68
use rustc_data_structures::fx::FxHashSet;
79
use rustc_middle::bug;

‎compiler/rustc_codegen_gcc/src/builder.rs‎

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
538538
}
539539

540540
fn ret(&mut self, mut value: RValue<'gcc>) {
541-
if self.structs_as_pointer.borrow().contains(&value) {
542-
// NOTE: hack to workaround a limitation of the rustc API: see comment on
543-
// CodegenCx.structs_as_pointer
544-
value = value.dereference(self.location).to_rvalue();
545-
}
546541
let expected_return_type = self.current_func().get_return_type();
547542
if !expected_return_type.is_compatible_with(value.get_type()) {
548543
// NOTE: due to opaque pointers now being used, we need to cast here.
@@ -700,7 +695,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
700695
let a = self.gcc_int_cast(a, a_type);
701696
let b_type = b.get_type().to_unsigned(self);
702697
let b = self.gcc_int_cast(b, b_type);
703-
a / b
698+
self.gcc_udiv(a, b)
704699
}
705700

706701
fn sdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
@@ -712,8 +707,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
712707
// FIXME(antoyo): rustc_codegen_ssa::mir::intrinsic uses different types for a and b but they
713708
// should be the same.
714709
let typ = a.get_type().to_signed(self);
715-
let b = self.context.new_cast(self.location,b, typ);
716-
a / b
710+
let b = self.gcc_int_cast(b, typ);
711+
self.gcc_sdiv(a, b)
717712
}
718713

719714
fn fdiv(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
@@ -1119,13 +1114,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11191114
// TODO(antoyo)
11201115
}
11211116

1122-
fn store(&mut self, mut val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
1123-
if self.structs_as_pointer.borrow().contains(&val) {
1124-
// NOTE: hack to workaround a limitation of the rustc API: see comment on
1125-
// CodegenCx.structs_as_pointer
1126-
val = val.dereference(self.location).to_rvalue();
1127-
}
1128-
1117+
fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
11291118
self.store_with_flags(val, ptr, align, MemFlags::empty())
11301119
}
11311120

@@ -1508,16 +1497,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15081497
element.get_address(self.location)
15091498
} else if value_type.dyncast_vector().is_some() {
15101499
panic!();
1511-
} else if let Some(pointer_type) = value_type.get_pointee() {
1512-
if let Some(struct_type) = pointer_type.is_struct() {
1513-
// NOTE: hack to workaround a limitation of the rustc API: see comment on
1514-
// CodegenCx.structs_as_pointer
1515-
aggregate_value
1516-
.dereference_field(self.location, struct_type.get_field(idx as i32))
1517-
.to_rvalue()
1518-
} else {
1519-
panic!("Unexpected type {:?}", value_type);
1520-
}
15211500
} else if let Some(struct_type) = value_type.is_struct() {
15221501
aggregate_value
15231502
.access_field(self.location, struct_type.get_field(idx as i32))
@@ -1537,21 +1516,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15371516
assert_eq!(idx as usize as u64, idx);
15381517
let value_type = aggregate_value.get_type();
15391518

1519+
let new_val = self.current_func().new_local(None, value_type, "aggregate_value");
1520+
self.block.add_assignment(None, new_val, aggregate_value);
1521+
15401522
let lvalue = if value_type.dyncast_array().is_some() {
15411523
let index = self
15421524
.context
15431525
.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
1544-
self.context.new_array_access(self.location, aggregate_value, index)
1526+
self.context.new_array_access(self.location, new_val, index)
15451527
} else if value_type.dyncast_vector().is_some() {
15461528
panic!();
1547-
} else if let Some(pointer_type) = value_type.get_pointee() {
1548-
if let Some(struct_type) = pointer_type.is_struct() {
1549-
// NOTE: hack to workaround a limitation of the rustc API: see comment on
1550-
// CodegenCx.structs_as_pointer
1551-
aggregate_value.dereference_field(self.location, struct_type.get_field(idx as i32))
1552-
} else {
1553-
panic!("Unexpected type {:?}", value_type);
1554-
}
1529+
} else if let Some(struct_type) = value_type.is_struct() {
1530+
new_val.access_field(None, struct_type.get_field(idx as i32))
15551531
} else {
15561532
panic!("Unexpected type {:?}", value_type);
15571533
};
@@ -1568,7 +1544,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15681544

15691545
self.llbb().add_assignment(self.location, lvalue, value);
15701546

1571-
aggregate_value
1547+
new_val.to_rvalue()
15721548
}
15731549

15741550
fn set_personality_fn(&mut self, _personality: Function<'gcc>) {

‎compiler/rustc_codegen_gcc/src/common.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
117117

118118
fn const_undef(&self, typ: Type<'gcc>) -> RValue<'gcc> {
119119
let local = self.current_func.borrow().expect("func").new_local(None, typ, "undefined");
120-
if typ.is_struct().is_some() {
121-
// NOTE: hack to workaround a limitation of the rustc API: see comment on
122-
// CodegenCx.structs_as_pointer
123-
let pointer = local.get_address(None);
124-
self.structs_as_pointer.borrow_mut().insert(pointer);
125-
pointer
126-
} else {
127-
local.to_rvalue()
128-
}
120+
local.to_rvalue()
129121
}
130122

131123
fn const_poison(&self, typ: Type<'gcc>) -> RValue<'gcc> {

‎compiler/rustc_codegen_gcc/src/context.rs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,6 @@ pub struct CodegenCx<'gcc, 'tcx> {
124124

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

127-
/// NOTE: a hack is used because the rustc API is not suitable to libgccjit and as such,
128-
/// `const_undef()` returns struct as pointer so that they can later be assigned a value (in
129-
/// e.g. Builder::insert_value).
130-
/// As such, this set remembers which of these pointers were returned by this function so that
131-
/// they can be dereferenced later.
132-
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
133-
pub structs_as_pointer: RefCell<FxHashSet<RValue<'gcc>>>,
134-
135127
#[cfg(feature = "master")]
136128
pub cleanup_blocks: RefCell<FxHashSet<Block<'gcc>>>,
137129
/// The alignment of a u128/i128 type.
@@ -304,7 +296,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
304296
#[cfg(feature = "master")]
305297
rust_try_fn: Cell::new(None),
306298
pointee_infos: Default::default(),
307-
structs_as_pointer: Default::default(),
308299
#[cfg(feature = "master")]
309300
cleanup_blocks: Default::default(),
310301
};

0 commit comments

Comments
(0)

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