Skip to content

Commit

Permalink
Auto merge of rust-lang#108159 - matthiaskrgr:rollup-5k2j7cx, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Feb 17, 2023
2 parents f4f5fc3 + ae5473c commit f722b24
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 42 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ pub struct TargetDataLayout {

pub instruction_address_space: AddressSpace,

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {

// The semantics of #[used] in Rust only require the symbol to make it into the
// object file. It is explicitly allowed for the linker to strip the symbol if it
// is dead, which means we are allowed use `llvm.compiler.used` instead of
// is dead, which means we are allowed to use `llvm.compiler.used` instead of
// `llvm.used` here.
//
// Additionally, https://reviews.llvm.org/D97448 in LLVM 13 started emitting unique
Expand All @@ -532,7 +532,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
// That said, we only ever emit these when compiling for ELF targets, unless
// `#[used(compiler)]` is explicitly requested. This is to avoid similar breakage
// on other targets, in particular MachO targets have *their* static constructor
// lists broken if `llvm.compiler.used` is emitted rather than llvm.used. However,
// lists broken if `llvm.compiler.used` is emitted rather than `llvm.used`. However,
// that check happens when assigning the `CodegenFnAttrFlags` in `rustc_hir_analysis`,
// so we don't need to take care of it here.
self.add_compiler_used_global(g);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
//! The backend-agnostic functions of this crate use functions defined in various traits that
//! have to be implemented by each backends.
//! have to be implemented by each backend.

#[macro_use]
extern crate rustc_macros;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
assert_eq!(self.new_block(), START_BLOCK);
self.visit_rvalue(
&mut rvalue,
Location { block: BasicBlock::new(0), statement_index: usize::MAX },
Location { block: START_BLOCK, statement_index: usize::MAX },
);

let span = self.promoted.span;
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ bitflags! {
/// the MIR `InstrumentCoverage` pass and not added to the coverage map
/// during codegen.
const NO_COVERAGE = 1 << 15;
/// `#[used(linker)]`: indicates that LLVM nor the linker can eliminate this function.
/// `#[used(linker)]`:
/// indicates that neither LLVM nor the linker will eliminate this function.
const USED_LINKER = 1 << 16;
/// `#[rustc_deallocator]`: a hint to LLVM that the function only deallocates memory.
const DEALLOCATOR = 1 << 17;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ macro_rules! make_mir_visitor {
self.visit_source_scope($(& $mutability)? *parent_scope);
}
if let Some((callee, callsite_span)) = inlined {
let location = START_BLOCK.start_location();
let location = Location::START;

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

Expand Down Expand Up @@ -837,7 +837,7 @@ macro_rules! make_mir_visitor {
} = var_debug_info;

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

for const_ in &$($mutability)? $body.required_consts {
let location = START_BLOCK.start_location();
let location = Location::START;
$self.visit_constant(const_, location);
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::{dump_mir, PassWhere};
use rustc_middle::mir::{
traversal, BasicBlock, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place,
Rvalue, Statement, StatementKind, TerminatorKind,
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, Rvalue,
Statement, StatementKind, TerminatorKind,
};
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::impls::MaybeLiveLocals;
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<'a, 'body, 'alloc, 'tcx> FilterInformation<'a, 'body, 'alloc, 'tcx> {
// to reuse the allocation.
write_info: write_info_alloc,
// Doesn't matter what we put here, will be overwritten before being used
at: Location { block: BasicBlock::from_u32(0), statement_index: 0 },
at: Location::START,
};
this.internal_filter_liveness();
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

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

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

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

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

// When first entering the generator, move the resume argument into its new local.
let source_info = SourceInfo::outermost(body.span);
let stmts = &mut body.basic_blocks_mut()[BasicBlock::new(0)].statements;
let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements;
stmts.insert(
0,
Statement {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
history: Vec::new(),
changed: false,
};
let blocks = BasicBlock::new(0)..body.basic_blocks.next_index();
let blocks = START_BLOCK..body.basic_blocks.next_index();
this.process_blocks(body, blocks);
this.changed
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl UsedLocals {
self.increment = false;

// The location of the statement is irrelevant.
let location = Location { block: START_BLOCK, statement_index: 0 };
let location = Location::START;
self.visit_statement(statement, location);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armebv7r_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn target() -> Target {
max_atomic_width: Some(32),
emit_debug_gdb_scripts: false,
// GCC and Clang default to 8 for arm-none here
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn target() -> Target {
max_atomic_width: Some(32),
emit_debug_gdb_scripts: false,
// GCC and Clang default to 8 for arm-none here
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armv4t_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn target() -> Target {
// from thumb_base, rust-lang/rust#44993.
emit_debug_gdb_scripts: false,
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armv7a_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn target() -> Target {
max_atomic_width: Some(64),
panic_strategy: PanicStrategy::Abort,
emit_debug_gdb_scripts: false,
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
};
Target {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armv7a_none_eabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn target() -> Target {
panic_strategy: PanicStrategy::Abort,
emit_debug_gdb_scripts: false,
// GCC and Clang default to 8 for arm-none here
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
};
Target {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armv7r_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn target() -> Target {
max_atomic_width: Some(32),
emit_debug_gdb_scripts: false,
// GCC and Clang default to 8 for arm-none here
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/armv7r_none_eabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn target() -> Target {
max_atomic_width: Some(32),
emit_debug_gdb_scripts: false,
// GCC and Clang default to 8 for arm-none here
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn target() -> Target {
base.has_rpath = true;
base.linker_flavor = LinkerFlavor::Unix(Cc::Yes);

base.c_enum_min_bits = 8;
base.c_enum_min_bits = Some(8);

Target {
llvm_target: "hexagon-unknown-linux-musl".into(),
Expand Down
30 changes: 16 additions & 14 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,10 +1344,18 @@ impl Target {
});
}

dl.c_enum_min_size = match Integer::from_size(Size::from_bits(self.c_enum_min_bits)) {
Ok(bits) => bits,
Err(err) => return Err(TargetDataLayoutErrors::InvalidBitsSize { err }),
};
dl.c_enum_min_size = self
.c_enum_min_bits
.map_or_else(
|| {
self.c_int_width
.parse()
.map_err(|_| String::from("failed to parse c_int_width"))
},
Ok,
)
.and_then(|i| Integer::from_size(Size::from_bits(i)))
.map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?;

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

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

/// Whether or not the DWARF `.debug_aranges` section should be generated.
pub generate_arange_section: bool,
Expand Down Expand Up @@ -1935,7 +1943,7 @@ impl Default for TargetOptions {
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
supported_sanitizers: SanitizerSet::empty(),
default_adjusted_cabi: None,
c_enum_min_bits: 32,
c_enum_min_bits: None,
generate_arange_section: true,
supports_stack_protector: true,
entry_name: "main".into(),
Expand Down Expand Up @@ -2122,12 +2130,6 @@ impl Target {
base.$key_name = s;
}
} );
($key_name:ident, u64) => ( {
let name = (stringify!($key_name)).replace("_", "-");
if let Some(s) = obj.remove(&name).and_then(|j| Json::as_u64(&j)) {
base.$key_name = s;
}
} );
($key_name:ident, u32) => ( {
let name = (stringify!($key_name)).replace("_", "-");
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) {
Expand Down Expand Up @@ -2496,6 +2498,7 @@ impl Target {

key!(is_builtin, bool);
key!(c_int_width = "target-c-int-width");
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
key!(os);
key!(env);
key!(abi);
Expand Down Expand Up @@ -2591,7 +2594,6 @@ impl Target {
key!(supported_split_debuginfo, falliable_list)?;
key!(supported_sanitizers, SanitizerSet)?;
key!(default_adjusted_cabi, Option<Abi>)?;
key!(c_enum_min_bits, u64);
key!(generate_arange_section, bool);
key!(supports_stack_protector, bool);
key!(entry_name);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/thumb_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn opts() -> TargetOptions {
frame_pointer: FramePointer::Always,
// ARM supports multiple ABIs for enums, the linux one matches the default of 32 here
// but any arm-none or thumb-none target will be defaulted to 8 on GCC and clang
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
..Default::default()
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn target() -> Target {
// suggested from thumb_base, rust-lang/rust#44993.
emit_debug_gdb_scripts: false,
// suggested from thumb_base, with no-os gcc/clang use 8-bit enums
c_enum_min_bits: 8,
c_enum_min_bits: Some(8),
frame_pointer: FramePointer::MayOmit,

main_needs_argc_argv: false,
Expand Down
66 changes: 66 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,72 @@ impl Step for StdLink {
let libdir = builder.sysroot_libdir(target_compiler, target);
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));

if compiler.stage == 0 {
// special handling for stage0, to make `rustup toolchain link` and `x dist --stage 0`
// work for stage0-sysroot
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");

let host_lib_dir = builder.initial_rustc.ancestors().nth(2).unwrap().join("lib");
let host_bin_dir = builder.out.join(&builder.initial_rustc.parent().unwrap());
let host_codegen_backends =
host_lib_dir.join("rustlib").join(&compiler.host.triple).join("codegen-backends");
let sysroot_bin_dir = sysroot.join("bin");
let sysroot_lib_dir = sysroot.join("lib");
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);

// Create the `bin` directory in stage0-sysroot
t!(fs::create_dir_all(&sysroot_bin_dir));

// copy bin files from `builder.initial_rustc/./` to `stage0-sysroot/bin`
if let Ok(files) = fs::read_dir(&host_bin_dir) {
for file in files {
let file = t!(file);
if file.file_name() == "rustfmt" {
// This is when `rustc` and `cargo` are set in `config.toml`
if !file.path().starts_with(&builder.out) {
builder.copy(
&file.path().into_boxed_path(),
&sysroot_bin_dir.join(file.file_name()),
);
} else {
builder.copy(
&builder
.out
.join(&compiler.host.triple)
.join("rustfmt/bin/rustfmt"),
&sysroot_bin_dir.join(file.file_name()),
);
}
} else {
builder.copy(
&file.path().into_boxed_path(),
&sysroot_bin_dir.join(file.file_name()),
);
}
}
}

// copy dylib files from `builder.initial_rustc/../lib/*` while excluding the `rustlib` directory to `stage0-sysroot/lib`
if let Ok(files) = fs::read_dir(&host_lib_dir) {
for file in files {
let file = t!(file);
let path = file.path();
if path.is_file()
&& is_dylib(&file.file_name().into_string().unwrap())
&& !path.starts_with(sysroot_lib_dir.join("rustlib").into_boxed_path())
{
builder.copy(&path, &sysroot_lib_dir.join(path.file_name().unwrap()));
}
}
}

t!(fs::create_dir_all(&sysroot_codegen_backends));
// copy `codegen-backends` from `host_lib_dir/rustlib/codegen_backends` to `stage0-sysroot/lib/rustlib/host-triple/codegen-backends` if it exists.
if host_codegen_backends.exists() {
builder.cp_r(&host_codegen_backends, &sysroot_codegen_backends);
}
}
}
}

Expand Down
Loading

0 comments on commit f722b24

Please sign in to comment.