Skip to content

Commit f722b24

Browse files
committed
Auto merge of rust-lang#108159 - matthiaskrgr:rollup-5k2j7cx, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#107592 (Default `repr(C)` enums to `c_int` size) - rust-lang#107956 (Copy `bin/*` and `lib/*.dylib` files to `stage0-sysroot`) - rust-lang#108126 (fix a line, and do a consistency fix) - rust-lang#108144 (Add compiler-errors to a few more triagebot groups) - rust-lang#108149 (typo) - rust-lang#108154 (`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes]) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f4f5fc3 + ae5473c commit f722b24

File tree

24 files changed

+167
-42
lines changed

24 files changed

+167
-42
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ pub struct TargetDataLayout {
171171

172172
pub instruction_address_space: AddressSpace,
173173

174-
/// Minimum size of #[repr(C)] enums (default I32 bits)
174+
/// Minimum size of #[repr(C)] enums (default c_int::BITS, usually 32)
175+
/// Note: This isn't in LLVM's data layout string, it is `short_enum`
176+
/// so the only valid spec for LLVM is c_int::BITS or 8
175177
pub c_enum_min_size: Integer,
176178
}
177179

Diff for: compiler/rustc_codegen_llvm/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
521521

522522
// The semantics of #[used] in Rust only require the symbol to make it into the
523523
// object file. It is explicitly allowed for the linker to strip the symbol if it
524-
// is dead, which means we are allowed use `llvm.compiler.used` instead of
524+
// is dead, which means we are allowed to use `llvm.compiler.used` instead of
525525
// `llvm.used` here.
526526
//
527527
// Additionally, https://reviews.llvm.org/D97448 in LLVM 13 started emitting unique
@@ -532,7 +532,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
532532
// That said, we only ever emit these when compiling for ELF targets, unless
533533
// `#[used(compiler)]` is explicitly requested. This is to avoid similar breakage
534534
// on other targets, in particular MachO targets have *their* static constructor
535-
// lists broken if `llvm.compiler.used` is emitted rather than llvm.used. However,
535+
// lists broken if `llvm.compiler.used` is emitted rather than `llvm.used`. However,
536536
// that check happens when assigning the `CodegenFnAttrFlags` in `rustc_hir_analysis`,
537537
// so we don't need to take care of it here.
538538
self.add_compiler_used_global(g);

Diff for: compiler/rustc_codegen_ssa/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
1515
//! The backend-agnostic functions of this crate use functions defined in various traits that
16-
//! have to be implemented by each backends.
16+
//! have to be implemented by each backend.
1717
1818
#[macro_use]
1919
extern crate rustc_macros;

Diff for: compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
898898
assert_eq!(self.new_block(), START_BLOCK);
899899
self.visit_rvalue(
900900
&mut rvalue,
901-
Location { block: BasicBlock::new(0), statement_index: usize::MAX },
901+
Location { block: START_BLOCK, statement_index: usize::MAX },
902902
);
903903

904904
let span = self.promoted.span;

Diff for: compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ bitflags! {
9191
/// the MIR `InstrumentCoverage` pass and not added to the coverage map
9292
/// during codegen.
9393
const NO_COVERAGE = 1 << 15;
94-
/// `#[used(linker)]`: indicates that LLVM nor the linker can eliminate this function.
94+
/// `#[used(linker)]`:
95+
/// indicates that neither LLVM nor the linker will eliminate this function.
9596
const USED_LINKER = 1 << 16;
9697
/// `#[rustc_deallocator]`: a hint to LLVM that the function only deallocates memory.
9798
const DEALLOCATOR = 1 << 17;

Diff for: compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ macro_rules! make_mir_visitor {
323323
self.visit_source_scope($(& $mutability)? *parent_scope);
324324
}
325325
if let Some((callee, callsite_span)) = inlined {
326-
let location = START_BLOCK.start_location();
326+
let location = Location::START;
327327

328328
self.visit_span($(& $mutability)? *callsite_span);
329329

@@ -837,7 +837,7 @@ macro_rules! make_mir_visitor {
837837
} = var_debug_info;
838838

839839
self.visit_source_info(source_info);
840-
let location = START_BLOCK.start_location();
840+
let location = Location::START;
841841
match value {
842842
VarDebugInfoContents::Const(c) => self.visit_constant(c, location),
843843
VarDebugInfoContents::Place(place) =>
@@ -1026,7 +1026,7 @@ macro_rules! super_body {
10261026
$self.visit_span($(& $mutability)? $body.span);
10271027

10281028
for const_ in &$($mutability)? $body.required_consts {
1029-
let location = START_BLOCK.start_location();
1029+
let location = Location::START;
10301030
$self.visit_constant(const_, location);
10311031
}
10321032
}

Diff for: compiler/rustc_mir_transform/src/dest_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ use rustc_index::bit_set::BitSet;
136136
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
137137
use rustc_middle::mir::{dump_mir, PassWhere};
138138
use rustc_middle::mir::{
139-
traversal, BasicBlock, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place,
140-
Rvalue, Statement, StatementKind, TerminatorKind,
139+
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, Rvalue,
140+
Statement, StatementKind, TerminatorKind,
141141
};
142142
use rustc_middle::ty::TyCtxt;
143143
use rustc_mir_dataflow::impls::MaybeLiveLocals;
@@ -468,7 +468,7 @@ impl<'a, 'body, 'alloc, 'tcx> FilterInformation<'a, 'body, 'alloc, 'tcx> {
468468
// to reuse the allocation.
469469
write_info: write_info_alloc,
470470
// Doesn't matter what we put here, will be overwritten before being used
471-
at: Location { block: BasicBlock::from_u32(0), statement_index: 0 },
471+
at: Location::START,
472472
};
473473
this.internal_filter_liveness();
474474
}

Diff for: compiler/rustc_mir_transform/src/generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
487487

488488
let get_context_def_id = tcx.require_lang_item(LangItem::GetContext, None);
489489

490-
for bb in BasicBlock::new(0)..body.basic_blocks.next_index() {
490+
for bb in START_BLOCK..body.basic_blocks.next_index() {
491491
let bb_data = &body[bb];
492492
if bb_data.is_cleanup {
493493
continue;
@@ -1255,7 +1255,7 @@ fn create_generator_resume_function<'tcx>(
12551255
use rustc_middle::mir::AssertKind::{ResumedAfterPanic, ResumedAfterReturn};
12561256

12571257
// Jump to the entry point on the unresumed
1258-
cases.insert(0, (UNRESUMED, BasicBlock::new(0)));
1258+
cases.insert(0, (UNRESUMED, START_BLOCK));
12591259

12601260
// Panic when resumed on the returned or poisoned state
12611261
let generator_kind = body.generator_kind().unwrap();
@@ -1481,7 +1481,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
14811481

14821482
// When first entering the generator, move the resume argument into its new local.
14831483
let source_info = SourceInfo::outermost(body.span);
1484-
let stmts = &mut body.basic_blocks_mut()[BasicBlock::new(0)].statements;
1484+
let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements;
14851485
stmts.insert(
14861486
0,
14871487
Statement {

Diff for: compiler/rustc_mir_transform/src/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
9696
history: Vec::new(),
9797
changed: false,
9898
};
99-
let blocks = BasicBlock::new(0)..body.basic_blocks.next_index();
99+
let blocks = START_BLOCK..body.basic_blocks.next_index();
100100
this.process_blocks(body, blocks);
101101
this.changed
102102
}

Diff for: compiler/rustc_mir_transform/src/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl UsedLocals {
496496
self.increment = false;
497497

498498
// The location of the statement is irrelevant.
499-
let location = Location { block: START_BLOCK, statement_index: 0 };
499+
let location = Location::START;
500500
self.visit_statement(statement, location);
501501
}
502502

Diff for: compiler/rustc_target/src/spec/armebv7r_none_eabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn target() -> Target {
1919
max_atomic_width: Some(32),
2020
emit_debug_gdb_scripts: false,
2121
// GCC and Clang default to 8 for arm-none here
22-
c_enum_min_bits: 8,
22+
c_enum_min_bits: Some(8),
2323
..Default::default()
2424
},
2525
}

Diff for: compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn target() -> Target {
2020
max_atomic_width: Some(32),
2121
emit_debug_gdb_scripts: false,
2222
// GCC and Clang default to 8 for arm-none here
23-
c_enum_min_bits: 8,
23+
c_enum_min_bits: Some(8),
2424
..Default::default()
2525
},
2626
}

Diff for: compiler/rustc_target/src/spec/armv4t_none_eabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn target() -> Target {
4949
// from thumb_base, rust-lang/rust#44993.
5050
emit_debug_gdb_scripts: false,
5151
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
52-
c_enum_min_bits: 8,
52+
c_enum_min_bits: Some(8),
5353
..Default::default()
5454
},
5555
}

Diff for: compiler/rustc_target/src/spec/armv7a_none_eabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn target() -> Target {
2727
max_atomic_width: Some(64),
2828
panic_strategy: PanicStrategy::Abort,
2929
emit_debug_gdb_scripts: false,
30-
c_enum_min_bits: 8,
30+
c_enum_min_bits: Some(8),
3131
..Default::default()
3232
};
3333
Target {

Diff for: compiler/rustc_target/src/spec/armv7a_none_eabihf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn target() -> Target {
1919
panic_strategy: PanicStrategy::Abort,
2020
emit_debug_gdb_scripts: false,
2121
// GCC and Clang default to 8 for arm-none here
22-
c_enum_min_bits: 8,
22+
c_enum_min_bits: Some(8),
2323
..Default::default()
2424
};
2525
Target {

Diff for: compiler/rustc_target/src/spec/armv7r_none_eabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn target() -> Target {
1818
max_atomic_width: Some(32),
1919
emit_debug_gdb_scripts: false,
2020
// GCC and Clang default to 8 for arm-none here
21-
c_enum_min_bits: 8,
21+
c_enum_min_bits: Some(8),
2222
..Default::default()
2323
},
2424
}

Diff for: compiler/rustc_target/src/spec/armv7r_none_eabihf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn target() -> Target {
1919
max_atomic_width: Some(32),
2020
emit_debug_gdb_scripts: false,
2121
// GCC and Clang default to 8 for arm-none here
22-
c_enum_min_bits: 8,
22+
c_enum_min_bits: Some(8),
2323
..Default::default()
2424
},
2525
}

Diff for: compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn target() -> Target {
1111
base.has_rpath = true;
1212
base.linker_flavor = LinkerFlavor::Unix(Cc::Yes);
1313

14-
base.c_enum_min_bits = 8;
14+
base.c_enum_min_bits = Some(8);
1515

1616
Target {
1717
llvm_target: "hexagon-unknown-linux-musl".into(),

Diff for: compiler/rustc_target/src/spec/mod.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,18 @@ impl Target {
13441344
});
13451345
}
13461346

1347-
dl.c_enum_min_size = match Integer::from_size(Size::from_bits(self.c_enum_min_bits)) {
1348-
Ok(bits) => bits,
1349-
Err(err) => return Err(TargetDataLayoutErrors::InvalidBitsSize { err }),
1350-
};
1347+
dl.c_enum_min_size = self
1348+
.c_enum_min_bits
1349+
.map_or_else(
1350+
|| {
1351+
self.c_int_width
1352+
.parse()
1353+
.map_err(|_| String::from("failed to parse c_int_width"))
1354+
},
1355+
Ok,
1356+
)
1357+
.and_then(|i| Integer::from_size(Size::from_bits(i)))
1358+
.map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?;
13511359

13521360
Ok(dl)
13531361
}
@@ -1701,8 +1709,8 @@ pub struct TargetOptions {
17011709
/// If present it's a default value to use for adjusting the C ABI.
17021710
pub default_adjusted_cabi: Option<Abi>,
17031711

1704-
/// Minimum number of bits in #[repr(C)] enum. Defaults to 32.
1705-
pub c_enum_min_bits: u64,
1712+
/// Minimum number of bits in #[repr(C)] enum. Defaults to the size of c_int
1713+
pub c_enum_min_bits: Option<u64>,
17061714

17071715
/// Whether or not the DWARF `.debug_aranges` section should be generated.
17081716
pub generate_arange_section: bool,
@@ -1935,7 +1943,7 @@ impl Default for TargetOptions {
19351943
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
19361944
supported_sanitizers: SanitizerSet::empty(),
19371945
default_adjusted_cabi: None,
1938-
c_enum_min_bits: 32,
1946+
c_enum_min_bits: None,
19391947
generate_arange_section: true,
19401948
supports_stack_protector: true,
19411949
entry_name: "main".into(),
@@ -2122,12 +2130,6 @@ impl Target {
21222130
base.$key_name = s;
21232131
}
21242132
} );
2125-
($key_name:ident, u64) => ( {
2126-
let name = (stringify!($key_name)).replace("_", "-");
2127-
if let Some(s) = obj.remove(&name).and_then(|j| Json::as_u64(&j)) {
2128-
base.$key_name = s;
2129-
}
2130-
} );
21312133
($key_name:ident, u32) => ( {
21322134
let name = (stringify!($key_name)).replace("_", "-");
21332135
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) {
@@ -2496,6 +2498,7 @@ impl Target {
24962498

24972499
key!(is_builtin, bool);
24982500
key!(c_int_width = "target-c-int-width");
2501+
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
24992502
key!(os);
25002503
key!(env);
25012504
key!(abi);
@@ -2591,7 +2594,6 @@ impl Target {
25912594
key!(supported_split_debuginfo, falliable_list)?;
25922595
key!(supported_sanitizers, SanitizerSet)?;
25932596
key!(default_adjusted_cabi, Option<Abi>)?;
2594-
key!(c_enum_min_bits, u64);
25952597
key!(generate_arange_section, bool);
25962598
key!(supports_stack_protector, bool);
25972599
key!(entry_name);

Diff for: compiler/rustc_target/src/spec/thumb_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn opts() -> TargetOptions {
5353
frame_pointer: FramePointer::Always,
5454
// ARM supports multiple ABIs for enums, the linux one matches the default of 32 here
5555
// but any arm-none or thumb-none target will be defaulted to 8 on GCC and clang
56-
c_enum_min_bits: 8,
56+
c_enum_min_bits: Some(8),
5757
..Default::default()
5858
}
5959
}

Diff for: compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn target() -> Target {
5555
// suggested from thumb_base, rust-lang/rust#44993.
5656
emit_debug_gdb_scripts: false,
5757
// suggested from thumb_base, with no-os gcc/clang use 8-bit enums
58-
c_enum_min_bits: 8,
58+
c_enum_min_bits: Some(8),
5959
frame_pointer: FramePointer::MayOmit,
6060

6161
main_needs_argc_argv: false,

Diff for: src/bootstrap/compile.rs

+66
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,72 @@ impl Step for StdLink {
445445
let libdir = builder.sysroot_libdir(target_compiler, target);
446446
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
447447
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
448+
449+
if compiler.stage == 0 {
450+
// special handling for stage0, to make `rustup toolchain link` and `x dist --stage 0`
451+
// work for stage0-sysroot
452+
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
453+
454+
let host_lib_dir = builder.initial_rustc.ancestors().nth(2).unwrap().join("lib");
455+
let host_bin_dir = builder.out.join(&builder.initial_rustc.parent().unwrap());
456+
let host_codegen_backends =
457+
host_lib_dir.join("rustlib").join(&compiler.host.triple).join("codegen-backends");
458+
let sysroot_bin_dir = sysroot.join("bin");
459+
let sysroot_lib_dir = sysroot.join("lib");
460+
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
461+
462+
// Create the `bin` directory in stage0-sysroot
463+
t!(fs::create_dir_all(&sysroot_bin_dir));
464+
465+
// copy bin files from `builder.initial_rustc/./` to `stage0-sysroot/bin`
466+
if let Ok(files) = fs::read_dir(&host_bin_dir) {
467+
for file in files {
468+
let file = t!(file);
469+
if file.file_name() == "rustfmt" {
470+
// This is when `rustc` and `cargo` are set in `config.toml`
471+
if !file.path().starts_with(&builder.out) {
472+
builder.copy(
473+
&file.path().into_boxed_path(),
474+
&sysroot_bin_dir.join(file.file_name()),
475+
);
476+
} else {
477+
builder.copy(
478+
&builder
479+
.out
480+
.join(&compiler.host.triple)
481+
.join("rustfmt/bin/rustfmt"),
482+
&sysroot_bin_dir.join(file.file_name()),
483+
);
484+
}
485+
} else {
486+
builder.copy(
487+
&file.path().into_boxed_path(),
488+
&sysroot_bin_dir.join(file.file_name()),
489+
);
490+
}
491+
}
492+
}
493+
494+
// copy dylib files from `builder.initial_rustc/../lib/*` while excluding the `rustlib` directory to `stage0-sysroot/lib`
495+
if let Ok(files) = fs::read_dir(&host_lib_dir) {
496+
for file in files {
497+
let file = t!(file);
498+
let path = file.path();
499+
if path.is_file()
500+
&& is_dylib(&file.file_name().into_string().unwrap())
501+
&& !path.starts_with(sysroot_lib_dir.join("rustlib").into_boxed_path())
502+
{
503+
builder.copy(&path, &sysroot_lib_dir.join(path.file_name().unwrap()));
504+
}
505+
}
506+
}
507+
508+
t!(fs::create_dir_all(&sysroot_codegen_backends));
509+
// copy `codegen-backends` from `host_lib_dir/rustlib/codegen_backends` to `stage0-sysroot/lib/rustlib/host-triple/codegen-backends` if it exists.
510+
if host_codegen_backends.exists() {
511+
builder.cp_r(&host_codegen_backends, &sysroot_codegen_backends);
512+
}
513+
}
448514
}
449515
}
450516

0 commit comments

Comments
 (0)