Skip to content

Commit 00d2994

Browse files
committed
Auto merge of #145063 - tgross35:rollup-mkyt3zj, r=tgross35
Rollup of 8 pull requests Successful merges: - #144705 (compiler-builtins: plumb LSE support for aarch64 on linux/gnu when optimized-compiler-builtins not enabled) - #144857 (Port `#[allow_internal_unsafe]` to the new attribute system) - #144900 (Stabilize `unsigned_signed_diff` feature) - #144903 (Rename `begin_panic_handler` to `panic_handler`) - #144974 (compiler-builtins subtree update) - #145004 (Couple of minor cleanups) - #145007 (Fix build/doc/test of error index generator) - #145018 (Derive `Hash` for rustc_public types) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2fd855f + da9f352 commit 00d2994

File tree

200 files changed

+873
-796
lines changed

Some content is hidden

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

200 files changed

+873
-796
lines changed

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
113113
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
114114
}
115115
}
116+
117+
pub(crate) struct AllowInternalUnsafeParser;
118+
119+
impl<S: Stage> NoArgsAttributeParser<S> for AllowInternalUnsafeParser {
120+
const PATH: &[Symbol] = &[sym::allow_internal_unsafe];
121+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
122+
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::AllowInternalUnsafe(span);
123+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use crate::attributes::lint_helpers::{
3333
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3434
};
3535
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
36-
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
36+
use crate::attributes::macro_attrs::{
37+
AllowInternalUnsafeParser, MacroEscapeParser, MacroUseParser,
38+
};
3739
use crate::attributes::must_use::MustUseParser;
3840
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
3941
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -178,6 +180,7 @@ attribute_parsers!(
178180
Single<SkipDuringMethodDispatchParser>,
179181
Single<TransparencyParser>,
180182
Single<WithoutArgs<AllowIncoherentImplParser>>,
183+
Single<WithoutArgs<AllowInternalUnsafeParser>>,
181184
Single<WithoutArgs<AsPtrParser>>,
182185
Single<WithoutArgs<AutomaticallyDerivedParser>>,
183186
Single<WithoutArgs<CoherenceIsCoreParser>>,

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ pub(crate) fn codegen(
862862
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
863863
let thin_bc =
864864
module.thin_lto_buffer.as_deref().expect("cannot find embedded bitcode");
865-
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, &thin_bc);
865+
embed_bitcode(cgcx, llcx, llmod, &thin_bc);
866866
}
867867
}
868868

@@ -1058,40 +1058,38 @@ fn embed_bitcode(
10581058
cgcx: &CodegenContext<LlvmCodegenBackend>,
10591059
llcx: &llvm::Context,
10601060
llmod: &llvm::Module,
1061-
cmdline: &str,
10621061
bitcode: &[u8],
10631062
) {
10641063
// We're adding custom sections to the output object file, but we definitely
10651064
// do not want these custom sections to make their way into the final linked
1066-
// executable. The purpose of these custom sections is for tooling
1067-
// surrounding object files to work with the LLVM IR, if necessary. For
1068-
// example rustc's own LTO will look for LLVM IR inside of the object file
1069-
// in these sections by default.
1065+
// executable. The purpose of this custom section is for tooling surrounding
1066+
// object files to work with the LLVM IR, if necessary. For example rustc's
1067+
// own LTO will look for LLVM IR inside of the object file in this section
1068+
// by default.
10701069
//
10711070
// To handle this is a bit different depending on the object file format
10721071
// used by the backend, broken down into a few different categories:
10731072
//
10741073
// * Mach-O - this is for macOS. Inspecting the source code for the native
1075-
// linker here shows that the `.llvmbc` and `.llvmcmd` sections are
1076-
// automatically skipped by the linker. In that case there's nothing extra
1077-
// that we need to do here.
1074+
// linker here shows that the `.llvmbc` section is automatically skipped
1075+
// by the linker. In that case there's nothing extra that we need to do
1076+
// here.
10781077
//
1079-
// * Wasm - the native LLD linker is hard-coded to skip `.llvmbc` and
1080-
// `.llvmcmd` sections, so there's nothing extra we need to do.
1078+
// * Wasm - the native LLD linker is hard-coded to skip `.llvmbc` section,
1079+
// so there's nothing extra we need to do.
10811080
//
1082-
// * COFF - if we don't do anything the linker will by default copy all
1083-
// these sections to the output artifact, not what we want! To subvert
1084-
// this we want to flag the sections we inserted here as
1085-
// `IMAGE_SCN_LNK_REMOVE`.
1081+
// * COFF - if we don't do anything the linker will by default copy this
1082+
// section to the output artifact, not what we want! To subvert this we
1083+
// want to flag the section we inserted here as `IMAGE_SCN_LNK_REMOVE`.
10861084
//
1087-
// * ELF - this is very similar to COFF above. One difference is that these
1088-
// sections are removed from the output linked artifact when
1089-
// `--gc-sections` is passed, which we pass by default. If that flag isn't
1090-
// passed though then these sections will show up in the final output.
1091-
// Additionally the flag that we need to set here is `SHF_EXCLUDE`.
1085+
// * ELF - this is very similar to COFF above. One difference is that this
1086+
// section is removed from the output linked artifact when `--gc-sections`
1087+
// is passed, which we pass by default. If that flag isn't passed through
1088+
// then this section will show up in the final output. Additionally the
1089+
// flag that we need to set here is `SHF_EXCLUDE`.
10921090
//
1093-
// * XCOFF - AIX linker ignores content in .ipa and .info if no auxiliary
1094-
// symbol associated with these sections.
1091+
// * XCOFF - AIX linker ignores content in .ipa if no auxiliary symbol
1092+
// associated with this section.
10951093
//
10961094
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
10971095
// and COFF we emit the sections using module level inline assembly for that
@@ -1110,26 +1108,11 @@ fn embed_bitcode(
11101108
llvm::set_section(llglobal, bitcode_section_name(cgcx));
11111109
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
11121110
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
1113-
1114-
let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
1115-
let llglobal = llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");
1116-
llvm::set_initializer(llglobal, llconst);
1117-
let section = if cgcx.target_is_like_darwin {
1118-
c"__LLVM,__cmdline"
1119-
} else if cgcx.target_is_like_aix {
1120-
c".info"
1121-
} else {
1122-
c".llvmcmd"
1123-
};
1124-
llvm::set_section(llglobal, section);
1125-
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
11261111
} else {
11271112
// We need custom section flags, so emit module-level inline assembly.
11281113
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
11291114
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
11301115
llvm::append_module_inline_asm(llmod, &asm);
1131-
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, cmdline.as_bytes());
1132-
llvm::append_module_inline_asm(llmod, &asm);
11331116
}
11341117
}
11351118

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,9 @@ pub struct ModuleConfig {
7676
/// Names of additional optimization passes to run.
7777
pub passes: Vec<String>,
7878
/// Some(level) to optimize at a certain level, or None to run
79-
/// absolutely no optimizations (used for the metadata module).
79+
/// absolutely no optimizations (used for the allocator module).
8080
pub opt_level: Option<config::OptLevel>,
8181

82-
/// Some(level) to optimize binary size, or None to not affect program size.
83-
pub opt_size: Option<config::OptLevel>,
84-
8582
pub pgo_gen: SwitchWithOptPath,
8683
pub pgo_use: Option<PathBuf>,
8784
pub pgo_sample_use: Option<PathBuf>,
@@ -102,15 +99,13 @@ pub struct ModuleConfig {
10299
pub emit_obj: EmitObj,
103100
pub emit_thin_lto: bool,
104101
pub emit_thin_lto_summary: bool,
105-
pub bc_cmdline: String,
106102

107103
// Miscellaneous flags. These are mostly copied from command-line
108104
// options.
109105
pub verify_llvm_ir: bool,
110106
pub lint_llvm_ir: bool,
111107
pub no_prepopulate_passes: bool,
112108
pub no_builtins: bool,
113-
pub time_module: bool,
114109
pub vectorize_loop: bool,
115110
pub vectorize_slp: bool,
116111
pub merge_functions: bool,
@@ -171,7 +166,6 @@ impl ModuleConfig {
171166
passes: if_regular!(sess.opts.cg.passes.clone(), vec![]),
172167

173168
opt_level: opt_level_and_size,
174-
opt_size: opt_level_and_size,
175169

176170
pgo_gen: if_regular!(
177171
sess.opts.cg.profile_generate.clone(),
@@ -221,17 +215,12 @@ impl ModuleConfig {
221215
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
222216
false
223217
),
224-
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
225218

226219
verify_llvm_ir: sess.verify_llvm_ir(),
227220
lint_llvm_ir: sess.opts.unstable_opts.lint_llvm_ir,
228221
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
229222
no_builtins: no_builtins || sess.target.no_builtins,
230223

231-
// Exclude metadata and allocator modules from time_passes output,
232-
// since they throw off the "LLVM passes" measurement.
233-
time_module: if_regular!(true, false),
234-
235224
// Copy what clang does by turning on loop vectorization at O2 and
236225
// slp vectorization at O3.
237226
vectorize_loop: !sess.opts.cg.no_vectorize_loops
@@ -1740,7 +1729,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17401729
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
17411730
work: WorkItem<B>,
17421731
) {
1743-
if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() {
1732+
if llvm_start_time.is_none() {
17441733
*llvm_start_time = Some(cgcx.prof.verbose_generic_activity("LLVM_passes"));
17451734
}
17461735

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -681,33 +681,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
681681

682682
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, target_cpu, autodiff_items);
683683

684-
// Codegen an allocator shim, if necessary.
685-
if let Some(kind) = allocator_kind_for_codegen(tcx) {
686-
let llmod_id =
687-
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
688-
let module_llvm = tcx.sess.time("write_allocator_module", || {
689-
backend.codegen_allocator(
690-
tcx,
691-
&llmod_id,
692-
kind,
693-
// If allocator_kind is Some then alloc_error_handler_kind must
694-
// also be Some.
695-
tcx.alloc_error_handler_kind(()).unwrap(),
696-
)
697-
});
698-
699-
ongoing_codegen.wait_for_signal_to_codegen_item();
700-
ongoing_codegen.check_for_errors(tcx.sess);
701-
702-
// These modules are generally cheap and won't throw off scheduling.
703-
let cost = 0;
704-
submit_codegened_module_to_llvm(
705-
&ongoing_codegen.coordinator,
706-
ModuleCodegen::new_allocator(llmod_id, module_llvm),
707-
cost,
708-
);
709-
}
710-
711684
// For better throughput during parallel processing by LLVM, we used to sort
712685
// CGUs largest to smallest. This would lead to better thread utilization
713686
// by, for example, preventing a large CGU from being processed last and
@@ -823,6 +796,35 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
823796
}
824797
}
825798

799+
// Codegen an allocator shim, if necessary.
800+
// Do this last to ensure the LLVM_passes timer doesn't start while no CGUs have been codegened
801+
// yet for the backend to optimize.
802+
if let Some(kind) = allocator_kind_for_codegen(tcx) {
803+
let llmod_id =
804+
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
805+
let module_llvm = tcx.sess.time("write_allocator_module", || {
806+
backend.codegen_allocator(
807+
tcx,
808+
&llmod_id,
809+
kind,
810+
// If allocator_kind is Some then alloc_error_handler_kind must
811+
// also be Some.
812+
tcx.alloc_error_handler_kind(()).unwrap(),
813+
)
814+
});
815+
816+
ongoing_codegen.wait_for_signal_to_codegen_item();
817+
ongoing_codegen.check_for_errors(tcx.sess);
818+
819+
// These modules are generally cheap and won't throw off scheduling.
820+
let cost = 0;
821+
submit_codegened_module_to_llvm(
822+
&ongoing_codegen.coordinator,
823+
ModuleCodegen::new_allocator(llmod_id, module_llvm),
824+
cost,
825+
);
826+
}
827+
826828
ongoing_codegen.codegen_finished(tcx);
827829

828830
// Since the main thread is sometimes blocked during codegen, we keep track

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,7 @@ impl SyntaxExtension {
905905
find_attr!(attrs, AttributeKind::AllowInternalUnstable(i, _) => i)
906906
.map(|i| i.as_slice())
907907
.unwrap_or_default();
908-
// FIXME(jdonszelman): allow_internal_unsafe isn't yet new-style
909-
// let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe);
910-
let allow_internal_unsafe =
911-
ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some();
908+
let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe(_));
912909

913910
let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export)
914911
.and_then(|macro_export| macro_export.meta_item_list())

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ pub enum AttributeKind {
249249
/// Represents `#[rustc_allow_incoherent_impl]`.
250250
AllowIncoherentImpl(Span),
251251

252+
/// Represents `#[allow_internal_unsafe]`.
253+
AllowInternalUnsafe(Span),
254+
252255
/// Represents `#[allow_internal_unstable]`.
253256
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
254257

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ impl AttributeKind {
1616
Align { .. } => No,
1717
AllowConstFnUnstable(..) => No,
1818
AllowIncoherentImpl(..) => No,
19+
AllowInternalUnsafe(..) => Yes,
1920
AllowInternalUnstable(..) => Yes,
2021
AsPtr(..) => Yes,
2122
AutomaticallyDerived(..) => Yes,

compiler/rustc_lint/src/builtin.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
//! [`crate::late_lint_methods!`] invocation in `lib.rs`.
1515
1616
use std::fmt::Write;
17+
use std::slice;
1718

1819
use ast::token::TokenKind;
1920
use rustc_abi::BackendRepr;
2021
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2122
use rustc_ast::visit::{FnCtxt, FnKind};
2223
use rustc_ast::{self as ast, *};
2324
use rustc_ast_pretty::pprust::expr_to_string;
25+
use rustc_attr_parsing::AttributeParser;
2426
use rustc_errors::{Applicability, LintDiagnostic};
2527
use rustc_feature::GateIssue;
2628
use rustc_hir as hir;
@@ -249,7 +251,16 @@ impl UnsafeCode {
249251

250252
impl EarlyLintPass for UnsafeCode {
251253
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
252-
if attr.has_name(sym::allow_internal_unsafe) {
254+
if AttributeParser::parse_limited(
255+
cx.builder.sess(),
256+
slice::from_ref(attr),
257+
sym::allow_internal_unsafe,
258+
attr.span,
259+
DUMMY_NODE_ID,
260+
Some(cx.builder.features()),
261+
)
262+
.is_some()
263+
{
253264
self.report_unsafe(cx, attr.span, BuiltinUnsafe::AllowInternalUnsafe);
254265
}
255266
}

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ passes_allow_incoherent_impl =
2929
`rustc_allow_incoherent_impl` attribute should be applied to impl items
3030
.label = the only currently supported targets are inherent methods
3131
32-
passes_allow_internal_unstable =
32+
passes_macro_only_attribute =
3333
attribute should be applied to a macro
3434
.label = not a macro
3535

0 commit comments

Comments
 (0)