Skip to content

Commit 8efeb49

Browse files
authored
Merge pull request #682 from rust-lang/sync_from_rust_2025_05_21
Sync from rust 2025/05/21
2 parents 706905b + ba53d97 commit 8efeb49

File tree

11 files changed

+230
-31
lines changed

11 files changed

+230
-31
lines changed

build_system/src/test.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,15 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
710710
println!("[TEST] libcore");
711711
let path = get_sysroot_dir().join("sysroot_src/library/coretests");
712712
let _ = remove_dir_all(path.join("target"));
713-
run_cargo_command(&[&"test"], Some(&path), env, args)?;
713+
// TODO(antoyo): run in release mode when we fix the failures.
714+
// TODO(antoyo): remove the --skip f16::test_total_cmp when this issue is fixed:
715+
// https://github.com/rust-lang/rust/issues/141503
716+
run_cargo_command(
717+
&[&"test", &"--", &"--skip", &"f16::test_total_cmp"],
718+
Some(&path),
719+
env,
720+
args,
721+
)?;
714722
Ok(())
715723
}
716724

libgccjit.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8b194529188f9d3a98cc211caa805a5355bfa8f0
1+
04ce66d8c918de9273bd7101638ad8724edf5e21
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From cdb3d407740e4f15c3746051f8ba89b8e74e99d3 Mon Sep 17 00:00:00 2001
2+
From: None <[email protected]>
3+
Date: Fri, 30 May 2025 13:46:22 -0400
4+
Subject: [PATCH] Pin compiler_builtins to 0.1.160
5+
6+
---
7+
library/alloc/Cargo.toml | 2 +-
8+
library/std/Cargo.toml | 2 +-
9+
2 files changed, 2 insertions(+), 2 deletions(-)
10+
11+
diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml
12+
index 9d0d957..365c9dc 100644
13+
--- a/library/alloc/Cargo.toml
14+
+++ b/library/alloc/Cargo.toml
15+
@@ -16,7 +16,7 @@ bench = false
16+
17+
[dependencies]
18+
core = { path = "../core", public = true }
19+
-compiler_builtins = { version = "=0.1.159", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.160", features = ['rustc-dep-of-std'] }
21+
22+
[features]
23+
compiler-builtins-mem = ['compiler_builtins/mem']
24+
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
25+
index 4ff4895..31371f0 100644
26+
--- a/library/std/Cargo.toml
27+
+++ b/library/std/Cargo.toml
28+
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
29+
panic_unwind = { path = "../panic_unwind", optional = true }
30+
panic_abort = { path = "../panic_abort" }
31+
core = { path = "../core", public = true }
32+
-compiler_builtins = { version = "=0.1.159" }
33+
+compiler_builtins = { version = "=0.1.160" }
34+
unwind = { path = "../unwind" }
35+
hashbrown = { version = "0.15", default-features = false, features = [
36+
'rustc-dep-of-std',
37+
--
38+
2.49.0
39+

rust-toolchain

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

src/attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use gccjit::FnAttribute;
33
use gccjit::Function;
44
#[cfg(feature = "master")]
5-
use rustc_attr_parsing::InlineAttr;
6-
use rustc_attr_parsing::InstructionSetAttr;
5+
use rustc_attr_data_structures::InlineAttr;
6+
use rustc_attr_data_structures::InstructionSetAttr;
77
#[cfg(feature = "master")]
88
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
99
#[cfg(feature = "master")]

src/builder.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::convert::TryFrom;
44
use std::ops::Deref;
55

66
use gccjit::{
7-
BinaryOp, Block, ComparisonOp, Context, Function, LValue, Location, RValue, ToRValue, Type,
8-
UnaryOp,
7+
BinaryOp, Block, ComparisonOp, Context, Function, FunctionType, LValue, Location, RValue,
8+
ToRValue, Type, UnaryOp,
99
};
1010
use rustc_abi as abi;
1111
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
@@ -765,7 +765,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
765765

766766
#[cfg(feature = "master")]
767767
match self.cx.type_kind(a_type) {
768-
TypeKind::Half | TypeKind::Float => {
768+
TypeKind::Half => {
769+
let fmodf = self.context.get_builtin_function("fmodf");
770+
let f32_type = self.type_f32();
771+
let a = self.context.new_cast(self.location, a, f32_type);
772+
let b = self.context.new_cast(self.location, b, f32_type);
773+
let result = self.context.new_call(self.location, fmodf, &[a, b]);
774+
return self.context.new_cast(self.location, result, a_type);
775+
}
776+
TypeKind::Float => {
769777
let fmodf = self.context.get_builtin_function("fmodf");
770778
return self.context.new_call(self.location, fmodf, &[a, b]);
771779
}
@@ -774,8 +782,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
774782
return self.context.new_call(self.location, fmod, &[a, b]);
775783
}
776784
TypeKind::FP128 => {
777-
let fmodl = self.context.get_builtin_function("fmodl");
778-
return self.context.new_call(self.location, fmodl, &[a, b]);
785+
let f128_type = self.type_f128();
786+
let fmodf128 = self.context.new_function(
787+
None,
788+
FunctionType::Extern,
789+
f128_type,
790+
&[
791+
self.context.new_parameter(None, f128_type, "a"),
792+
self.context.new_parameter(None, f128_type, "b"),
793+
],
794+
"fmodf128",
795+
false,
796+
);
797+
return self.context.new_call(self.location, fmodf128, &[a, b]);
779798
}
780799
_ => (),
781800
}

src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
106106
// This is a monomorphization of a generic function.
107107
if !(cx.tcx.sess.opts.share_generics()
108108
|| tcx.codegen_fn_attrs(instance_def_id).inline
109-
== rustc_attr_parsing::InlineAttr::Never)
109+
== rustc_attr_data_structures::InlineAttr::Never)
110110
{
111111
// When not sharing generics, all instances are in the same
112112
// crate and have hidden visibility.

src/common.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,15 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
237237

238238
// FIXME(antoyo): there's some issues with using the u128 code that follows, so hard-code
239239
// the paths for floating-point values.
240-
if ty == self.float_type {
240+
// TODO: Remove this code?
241+
/*if ty == self.float_type {
241242
return self
242243
.context
243244
.new_rvalue_from_double(ty, f32::from_bits(data as u32) as f64);
244245
}
245246
if ty == self.double_type {
246247
return self.context.new_rvalue_from_double(ty, f64::from_bits(data as u64));
247-
}
248+
}*/
248249

249250
let value = self.const_uint_big(self.type_ix(bitsize), data);
250251
let bytesize = layout.size(self).bytes();

src/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
915915
let name_suffix = match self.type_kind(dest_typ) {
916916
TypeKind::Float => "tisf",
917917
TypeKind::Double => "tidf",
918-
TypeKind::FP128 => "tixf",
918+
TypeKind::FP128 => "titf",
919919
kind => panic!("cannot cast a non-native integer to type {:?}", kind),
920920
};
921921
let sign = if signed { "" } else { "un" };

src/intrinsic/mod.rs

Lines changed: 141 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,95 @@ fn get_simple_function<'gcc, 'tcx>(
160160
))
161161
}
162162

163+
fn get_simple_function_f128<'gcc, 'tcx>(
164+
cx: &CodegenCx<'gcc, 'tcx>,
165+
name: Symbol,
166+
) -> Option<Function<'gcc>> {
167+
if !cx.supports_f128_type {
168+
return None;
169+
}
170+
171+
let f128_type = cx.type_f128();
172+
let func_name = match name {
173+
sym::ceilf128 => "ceilf128",
174+
sym::floorf128 => "floorf128",
175+
sym::truncf128 => "truncf128",
176+
sym::roundf128 => "roundf128",
177+
sym::round_ties_even_f128 => "roundevenf128",
178+
sym::sqrtf128 => "sqrtf128",
179+
_ => return None,
180+
};
181+
Some(cx.context.new_function(
182+
None,
183+
FunctionType::Extern,
184+
f128_type,
185+
&[cx.context.new_parameter(None, f128_type, "a")],
186+
func_name,
187+
false,
188+
))
189+
}
190+
191+
fn get_simple_function_f128_2args<'gcc, 'tcx>(
192+
cx: &CodegenCx<'gcc, 'tcx>,
193+
name: Symbol,
194+
) -> Option<Function<'gcc>> {
195+
if !cx.supports_f128_type {
196+
return None;
197+
}
198+
199+
let f128_type = cx.type_f128();
200+
let func_name = match name {
201+
sym::maxnumf128 => "fmaxf128",
202+
sym::minnumf128 => "fminf128",
203+
_ => return None,
204+
};
205+
Some(cx.context.new_function(
206+
None,
207+
FunctionType::Extern,
208+
f128_type,
209+
&[
210+
cx.context.new_parameter(None, f128_type, "a"),
211+
cx.context.new_parameter(None, f128_type, "b"),
212+
],
213+
func_name,
214+
false,
215+
))
216+
}
217+
218+
fn f16_builtin<'gcc, 'tcx>(
219+
cx: &CodegenCx<'gcc, 'tcx>,
220+
name: Symbol,
221+
args: &[OperandRef<'tcx, RValue<'gcc>>],
222+
) -> RValue<'gcc> {
223+
let f32_type = cx.type_f32();
224+
let builtin_name = match name {
225+
sym::ceilf16 => "__builtin_ceilf",
226+
sym::floorf16 => "__builtin_floorf",
227+
sym::fmaf16 => "fmaf",
228+
sym::maxnumf16 => "__builtin_fmaxf",
229+
sym::minnumf16 => "__builtin_fminf",
230+
sym::powf16 => "__builtin_powf",
231+
sym::powif16 => {
232+
let func = cx.context.get_builtin_function("__builtin_powif");
233+
let arg0 = cx.context.new_cast(None, args[0].immediate(), f32_type);
234+
let args = [arg0, args[1].immediate()];
235+
let result = cx.context.new_call(None, func, &args);
236+
return cx.context.new_cast(None, result, cx.type_f16());
237+
}
238+
sym::roundf16 => "__builtin_roundf",
239+
sym::round_ties_even_f16 => "__builtin_rintf",
240+
sym::sqrtf16 => "__builtin_sqrtf",
241+
sym::truncf16 => "__builtin_truncf",
242+
_ => unreachable!(),
243+
};
244+
245+
let func = cx.context.get_builtin_function(builtin_name);
246+
let args: Vec<_> =
247+
args.iter().map(|arg| cx.context.new_cast(None, arg.immediate(), f32_type)).collect();
248+
let result = cx.context.new_call(None, func, &args);
249+
cx.context.new_cast(None, result, cx.type_f16())
250+
}
251+
163252
impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
164253
fn codegen_intrinsic_call(
165254
&mut self,
@@ -188,7 +277,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
188277
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
189278

190279
let simple = get_simple_intrinsic(self, name);
191-
let simple_func = get_simple_function(self, name);
280+
let simple_func = get_simple_function(self, name)
281+
.or_else(|| get_simple_function_f128(self, name))
282+
.or_else(|| get_simple_function_f128_2args(self, name));
192283

193284
// FIXME(tempdragon): Re-enable `clippy::suspicious_else_formatting` if the following issue is solved:
194285
// https://github.com/rust-lang/rust-clippy/issues/12497
@@ -211,17 +302,55 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
211302
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
212303
)
213304
}
214-
sym::fmaf16 => {
215-
// TODO(antoyo): use the correct builtin for f16.
216-
let func = self.cx.context.get_builtin_function("fmaf");
217-
let args: Vec<_> = args
218-
.iter()
219-
.map(|arg| {
220-
self.cx.context.new_cast(self.location, arg.immediate(), self.cx.type_f32())
221-
})
222-
.collect();
223-
let result = self.cx.context.new_call(self.location, func, &args);
224-
self.cx.context.new_cast(self.location, result, self.cx.type_f16())
305+
sym::ceilf16
306+
| sym::floorf16
307+
| sym::fmaf16
308+
| sym::maxnumf16
309+
| sym::minnumf16
310+
| sym::powf16
311+
| sym::powif16
312+
| sym::roundf16
313+
| sym::round_ties_even_f16
314+
| sym::sqrtf16
315+
| sym::truncf16 => f16_builtin(self, name, args),
316+
sym::fmaf128 => {
317+
let f128_type = self.cx.type_f128();
318+
let func = self.cx.context.new_function(
319+
None,
320+
FunctionType::Extern,
321+
f128_type,
322+
&[
323+
self.cx.context.new_parameter(None, f128_type, "a"),
324+
self.cx.context.new_parameter(None, f128_type, "b"),
325+
self.cx.context.new_parameter(None, f128_type, "c"),
326+
],
327+
"fmaf128",
328+
false,
329+
);
330+
self.cx.context.new_call(
331+
self.location,
332+
func,
333+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
334+
)
335+
}
336+
sym::powif128 => {
337+
let f128_type = self.cx.type_f128();
338+
let func = self.cx.context.new_function(
339+
None,
340+
FunctionType::Extern,
341+
f128_type,
342+
&[
343+
self.cx.context.new_parameter(None, f128_type, "a"),
344+
self.cx.context.new_parameter(None, self.int_type, "b"),
345+
],
346+
"__powitf2",
347+
false,
348+
);
349+
self.cx.context.new_call(
350+
self.location,
351+
func,
352+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
353+
)
225354
}
226355
sym::is_val_statically_known => {
227356
let a = args[0].immediate();

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern crate tracing;
3737
extern crate rustc_abi;
3838
extern crate rustc_apfloat;
3939
extern crate rustc_ast;
40-
extern crate rustc_attr_parsing;
40+
extern crate rustc_attr_data_structures;
4141
extern crate rustc_codegen_ssa;
4242
extern crate rustc_data_structures;
4343
extern crate rustc_errors;
@@ -521,13 +521,16 @@ fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig
521521
let target_features = f(false);
522522
let unstable_target_features = f(true);
523523

524+
let has_reliable_f16 = target_info.supports_target_dependent_type(CType::Float16);
525+
let has_reliable_f128 = target_info.supports_target_dependent_type(CType::Float128);
526+
524527
TargetConfig {
525528
target_features,
526529
unstable_target_features,
527530
// There are no known bugs with GCC support for f16 or f128
528-
has_reliable_f16: true,
529-
has_reliable_f16_math: true,
530-
has_reliable_f128: true,
531-
has_reliable_f128_math: true,
531+
has_reliable_f16,
532+
has_reliable_f16_math: has_reliable_f16,
533+
has_reliable_f128,
534+
has_reliable_f128_math: has_reliable_f128,
532535
}
533536
}

0 commit comments

Comments
 (0)