Skip to content

Commit 7cd749d

Browse files
Rollup merge of #141511 - Noratrieb:codegen-fn-attrs, r=compiler-errors
Cleanup CodegenFnAttrFlags - Rename `USED` to `USED_COMPILER` to better reflect its behavior. - Reorder some items to group the used and allocator flags together - Renumber them without gaps
2 parents 76ca0e2 + fa2bb59 commit 7cd749d

File tree

9 files changed

+31
-34
lines changed

9 files changed

+31
-34
lines changed

compiler/rustc_codegen_gcc/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
154154
// TODO(antoyo): set link section.
155155
}
156156

157-
if attrs.flags.contains(CodegenFnAttrFlags::USED)
157+
if attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
158158
|| attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
159159
{
160160
self.add_used_global(global.to_rvalue());

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'ll> CodegenCx<'ll, '_> {
527527

528528
base::set_variable_sanitizer_attrs(g, attrs);
529529

530-
if attrs.flags.contains(CodegenFnAttrFlags::USED) {
530+
if attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER) {
531531
// `USED` and `USED_LINKER` can't be used together.
532532
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER));
533533

@@ -551,7 +551,7 @@ impl<'ll> CodegenCx<'ll, '_> {
551551
}
552552
if attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) {
553553
// `USED` and `USED_LINKER` can't be used together.
554-
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED));
554+
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER));
555555

556556
self.add_used_global(g);
557557
}

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
128128
} else {
129129
SymbolExportKind::Text
130130
},
131-
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
131+
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
132132
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
133133
|| used,
134134
};

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
189189
)
190190
.emit();
191191
}
192-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
192+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER;
193193
}
194194
Some(_) => {
195195
tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span() });
@@ -220,7 +220,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
220220
|| tcx.sess.target.is_like_windows
221221
|| tcx.sess.target.is_like_wasm);
222222
codegen_fn_attrs.flags |= if is_like_elf {
223-
CodegenFnAttrFlags::USED
223+
CodegenFnAttrFlags::USED_COMPILER
224224
} else {
225225
CodegenFnAttrFlags::USED_LINKER
226226
};

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,49 +96,46 @@ bitflags::bitflags! {
9696
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
9797
/// the hot path.
9898
const COLD = 1 << 0;
99-
/// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this
100-
/// function is never null and the function has no side effects other than allocating.
101-
const ALLOCATOR = 1 << 1;
102-
/// An indicator that function will never unwind. Will become obsolete
103-
/// once C-unwind is fully stabilized.
104-
const NEVER_UNWIND = 1 << 3;
99+
/// `#[rustc_nounwind]`: An indicator that function will never unwind.
100+
const NEVER_UNWIND = 1 << 1;
105101
/// `#[naked]`: an indicator to LLVM that no function prologue/epilogue
106102
/// should be generated.
107-
const NAKED = 1 << 4;
103+
const NAKED = 1 << 2;
108104
/// `#[no_mangle]`: an indicator that the function's name should be the same
109105
/// as its symbol.
110-
const NO_MANGLE = 1 << 5;
106+
const NO_MANGLE = 1 << 3;
111107
/// `#[rustc_std_internal_symbol]`: an indicator that this symbol is a
112108
/// "weird symbol" for the standard library in that it has slightly
113109
/// different linkage, visibility, and reachability rules.
114-
const RUSTC_STD_INTERNAL_SYMBOL = 1 << 6;
110+
const RUSTC_STD_INTERNAL_SYMBOL = 1 << 4;
115111
/// `#[thread_local]`: indicates a static is actually a thread local
116112
/// piece of memory
117-
const THREAD_LOCAL = 1 << 8;
118-
/// `#[used]`: indicates that LLVM can't eliminate this function (but the
113+
const THREAD_LOCAL = 1 << 5;
114+
/// `#[used(compiler)]`: indicates that LLVM can't eliminate this function (but the
119115
/// linker can!).
120-
const USED = 1 << 9;
116+
const USED_COMPILER = 1 << 6;
117+
/// `#[used(linker)]`:
118+
/// indicates that neither LLVM nor the linker will eliminate this function.
119+
const USED_LINKER = 1 << 7;
121120
/// `#[track_caller]`: allow access to the caller location
122-
const TRACK_CALLER = 1 << 10;
121+
const TRACK_CALLER = 1 << 8;
123122
/// #[ffi_pure]: applies clang's `pure` attribute to a foreign function
124123
/// declaration.
125-
const FFI_PURE = 1 << 11;
124+
const FFI_PURE = 1 << 9;
126125
/// #[ffi_const]: applies clang's `const` attribute to a foreign function
127126
/// declaration.
128-
const FFI_CONST = 1 << 12;
129-
// (Bit 13 was used for `#[cmse_nonsecure_entry]`, but is now unused.)
130-
// (Bit 14 was used for `#[coverage(off)]`, but is now unused.)
131-
/// `#[used(linker)]`:
132-
/// indicates that neither LLVM nor the linker will eliminate this function.
133-
const USED_LINKER = 1 << 15;
127+
const FFI_CONST = 1 << 10;
128+
/// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this
129+
/// function is never null and the function has no side effects other than allocating.
130+
const ALLOCATOR = 1 << 11;
134131
/// `#[rustc_deallocator]`: a hint to LLVM that the function only deallocates memory.
135-
const DEALLOCATOR = 1 << 16;
132+
const DEALLOCATOR = 1 << 12;
136133
/// `#[rustc_reallocator]`: a hint to LLVM that the function only reallocates memory.
137-
const REALLOCATOR = 1 << 17;
134+
const REALLOCATOR = 1 << 13;
138135
/// `#[rustc_allocator_zeroed]`: a hint to LLVM that the function only allocates zeroed memory.
139-
const ALLOCATOR_ZEROED = 1 << 18;
136+
const ALLOCATOR_ZEROED = 1 << 14;
140137
/// `#[no_builtins]`: indicates that disable implicit builtin knowledge of functions for the function.
141-
const NO_BUILTINS = 1 << 19;
138+
const NO_BUILTINS = 1 << 15;
142139
}
143140
}
144141
rustc_data_structures::external_bitflags_debug! { CodegenFnAttrFlags }

compiler/rustc_passes/src/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ fn has_allow_dead_code_or_lang_attr(
707707
// #[used], #[no_mangle], #[export_name], etc also keeps the item alive
708708
// forcefully, e.g., for placing it in a specific section.
709709
cg_attrs.contains_extern_indicator()
710-
|| cg_attrs.flags.contains(CodegenFnAttrFlags::USED)
710+
|| cg_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
711711
|| cg_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
712712
}
713713
}

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
427427
// FIXME(nbdd0121): `#[used]` are marked as reachable here so it's picked up by
428428
// `linked_symbols` in cg_ssa. They won't be exported in binary or cdylib due to their
429429
// `SymbolExportLevel::Rust` export level but may end up being exported in dylibs.
430-
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
430+
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
431431
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
432432
}
433433

src/tools/miri/src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
281281
}
282282
let codegen_fn_attrs = tcx.codegen_fn_attrs(local_def_id);
283283
if codegen_fn_attrs.contains_extern_indicator()
284-
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED)
284+
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
285285
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
286286
{
287287
Some((

src/tools/miri/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn iter_exported_symbols<'tcx>(
135135
let codegen_attrs = tcx.codegen_fn_attrs(def_id);
136136
codegen_attrs.contains_extern_indicator()
137137
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
138-
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
138+
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
139139
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
140140
};
141141
if exported {

0 commit comments

Comments
 (0)