Skip to content

Commit 1920fb1

Browse files
authored
Merge pull request #851 from rust-lang/sync_from_rust_2026_02_12
Sync from rust 2026/02/12
2 parents 740a55f + c5cb569 commit 1920fb1

File tree

14 files changed

+72
-70
lines changed

14 files changed

+72
-70
lines changed

.github/workflows/m68k.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: |
8484
./y.sh prepare --only-libcore --cross
8585
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
86-
CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
86+
CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build -Zjson-target-spec --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
8787
./y.sh clean all
8888
8989
- name: Build

build_system/src/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
141141
}
142142

143143
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
144+
if config.target.ends_with(".json") {
145+
args.push(&"-Zjson-target-spec");
146+
}
147+
144148
for feature in &config.features {
145149
args.push(&"--features");
146150
args.push(feature);

messages.ftl

Lines changed: 0 additions & 8 deletions
This file was deleted.

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-2026-01-30"
2+
channel = "nightly-2026-02-13"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/back/lto.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct LtoData {
5050
}
5151

5252
fn prepare_lto(
53-
cgcx: &CodegenContext<GccCodegenBackend>,
53+
cgcx: &CodegenContext,
5454
each_linked_rlib_for_lto: &[PathBuf],
5555
dcx: DiagCtxtHandle<'_>,
5656
) -> LtoData {
@@ -111,7 +111,7 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
111111
/// Performs fat LTO by merging all modules into a single one and returning it
112112
/// for further optimization.
113113
pub(crate) fn run_fat(
114-
cgcx: &CodegenContext<GccCodegenBackend>,
114+
cgcx: &CodegenContext,
115115
shared_emitter: &SharedEmitter,
116116
each_linked_rlib_for_lto: &[PathBuf],
117117
modules: Vec<FatLtoInput<GccCodegenBackend>>,
@@ -132,7 +132,7 @@ pub(crate) fn run_fat(
132132
}
133133

134134
fn fat_lto(
135-
cgcx: &CodegenContext<GccCodegenBackend>,
135+
cgcx: &CodegenContext,
136136
_dcx: DiagCtxtHandle<'_>,
137137
modules: Vec<FatLtoInput<GccCodegenBackend>>,
138138
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
@@ -283,7 +283,7 @@ impl ModuleBufferMethods for ModuleBuffer {
283283
/// lists, one of the modules that need optimization and another for modules that
284284
/// can simply be copied over from the incr. comp. cache.
285285
pub(crate) fn run_thin(
286-
cgcx: &CodegenContext<GccCodegenBackend>,
286+
cgcx: &CodegenContext,
287287
dcx: DiagCtxtHandle<'_>,
288288
each_linked_rlib_for_lto: &[PathBuf],
289289
modules: Vec<(String, ThinBuffer)>,
@@ -345,7 +345,7 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<GccContext>) -> (String, ThinBu
345345
/// all of the `LtoModuleCodegen` units returned below and destroyed once
346346
/// they all go out of scope.
347347
fn thin_lto(
348-
cgcx: &CodegenContext<GccCodegenBackend>,
348+
cgcx: &CodegenContext,
349349
_dcx: DiagCtxtHandle<'_>,
350350
modules: Vec<(String, ThinBuffer)>,
351351
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
@@ -520,11 +520,9 @@ fn thin_lto(
520520

521521
pub fn optimize_thin_module(
522522
thin_module: ThinModule<GccCodegenBackend>,
523-
_cgcx: &CodegenContext<GccCodegenBackend>,
523+
_cgcx: &CodegenContext,
524524
) -> ModuleCodegen<GccContext> {
525525
//let module_name = &thin_module.shared.module_names[thin_module.idx];
526-
/*let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
527-
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&dcx, e))?;*/
528526

529527
// Right now the implementation we've got only works over serialized
530528
// modules, so we create a fresh new LLVM context and parse the module

src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use rustc_target::spec::SplitDebuginfo;
1414

1515
use crate::base::add_pic_option;
1616
use crate::errors::CopyBitcode;
17-
use crate::{GccCodegenBackend, GccContext, LtoMode};
17+
use crate::{GccContext, LtoMode};
1818

1919
pub(crate) fn codegen(
20-
cgcx: &CodegenContext<GccCodegenBackend>,
20+
cgcx: &CodegenContext,
2121
shared_emitter: &SharedEmitter,
2222
module: ModuleCodegen<GccContext>,
2323
config: &ModuleConfig,
@@ -227,7 +227,7 @@ pub(crate) fn codegen(
227227
}
228228

229229
pub(crate) fn save_temp_bitcode(
230-
cgcx: &CodegenContext<GccCodegenBackend>,
230+
cgcx: &CodegenContext,
231231
_module: &ModuleCodegen<GccContext>,
232232
_name: &str,
233233
) {

src/builder.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,32 +1873,31 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
18731873
// On the other hand, f_max works even if int_ty::MAX is greater than float_ty::MAX. Because
18741874
// we're rounding towards zero, we just get float_ty::MAX (which is always an integer).
18751875
// This already happens today with u128::MAX = 2^128 - 1 > f32::MAX.
1876-
let int_max = |signed: bool, int_width: u64| -> u128 {
1876+
fn int_max(signed: bool, int_width: u64) -> u128 {
18771877
let shift_amount = 128 - int_width;
18781878
if signed { i128::MAX as u128 >> shift_amount } else { u128::MAX >> shift_amount }
1879-
};
1880-
let int_min = |signed: bool, int_width: u64| -> i128 {
1879+
}
1880+
fn int_min(signed: bool, int_width: u64) -> i128 {
18811881
if signed { i128::MIN >> (128 - int_width) } else { 0 }
1882-
};
1882+
}
18831883

1884-
let compute_clamp_bounds_single = |signed: bool, int_width: u64| -> (u128, u128) {
1884+
// TODO: rewrite using a generic function with <F: Float>.
1885+
let compute_clamp_bounds_half = |signed: bool, int_width: u64| -> (u128, u128) {
18851886
let rounded_min =
1886-
ieee::Single::from_i128_r(int_min(signed, int_width), Round::TowardZero);
1887-
assert_eq!(rounded_min.status, Status::OK);
1887+
ieee::Half::from_i128_r(int_min(signed, int_width), Round::TowardZero);
1888+
//assert_eq!(rounded_min.status, Status::OK);
18881889
let rounded_max =
1889-
ieee::Single::from_u128_r(int_max(signed, int_width), Round::TowardZero);
1890+
ieee::Half::from_u128_r(int_max(signed, int_width), Round::TowardZero);
18901891
assert!(rounded_max.value.is_finite());
18911892
(rounded_min.value.to_bits(), rounded_max.value.to_bits())
18921893
};
1893-
let compute_clamp_bounds_double = |signed: bool, int_width: u64| -> (u128, u128) {
1894-
let rounded_min =
1895-
ieee::Double::from_i128_r(int_min(signed, int_width), Round::TowardZero);
1894+
fn compute_clamp_bounds<F: Float>(signed: bool, int_width: u64) -> (u128, u128) {
1895+
let rounded_min = F::from_i128_r(int_min(signed, int_width), Round::TowardZero);
18961896
assert_eq!(rounded_min.status, Status::OK);
1897-
let rounded_max =
1898-
ieee::Double::from_u128_r(int_max(signed, int_width), Round::TowardZero);
1897+
let rounded_max = F::from_u128_r(int_max(signed, int_width), Round::TowardZero);
18991898
assert!(rounded_max.value.is_finite());
19001899
(rounded_min.value.to_bits(), rounded_max.value.to_bits())
1901-
};
1900+
}
19021901
// To implement saturation, we perform the following steps:
19031902
//
19041903
// 1. Cast val to an integer with fpto[su]i. This may result in undef.
@@ -1928,15 +1927,19 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19281927

19291928
let float_bits_to_llval = |bx: &mut Self, bits| {
19301929
let bits_llval = match float_width {
1930+
16 => bx.cx().const_u16(bits as u16),
19311931
32 => bx.cx().const_u32(bits as u32),
19321932
64 => bx.cx().const_u64(bits as u64),
1933+
128 => bx.cx().const_u128(bits),
19331934
n => bug!("unsupported float width {}", n),
19341935
};
19351936
bx.bitcast(bits_llval, float_ty)
19361937
};
19371938
let (f_min, f_max) = match float_width {
1938-
32 => compute_clamp_bounds_single(signed, int_width),
1939-
64 => compute_clamp_bounds_double(signed, int_width),
1939+
16 => compute_clamp_bounds_half(signed, int_width),
1940+
32 => compute_clamp_bounds::<ieee::Single>(signed, int_width),
1941+
64 => compute_clamp_bounds::<ieee::Double>(signed, int_width),
1942+
128 => compute_clamp_bounds::<ieee::Quad>(signed, int_width),
19401943
n => bug!("unsupported float width {}", n),
19411944
};
19421945
let f_min = float_bits_to_llval(self, f_min);

src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2020
bytes_in_context(self, bytes)
2121
}
2222

23+
pub fn const_u16(&self, i: u16) -> RValue<'gcc> {
24+
self.const_uint(self.type_u16(), i as u64)
25+
}
26+
2327
fn global_string(&self, string: &str) -> LValue<'gcc> {
2428
// TODO(antoyo): handle non-null-terminated strings.
2529
let string = self.context.new_string_literal(string);

src/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ use rustc_macros::Diagnostic;
22
use rustc_span::Span;
33

44
#[derive(Diagnostic)]
5-
#[diag(codegen_gcc_unwinding_inline_asm)]
5+
#[diag("GCC backend does not support unwinding from inline asm")]
66
pub(crate) struct UnwindingInlineAsm {
77
#[primary_span]
88
pub span: Span,
99
}
1010

1111
#[derive(Diagnostic)]
12-
#[diag(codegen_gcc_copy_bitcode)]
12+
#[diag("failed to copy bitcode to object file: {$err}")]
1313
pub(crate) struct CopyBitcode {
1414
pub err: std::io::Error,
1515
}
1616

1717
#[derive(Diagnostic)]
18-
#[diag(codegen_gcc_lto_bitcode_from_rlib)]
18+
#[diag("failed to get bitcode from object file for LTO ({$gcc_err})")]
1919
pub(crate) struct LtoBitcodeFromRlib {
2020
pub gcc_err: String,
2121
}
2222

2323
#[derive(Diagnostic)]
24-
#[diag(codegen_gcc_explicit_tail_calls_unsupported)]
24+
#[diag("explicit tail calls with the 'become' keyword are not implemented in the GCC backend")]
2525
pub(crate) struct ExplicitTailCallsUnsupported;

src/int.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
942942
fn float_to_int_cast(
943943
&self,
944944
signed: bool,
945-
value: RValue<'gcc>,
945+
mut value: RValue<'gcc>,
946946
dest_typ: Type<'gcc>,
947947
) -> RValue<'gcc> {
948948
let value_type = value.get_type();
@@ -951,16 +951,22 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
951951
}
952952

953953
debug_assert!(dest_typ.dyncast_array().is_some());
954+
let (dest_type, param_type) = match self.type_kind(value_type) {
955+
TypeKind::Half => (Some(self.float_type), self.float_type),
956+
_ => (None, value_type),
957+
};
954958
let name_suffix = match self.type_kind(value_type) {
955959
// cSpell:disable
956-
TypeKind::Float => "sfti",
960+
// Since we will cast Half to a float, we use sfti for both.
961+
TypeKind::Half | TypeKind::Float => "sfti",
957962
TypeKind::Double => "dfti",
963+
TypeKind::FP128 => "tfti",
958964
// cSpell:enable
959965
kind => panic!("cannot cast a {:?} to non-native integer", kind),
960966
};
961967
let sign = if signed { "" } else { "uns" };
962968
let func_name = format!("__fix{}{}", sign, name_suffix);
963-
let param = self.context.new_parameter(None, value_type, "n");
969+
let param = self.context.new_parameter(None, param_type, "n");
964970
let func = self.context.new_function(
965971
None,
966972
FunctionType::Extern,
@@ -969,6 +975,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
969975
func_name,
970976
false,
971977
);
978+
if let Some(dest_type) = dest_type {
979+
value = self.context.new_cast(None, value, dest_type);
980+
}
972981
self.context.new_call(None, func, &[value])
973982
}
974983

0 commit comments

Comments
 (0)