Skip to content

Commit 2776bdf

Browse files
committed
Auto merge of #135525 - jhpratt:rollup-4gu2wpm, r=jhpratt
Rollup of 7 pull requests Successful merges: - #132397 (Make missing_abi lint warn-by-default.) - #133807 (ci: Enable opt-dist for dist-aarch64-linux builds) - #134143 (Convert `struct FromBytesWithNulError` into enum) - #134338 (Use a C-safe return type for `__rust_[ui]128_*` overflowing intrinsics) - #134678 (Update `ReadDir::next` in `std::sys::pal::unix::fs` to use `&raw const (*p).field` instead of `p.byte_offset().cast()`) - #135424 (Detect unstable lint docs that dont enable their feature) - #135520 (Make sure we actually use the right trivial lifetime substs when eagerly monomorphizing drop for ADTs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00ded39 + 8e91327 commit 2776bdf

File tree

81 files changed

+431
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+431
-317
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core" }
19-
-compiler_builtins = { version = "=0.1.141", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.141", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_codegen_cranelift/src/codegen_i128.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,22 @@ pub(crate) fn maybe_codegen_mul_checked<'tcx>(
7676
}
7777

7878
let is_signed = type_sign(lhs.layout().ty);
79-
80-
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
81-
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
79+
let oflow_out_place = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
8280
let param_types = vec![
83-
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
8481
AbiParam::new(types::I128),
8582
AbiParam::new(types::I128),
83+
AbiParam::special(fx.pointer_type, ArgumentPurpose::Normal),
8684
];
87-
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
88-
fx.lib_call(
85+
let args = [lhs.load_scalar(fx), rhs.load_scalar(fx), oflow_out_place.to_ptr().get_addr(fx)];
86+
let ret = fx.lib_call(
8987
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
9088
param_types,
91-
vec![],
89+
vec![AbiParam::new(types::I128)],
9290
&args,
9391
);
94-
Some(out_place.to_cvalue(fx))
92+
let mul = ret[0];
93+
let oflow = oflow_out_place.to_cvalue(fx).load_scalar(fx);
94+
let oflow = clif_intcast(fx, oflow, types::I8, false);
95+
let layout = fx.layout_of(Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]));
96+
Some(CValue::by_val_pair(mul, oflow, layout))
9597
}

compiler/rustc_codegen_cranelift/src/compiler_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ builtin_functions! {
4343
fn __divti3(n: i128, d: i128) -> i128;
4444
fn __umodti3(n: u128, d: u128) -> u128;
4545
fn __modti3(n: i128, d: i128) -> i128;
46-
fn __rust_u128_mulo(a: u128, b: u128) -> (u128, bool);
46+
fn __rust_u128_mulo(a: u128, b: u128, oflow: &mut i32) -> u128;
4747

4848
// floats
4949
fn __floattisf(i: i128) -> f32;

compiler/rustc_codegen_gcc/example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<T> Index<usize> for [T] {
689689
}
690690
}
691691

692-
extern {
692+
extern "C" {
693693
type VaListImpl;
694694
}
695695

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ fn main() {
258258

259259
assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
260260

261-
extern {
261+
extern "C" {
262262
#[linkage = "weak"]
263263
static ABC: *const u8;
264264
}
265265

266266
{
267-
extern {
267+
extern "C" {
268268
#[linkage = "weak"]
269269
static ABC: *const u8;
270270
}

compiler/rustc_codegen_gcc/example/mod_bench.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(internal_features)]
44

55
#[link(name = "c")]
6-
extern {}
6+
extern "C" {}
77

88
#[panic_handler]
99
fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {

compiler/rustc_codegen_gcc/example/std_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::arch::x86_64::*;
77
use std::io::Write;
88
use std::ops::Coroutine;
99

10-
extern {
10+
extern "C" {
1111
pub fn printf(format: *const i8, ...) -> i32;
1212
}
1313

compiler/rustc_codegen_gcc/src/int.rs

+60-63
Original file line numberDiff line numberDiff line change
@@ -322,36 +322,26 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
322322
},
323323
}
324324
} else {
325-
match new_kind {
326-
Int(I128) | Uint(U128) => {
327-
let func_name = match oop {
328-
OverflowOp::Add => match new_kind {
329-
Int(I128) => "__rust_i128_addo",
330-
Uint(U128) => "__rust_u128_addo",
331-
_ => unreachable!(),
332-
},
333-
OverflowOp::Sub => match new_kind {
334-
Int(I128) => "__rust_i128_subo",
335-
Uint(U128) => "__rust_u128_subo",
336-
_ => unreachable!(),
337-
},
338-
OverflowOp::Mul => match new_kind {
339-
Int(I128) => "__rust_i128_mulo", // TODO(antoyo): use __muloti4d instead?
340-
Uint(U128) => "__rust_u128_mulo",
341-
_ => unreachable!(),
342-
},
343-
};
344-
return self.operation_with_overflow(func_name, lhs, rhs);
345-
}
346-
_ => match oop {
347-
OverflowOp::Mul => match new_kind {
348-
Int(I32) => "__mulosi4",
349-
Int(I64) => "__mulodi4",
350-
_ => unreachable!(),
351-
},
352-
_ => unimplemented!("overflow operation for {:?}", new_kind),
325+
let (func_name, width) = match oop {
326+
OverflowOp::Add => match new_kind {
327+
Int(I128) => ("__rust_i128_addo", 128),
328+
Uint(U128) => ("__rust_u128_addo", 128),
329+
_ => unreachable!(),
353330
},
354-
}
331+
OverflowOp::Sub => match new_kind {
332+
Int(I128) => ("__rust_i128_subo", 128),
333+
Uint(U128) => ("__rust_u128_subo", 128),
334+
_ => unreachable!(),
335+
},
336+
OverflowOp::Mul => match new_kind {
337+
Int(I32) => ("__mulosi4", 32),
338+
Int(I64) => ("__mulodi4", 64),
339+
Int(I128) => ("__rust_i128_mulo", 128), // TODO(antoyo): use __muloti4d instead?
340+
Uint(U128) => ("__rust_u128_mulo", 128),
341+
_ => unreachable!(),
342+
},
343+
};
344+
return self.operation_with_overflow(func_name, lhs, rhs, width);
355345
};
356346

357347
let intrinsic = self.context.get_builtin_function(name);
@@ -364,80 +354,87 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
364354
(res.dereference(self.location).to_rvalue(), overflow)
365355
}
366356

357+
/// Non-`__builtin_*` overflow operations with a `fn(T, T, &mut i32) -> T` signature.
367358
pub fn operation_with_overflow(
368359
&self,
369360
func_name: &str,
370361
lhs: RValue<'gcc>,
371362
rhs: RValue<'gcc>,
363+
width: u64,
372364
) -> (RValue<'gcc>, RValue<'gcc>) {
373365
let a_type = lhs.get_type();
374366
let b_type = rhs.get_type();
375367
debug_assert!(a_type.dyncast_array().is_some());
376368
debug_assert!(b_type.dyncast_array().is_some());
369+
let overflow_type = self.i32_type;
370+
let overflow_param_type = overflow_type.make_pointer();
371+
let res_type = a_type;
372+
373+
let overflow_value =
374+
self.current_func().new_local(self.location, overflow_type, "overflow");
375+
let overflow_addr = overflow_value.get_address(self.location);
376+
377377
let param_a = self.context.new_parameter(self.location, a_type, "a");
378378
let param_b = self.context.new_parameter(self.location, b_type, "b");
379-
let result_field = self.context.new_field(self.location, a_type, "result");
380-
let overflow_field = self.context.new_field(self.location, self.bool_type, "overflow");
381-
382-
let ret_ty = Ty::new_tup(self.tcx, &[self.tcx.types.i128, self.tcx.types.bool]);
379+
let param_overflow =
380+
self.context.new_parameter(self.location, overflow_param_type, "overflow");
381+
382+
let a_elem_type = a_type.dyncast_array().expect("non-array a value");
383+
debug_assert!(a_elem_type.is_integral());
384+
let res_ty = match width {
385+
32 => self.tcx.types.i32,
386+
64 => self.tcx.types.i64,
387+
128 => self.tcx.types.i128,
388+
_ => unreachable!("unexpected integer size"),
389+
};
383390
let layout = self
384391
.tcx
385-
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ret_ty))
392+
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(res_ty))
386393
.unwrap();
387394

388395
let arg_abi = ArgAbi { layout, mode: PassMode::Direct(ArgAttributes::new()) };
389396
let mut fn_abi = FnAbi {
390-
args: vec![arg_abi.clone(), arg_abi.clone()].into_boxed_slice(),
397+
args: vec![arg_abi.clone(), arg_abi.clone(), arg_abi.clone()].into_boxed_slice(),
391398
ret: arg_abi,
392399
c_variadic: false,
393-
fixed_count: 2,
400+
fixed_count: 3,
394401
conv: Conv::C,
395402
can_unwind: false,
396403
};
397404
fn_abi.adjust_for_foreign_abi(self.cx, spec::abi::Abi::C { unwind: false }).unwrap();
398405

399-
let indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
400-
401-
let return_type = self
402-
.context
403-
.new_struct_type(self.location, "result_overflow", &[result_field, overflow_field]);
404-
let result = if indirect {
405-
let return_value =
406-
self.current_func().new_local(self.location, return_type.as_type(), "return_value");
407-
let return_param_type = return_type.as_type().make_pointer();
408-
let return_param =
409-
self.context.new_parameter(self.location, return_param_type, "return_value");
406+
let ret_indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
407+
408+
let result = if ret_indirect {
409+
let res_value = self.current_func().new_local(self.location, res_type, "result_value");
410+
let res_addr = res_value.get_address(self.location);
411+
let res_param_type = res_type.make_pointer();
412+
let param_res = self.context.new_parameter(self.location, res_param_type, "result");
413+
410414
let func = self.context.new_function(
411415
self.location,
412416
FunctionType::Extern,
413417
self.type_void(),
414-
&[return_param, param_a, param_b],
418+
&[param_res, param_a, param_b, param_overflow],
415419
func_name,
416420
false,
417421
);
418-
self.llbb().add_eval(
419-
self.location,
420-
self.context.new_call(self.location, func, &[
421-
return_value.get_address(self.location),
422-
lhs,
423-
rhs,
424-
]),
425-
);
426-
return_value.to_rvalue()
422+
let _void =
423+
self.context.new_call(self.location, func, &[res_addr, lhs, rhs, overflow_addr]);
424+
res_value.to_rvalue()
427425
} else {
428426
let func = self.context.new_function(
429427
self.location,
430428
FunctionType::Extern,
431-
return_type.as_type(),
432-
&[param_a, param_b],
429+
res_type,
430+
&[param_a, param_b, param_overflow],
433431
func_name,
434432
false,
435433
);
436-
self.context.new_call(self.location, func, &[lhs, rhs])
434+
self.context.new_call(self.location, func, &[lhs, rhs, overflow_addr])
437435
};
438-
let overflow = result.access_field(self.location, overflow_field);
439-
let int_result = result.access_field(self.location, result_field);
440-
(int_result, overflow)
436+
437+
(result, self.context.new_cast(self.location, overflow_value, self.bool_type).to_rvalue())
441438
}
442439

443440
pub fn gcc_icmp(

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
10011001
128 => "__rust_i128_addo",
10021002
_ => unreachable!(),
10031003
};
1004-
let (int_result, overflow) = self.operation_with_overflow(func_name, lhs, rhs);
1004+
let (int_result, overflow) =
1005+
self.operation_with_overflow(func_name, lhs, rhs, width);
10051006
self.llbb().add_assignment(self.location, res, int_result);
10061007
overflow
10071008
};
@@ -1071,7 +1072,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
10711072
128 => "__rust_i128_subo",
10721073
_ => unreachable!(),
10731074
};
1074-
let (int_result, overflow) = self.operation_with_overflow(func_name, lhs, rhs);
1075+
let (int_result, overflow) =
1076+
self.operation_with_overflow(func_name, lhs, rhs, width);
10751077
self.llbb().add_assignment(self.location, res, int_result);
10761078
overflow
10771079
};

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3597,7 +3597,7 @@ declare_lint! {
35973597
///
35983598
/// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
35993599
pub MISSING_ABI,
3600-
Allow,
3600+
Warn,
36013601
"No declared ABI for extern declaration"
36023602
}
36033603

compiler/rustc_monomorphize/src/collector.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1410,19 +1410,33 @@ impl<'v> RootCollector<'_, 'v> {
14101410
&& !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
14111411
{
14121412
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
1413+
let id_args =
1414+
ty::GenericArgs::for_item(self.tcx, id.owner_id.to_def_id(), |param, _| {
1415+
match param.kind {
1416+
GenericParamDefKind::Lifetime => {
1417+
self.tcx.lifetimes.re_erased.into()
1418+
}
1419+
GenericParamDefKind::Type { .. }
1420+
| GenericParamDefKind::Const { .. } => {
1421+
unreachable!(
1422+
"`own_requires_monomorphization` check means that \
1423+
we should have no type/const params"
1424+
)
1425+
}
1426+
}
1427+
});
14131428

14141429
// This type is impossible to instantiate, so we should not try to
14151430
// generate a `drop_in_place` instance for it.
14161431
if self.tcx.instantiate_and_check_impossible_predicates((
14171432
id.owner_id.to_def_id(),
1418-
ty::List::empty(),
1433+
id_args,
14191434
)) {
14201435
return;
14211436
}
14221437

1423-
let ty = self.tcx.erase_regions(
1424-
self.tcx.type_of(id.owner_id.to_def_id()).instantiate_identity(),
1425-
);
1438+
let ty =
1439+
self.tcx.type_of(id.owner_id.to_def_id()).instantiate(self.tcx, id_args);
14261440
assert!(!ty.has_non_region_param());
14271441
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
14281442
}

compiler/rustc_type_ir/src/binder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
804804
#[inline(never)]
805805
fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
806806
panic!(
807-
"const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
807+
"region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
808808
ebr,
809809
r,
810810
ebr.index(),

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ dependencies = [
6161

6262
[[package]]
6363
name = "compiler_builtins"
64-
version = "0.1.141"
64+
version = "0.1.143"
6565
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "b5e7a0206befe4e574e37d6d7a0fe82e88fdf54bedb0608f239cb11b7a6aa6be"
66+
checksum = "c85ba2077e3eab3dd81be4ece6b7fb2ad0887c1fb813e9a45400baf75c6c7c29"
6767
dependencies = [
6868
"cc",
6969
"rustc-std-workspace-core",

library/alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "=0.1.141", features = ['rustc-dep-of-std'] }
13+
compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
1414

1515
[dev-dependencies]
1616
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

0 commit comments

Comments
 (0)