Skip to content

Commit a27da03

Browse files
committed
Add deny(unreachable_pub) to rustc_codegen_llvm.
The unused function `Builder::va_arg` is removed as part of this.
1 parent 28544c7 commit a27da03

31 files changed

+270
-253
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ use rustc_codegen_ssa::traits::*;
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_middle::bug;
1515
use rustc_middle::ty::layout::LayoutOf;
16-
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
16+
pub(crate) use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
1717
use rustc_middle::ty::Ty;
1818
use rustc_session::config;
19-
pub use rustc_target::abi::call::*;
19+
pub(crate) use rustc_target::abi::call::*;
2020
use rustc_target::abi::{self, HasDataLayout, Int, Size};
21-
pub use rustc_target::spec::abi::Abi;
21+
pub(crate) use rustc_target::spec::abi::Abi;
2222
use rustc_target::spec::SanitizerSet;
2323

2424
use libc::c_uint;
2525
use smallvec::SmallVec;
2626

2727
use std::cmp;
2828

29-
pub trait ArgAttributesExt {
29+
trait ArgAttributesExt {
3030
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value);
3131
fn apply_attrs_to_callsite(
3232
&self,
@@ -112,7 +112,7 @@ impl ArgAttributesExt for ArgAttributes {
112112
}
113113
}
114114

115-
pub trait LlvmType {
115+
pub(crate) trait LlvmType {
116116
fn llvm_type<'ll>(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type;
117117
}
118118

@@ -170,7 +170,7 @@ impl LlvmType for CastTarget {
170170
}
171171
}
172172

173-
pub trait ArgAbiExt<'ll, 'tcx> {
173+
trait ArgAbiExt<'ll, 'tcx> {
174174
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
175175
fn store(
176176
&self,
@@ -305,7 +305,7 @@ impl<'ll, 'tcx> ArgAbiMethods<'tcx> for Builder<'_, 'll, 'tcx> {
305305
}
306306
}
307307

308-
pub trait FnAbiLlvmExt<'ll, 'tcx> {
308+
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
309309
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
310310
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
311311
fn llvm_cconv(&self) -> llvm::CallConv;

compiler/rustc_codegen_llvm/src/attributes.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDi
1515
use crate::llvm::AttributePlace::Function;
1616
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
1717
use crate::llvm_util;
18-
pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
18+
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
1919

2020
use crate::context::CodegenCx;
2121
use crate::value::Value;
2222

23-
pub fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
23+
pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
2424
if !attrs.is_empty() {
2525
llvm::AddFunctionAttributes(llfn, idx, attrs);
2626
}
2727
}
2828

29-
pub fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
29+
pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
3030
if !attrs.is_empty() {
3131
llvm::AddCallSiteAttributes(callsite, idx, attrs);
3232
}
@@ -55,7 +55,7 @@ fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll
5555

5656
/// Get LLVM sanitize attributes.
5757
#[inline]
58-
pub fn sanitize_attrs<'ll>(
58+
pub(crate) fn sanitize_attrs<'ll>(
5959
cx: &CodegenCx<'ll, '_>,
6060
no_sanitize: SanitizerSet,
6161
) -> SmallVec<[&'ll Attribute; 4]> {
@@ -95,15 +95,15 @@ pub fn sanitize_attrs<'ll>(
9595

9696
/// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function.
9797
#[inline]
98-
pub fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>) -> &Attribute {
98+
pub(crate) fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>) -> &Attribute {
9999
// NOTE: We should determine if we even need async unwind tables, as they
100100
// take have more overhead and if we can use sync unwind tables we
101101
// probably should.
102102
let async_unwind = !use_sync_unwind.unwrap_or(false);
103103
llvm::CreateUWTableAttr(llcx, async_unwind)
104104
}
105105

106-
pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
106+
pub(crate) fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
107107
let mut fp = cx.sess().target.frame_pointer;
108108
let opts = &cx.sess().opts;
109109
// "mcount" function relies on stack pointer.
@@ -243,19 +243,19 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
243243
Some(sspattr.create_attr(cx.llcx))
244244
}
245245

246-
pub fn target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Attribute {
246+
pub(crate) fn target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Attribute {
247247
let target_cpu = llvm_util::target_cpu(cx.tcx.sess);
248248
llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu)
249249
}
250250

251-
pub fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
251+
pub(crate) fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
252252
llvm_util::tune_cpu(cx.tcx.sess)
253253
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu))
254254
}
255255

256256
/// Get the `NonLazyBind` LLVM attribute,
257257
/// if the codegen options allow skipping the PLT.
258-
pub fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
258+
pub(crate) fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
259259
// Don't generate calls through PLT if it's not necessary
260260
if !cx.sess().needs_plt() {
261261
Some(AttributeKind::NonLazyBind.create_attr(cx.llcx))
@@ -289,7 +289,7 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
289289

290290
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
291291
/// attributes.
292-
pub fn from_fn_attrs<'ll, 'tcx>(
292+
pub(crate) fn from_fn_attrs<'ll, 'tcx>(
293293
cx: &CodegenCx<'ll, 'tcx>,
294294
llfn: &'ll Value,
295295
instance: ty::Instance<'tcx>,

compiler/rustc_codegen_llvm/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a> ArchiveBuilder for LlvmArchiveBuilder<'a> {
106106
}
107107
}
108108

109-
pub struct LlvmArchiveBuilderBuilder;
109+
pub(crate) struct LlvmArchiveBuilderBuilder;
110110

111111
impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
112112
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {

compiler/rustc_codegen_llvm/src/back/lto.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ use std::sync::Arc;
3434

3535
/// We keep track of the computed LTO cache keys from the previous
3636
/// session to determine which CGUs we can reuse.
37-
pub const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";
37+
const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";
3838

39-
pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
39+
fn crate_type_allows_lto(crate_type: CrateType) -> bool {
4040
match crate_type {
4141
CrateType::Executable
4242
| CrateType::Dylib
@@ -709,7 +709,7 @@ impl Drop for ThinBuffer {
709709
}
710710
}
711711

712-
pub unsafe fn optimize_thin_module(
712+
pub(crate) unsafe fn optimize_thin_module(
713713
thin_module: ThinModule<LlvmCodegenBackend>,
714714
cgcx: &CodegenContext<LlvmCodegenBackend>,
715715
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
@@ -798,7 +798,7 @@ pub unsafe fn optimize_thin_module(
798798

799799
/// Maps LLVM module identifiers to their corresponding LLVM LTO cache keys
800800
#[derive(Debug, Default)]
801-
pub struct ThinLTOKeysMap {
801+
struct ThinLTOKeysMap {
802802
// key = llvm name of importing module, value = LLVM cache key
803803
keys: BTreeMap<String, String>,
804804
}
@@ -855,7 +855,7 @@ fn module_name_to_str(c_str: &CStr) -> &str {
855855
})
856856
}
857857

858-
pub fn parse_module<'a>(
858+
pub(crate) fn parse_module<'a>(
859859
cx: &'a llvm::Context,
860860
name: &CStr,
861861
data: &[u8],

compiler/rustc_codegen_llvm/src/back/profiling.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ fn llvm_args_to_string_id(profiler: &SelfProfiler, pass_name: &str, ir_name: &st
1919
EventId::from_label(profiler.alloc_string(components.as_slice()))
2020
}
2121

22-
pub struct LlvmSelfProfiler<'a> {
22+
pub(crate) struct LlvmSelfProfiler<'a> {
2323
profiler: Arc<SelfProfiler>,
2424
stack: Vec<TimingGuard<'a>>,
2525
llvm_pass_event_kind: StringId,
2626
}
2727

2828
impl<'a> LlvmSelfProfiler<'a> {
29-
pub fn new(profiler: Arc<SelfProfiler>) -> Self {
29+
pub(crate) fn new(profiler: Arc<SelfProfiler>) -> Self {
3030
let llvm_pass_event_kind = profiler.alloc_string("LLVM Pass");
3131
Self { profiler, stack: Vec::default(), llvm_pass_event_kind }
3232
}
@@ -41,7 +41,7 @@ impl<'a> LlvmSelfProfiler<'a> {
4141
}
4242
}
4343

44-
pub unsafe extern "C" fn selfprofile_before_pass_callback(
44+
pub(crate) unsafe extern "C" fn selfprofile_before_pass_callback(
4545
llvm_self_profiler: *mut c_void,
4646
pass_name: *const c_char,
4747
ir_name: *const c_char,
@@ -52,7 +52,7 @@ pub unsafe extern "C" fn selfprofile_before_pass_callback(
5252
llvm_self_profiler.before_pass_callback(pass_name, ir_name);
5353
}
5454

55-
pub unsafe extern "C" fn selfprofile_after_pass_callback(llvm_self_profiler: *mut c_void) {
55+
pub(crate) unsafe extern "C" fn selfprofile_after_pass_callback(llvm_self_profiler: *mut c_void) {
5656
let llvm_self_profiler = &mut *(llvm_self_profiler as *mut LlvmSelfProfiler<'_>);
5757
llvm_self_profiler.after_pass_callback();
5858
}

compiler/rustc_codegen_llvm/src/back/write.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ use std::slice;
4747
use std::str;
4848
use std::sync::Arc;
4949

50-
pub fn llvm_err<'a>(dcx: &rustc_errors::DiagCtxt, err: LlvmError<'a>) -> FatalError {
50+
pub(crate) fn llvm_err<'a>(dcx: &rustc_errors::DiagCtxt, err: LlvmError<'a>) -> FatalError {
5151
match llvm::last_error() {
5252
Some(llvm_err) => dcx.emit_almost_fatal(WithLlvmError(err, llvm_err)),
5353
None => dcx.emit_almost_fatal(err),
5454
}
5555
}
5656

57-
pub fn write_output_file<'ll>(
57+
fn write_output_file<'ll>(
5858
dcx: &rustc_errors::DiagCtxt,
5959
target: &'ll llvm::TargetMachine,
6060
pm: &llvm::PassManager<'ll>,
@@ -99,7 +99,7 @@ pub fn write_output_file<'ll>(
9999
}
100100
}
101101

102-
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
102+
pub(crate) fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
103103
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
104104
// Can't use query system here quite yet because this function is invoked before the query
105105
// system/tcx is set up.
@@ -108,7 +108,7 @@ pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine
108108
.unwrap_or_else(|err| llvm_err(sess.dcx(), err).raise())
109109
}
110110

111-
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMachine {
111+
pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMachine {
112112
let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() {
113113
tcx.output_filenames(()).split_dwarf_path(
114114
tcx.sess.split_debuginfo(),
@@ -131,9 +131,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMach
131131
.unwrap_or_else(|err| llvm_err(tcx.dcx(), err).raise())
132132
}
133133

134-
pub fn to_llvm_opt_settings(
135-
cfg: config::OptLevel,
136-
) -> (llvm::CodeGenOptLevel, llvm::CodeGenOptSize) {
134+
fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::CodeGenOptSize) {
137135
use self::config::OptLevel::*;
138136
match cfg {
139137
No => (llvm::CodeGenOptLevel::None, llvm::CodeGenOptSizeNone),
@@ -180,7 +178,7 @@ pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeMod
180178
}
181179
}
182180

183-
pub fn target_machine_factory(
181+
pub(crate) fn target_machine_factory(
184182
sess: &Session,
185183
optlvl: config::OptLevel,
186184
target_features: &[String],
@@ -321,7 +319,7 @@ pub(crate) fn save_temp_bitcode(
321319
}
322320

323321
/// In what context is a dignostic handler being attached to a codegen unit?
324-
pub enum CodegenDiagnosticsStage {
322+
pub(crate) enum CodegenDiagnosticsStage {
325323
/// Prelink optimization stage.
326324
Opt,
327325
/// LTO/ThinLTO postlink optimization stage.
@@ -330,14 +328,14 @@ pub enum CodegenDiagnosticsStage {
330328
Codegen,
331329
}
332330

333-
pub struct DiagnosticHandlers<'a> {
331+
pub(crate) struct DiagnosticHandlers<'a> {
334332
data: *mut (&'a CodegenContext<LlvmCodegenBackend>, &'a DiagCtxt),
335333
llcx: &'a llvm::Context,
336334
old_handler: Option<&'a llvm::DiagnosticHandler>,
337335
}
338336

339337
impl<'a> DiagnosticHandlers<'a> {
340-
pub fn new(
338+
pub(crate) fn new(
341339
cgcx: &'a CodegenContext<LlvmCodegenBackend>,
342340
dcx: &'a DiagCtxt,
343341
llcx: &'a llvm::Context,

compiler/rustc_codegen_llvm/src/base.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_target::spec::SanitizerSet;
3434

3535
use std::time::Instant;
3636

37-
pub struct ValueIter<'ll> {
37+
pub(crate) struct ValueIter<'ll> {
3838
cur: Option<&'ll Value>,
3939
step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>,
4040
}
@@ -51,11 +51,14 @@ impl<'ll> Iterator for ValueIter<'ll> {
5151
}
5252
}
5353

54-
pub fn iter_globals(llmod: &llvm::Module) -> ValueIter<'_> {
54+
pub(crate) fn iter_globals(llmod: &llvm::Module) -> ValueIter<'_> {
5555
unsafe { ValueIter { cur: llvm::LLVMGetFirstGlobal(llmod), step: llvm::LLVMGetNextGlobal } }
5656
}
5757

58-
pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen<ModuleLlvm>, u64) {
58+
pub(crate) fn compile_codegen_unit(
59+
tcx: TyCtxt<'_>,
60+
cgu_name: Symbol,
61+
) -> (ModuleCodegen<ModuleLlvm>, u64) {
5962
let start_time = Instant::now();
6063

6164
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
@@ -142,15 +145,15 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
142145
(module, cost)
143146
}
144147

145-
pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
148+
pub(crate) fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
146149
let Some(sect) = attrs.link_section else { return };
147150
unsafe {
148151
let buf = SmallCStr::new(sect.as_str());
149152
llvm::LLVMSetSection(llval, buf.as_ptr());
150153
}
151154
}
152155

153-
pub fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
156+
pub(crate) fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
154157
match linkage {
155158
Linkage::External => llvm::Linkage::ExternalLinkage,
156159
Linkage::AvailableExternally => llvm::Linkage::AvailableExternallyLinkage,
@@ -166,7 +169,7 @@ pub fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
166169
}
167170
}
168171

169-
pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
172+
pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
170173
match linkage {
171174
Visibility::Default => llvm::Visibility::Default,
172175
Visibility::Hidden => llvm::Visibility::Hidden,

0 commit comments

Comments
 (0)