Skip to content

Commit 78cddc0

Browse files
committed
Add deny(unreachable_pub) to rustc_codegen_llvm.
1 parent fae0fc1 commit 78cddc0

31 files changed

+206
-184
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
66
use rustc_codegen_ssa::traits::*;
77
use rustc_codegen_ssa::MemFlags;
88
use rustc_middle::ty::layout::LayoutOf;
9-
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
9+
pub(crate) use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
1010
use rustc_middle::ty::Ty;
1111
use rustc_middle::{bug, ty};
1212
use rustc_session::config;
13-
pub use rustc_target::abi::call::*;
13+
pub(crate) use rustc_target::abi::call::*;
1414
use rustc_target::abi::{self, HasDataLayout, Int, Size};
15-
pub use rustc_target::spec::abi::Abi;
15+
pub(crate) use rustc_target::spec::abi::Abi;
1616
use rustc_target::spec::SanitizerSet;
1717
use smallvec::SmallVec;
1818

@@ -25,7 +25,7 @@ use crate::type_of::LayoutLlvmExt;
2525
use crate::value::Value;
2626
use crate::{attributes, llvm_util};
2727

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

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

@@ -171,7 +171,7 @@ impl LlvmType for CastTarget {
171171
}
172172
}
173173

174-
pub trait ArgAbiExt<'ll, 'tcx> {
174+
trait ArgAbiExt<'ll, 'tcx> {
175175
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
176176
fn store(
177177
&self,
@@ -307,7 +307,7 @@ impl<'ll, 'tcx> ArgAbiMethods<'tcx> for Builder<'_, 'll, 'tcx> {
307307
}
308308
}
309309

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

compiler/rustc_codegen_llvm/src/attributes.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Set and unset common attributes on LLVM values.
22
3-
pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
3+
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
44
use rustc_codegen_ssa::traits::*;
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry};
@@ -17,13 +17,13 @@ use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace
1717
use crate::value::Value;
1818
use crate::{attributes, llvm_util};
1919

20-
pub fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
20+
pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
2121
if !attrs.is_empty() {
2222
llvm::AddFunctionAttributes(llfn, idx, attrs);
2323
}
2424
}
2525

26-
pub fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
26+
pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
2727
if !attrs.is_empty() {
2828
llvm::AddCallSiteAttributes(callsite, idx, attrs);
2929
}
@@ -80,7 +80,7 @@ fn patchable_function_entry_attrs<'ll>(
8080

8181
/// Get LLVM sanitize attributes.
8282
#[inline]
83-
pub fn sanitize_attrs<'ll>(
83+
pub(crate) fn sanitize_attrs<'ll>(
8484
cx: &CodegenCx<'ll, '_>,
8585
no_sanitize: SanitizerSet,
8686
) -> SmallVec<[&'ll Attribute; 4]> {
@@ -120,15 +120,15 @@ pub fn sanitize_attrs<'ll>(
120120

121121
/// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function.
122122
#[inline]
123-
pub fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>) -> &Attribute {
123+
pub(crate) fn uwtable_attr(llcx: &llvm::Context, use_sync_unwind: Option<bool>) -> &Attribute {
124124
// NOTE: We should determine if we even need async unwind tables, as they
125125
// take have more overhead and if we can use sync unwind tables we
126126
// probably should.
127127
let async_unwind = !use_sync_unwind.unwrap_or(false);
128128
llvm::CreateUWTableAttr(llcx, async_unwind)
129129
}
130130

131-
pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
131+
pub(crate) fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
132132
let mut fp = cx.sess().target.frame_pointer;
133133
let opts = &cx.sess().opts;
134134
// "mcount" function relies on stack pointer.
@@ -280,19 +280,19 @@ fn backchain_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
280280
if found_positive { Some(llvm::CreateAttrString(cx.llcx, "backchain")) } else { None }
281281
}
282282

283-
pub fn target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Attribute {
283+
pub(crate) fn target_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Attribute {
284284
let target_cpu = llvm_util::target_cpu(cx.tcx.sess);
285285
llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu)
286286
}
287287

288-
pub fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
288+
pub(crate) fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
289289
llvm_util::tune_cpu(cx.tcx.sess)
290290
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu))
291291
}
292292

293293
/// Get the `NonLazyBind` LLVM attribute,
294294
/// if the codegen options allow skipping the PLT.
295-
pub fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
295+
pub(crate) fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
296296
// Don't generate calls through PLT if it's not necessary
297297
if !cx.sess().needs_plt() {
298298
Some(AttributeKind::NonLazyBind.create_attr(cx.llcx))
@@ -327,7 +327,7 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
327327
/// Helper for `FnAbi::apply_attrs_llfn`:
328328
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
329329
/// attributes.
330-
pub fn llfn_attrs_from_instance<'ll, 'tcx>(
330+
pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
331331
cx: &CodegenCx<'ll, 'tcx>,
332332
llfn: &'ll Value,
333333
instance: ty::Instance<'tcx>,

compiler/rustc_codegen_llvm/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> ArchiveBuilder for LlvmArchiveBuilder<'a> {
102102
}
103103
}
104104

105-
pub struct LlvmArchiveBuilderBuilder;
105+
pub(crate) struct LlvmArchiveBuilderBuilder;
106106

107107
impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
108108
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
@@ -33,9 +33,9 @@ use crate::{LlvmCodegenBackend, ModuleLlvm};
3333

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

38-
pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
38+
fn crate_type_allows_lto(crate_type: CrateType) -> bool {
3939
match crate_type {
4040
CrateType::Executable
4141
| CrateType::Dylib
@@ -710,7 +710,7 @@ impl Drop for ThinBuffer {
710710
}
711711
}
712712

713-
pub unsafe fn optimize_thin_module(
713+
pub(crate) unsafe fn optimize_thin_module(
714714
thin_module: ThinModule<LlvmCodegenBackend>,
715715
cgcx: &CodegenContext<LlvmCodegenBackend>,
716716
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
@@ -806,7 +806,7 @@ pub unsafe fn optimize_thin_module(
806806

807807
/// Maps LLVM module identifiers to their corresponding LLVM LTO cache keys
808808
#[derive(Debug, Default)]
809-
pub struct ThinLTOKeysMap {
809+
struct ThinLTOKeysMap {
810810
// key = llvm name of importing module, value = LLVM cache key
811811
keys: BTreeMap<String, String>,
812812
}
@@ -863,7 +863,7 @@ fn module_name_to_str(c_str: &CStr) -> &str {
863863
})
864864
}
865865

866-
pub fn parse_module<'a>(
866+
pub(crate) fn parse_module<'a>(
867867
cx: &'a llvm::Context,
868868
name: &CStr,
869869
data: &[u8],

compiler/rustc_codegen_llvm/src/back/profiling.rs

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

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

3030
impl<'a> LlvmSelfProfiler<'a> {
31-
pub fn new(profiler: Arc<SelfProfiler>) -> Self {
31+
pub(crate) fn new(profiler: Arc<SelfProfiler>) -> Self {
3232
let llvm_pass_event_kind = profiler.alloc_string("LLVM Pass");
3333
Self { profiler, stack: Vec::default(), llvm_pass_event_kind }
3434
}
@@ -43,7 +43,7 @@ impl<'a> LlvmSelfProfiler<'a> {
4343
}
4444
}
4545

46-
pub unsafe extern "C" fn selfprofile_before_pass_callback(
46+
pub(crate) unsafe extern "C" fn selfprofile_before_pass_callback(
4747
llvm_self_profiler: *mut c_void,
4848
pass_name: *const c_char,
4949
ir_name: *const c_char,
@@ -56,7 +56,7 @@ pub unsafe extern "C" fn selfprofile_before_pass_callback(
5656
}
5757
}
5858

59-
pub unsafe extern "C" fn selfprofile_after_pass_callback(llvm_self_profiler: *mut c_void) {
59+
pub(crate) unsafe extern "C" fn selfprofile_after_pass_callback(llvm_self_profiler: *mut c_void) {
6060
let llvm_self_profiler = unsafe { &mut *(llvm_self_profiler as *mut LlvmSelfProfiler<'_>) };
6161
llvm_self_profiler.after_pass_callback();
6262
}

compiler/rustc_codegen_llvm/src/back/write.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ use crate::llvm::{self, DiagnosticInfo, PassManager};
4343
use crate::type_::Type;
4444
use crate::{base, common, llvm_util, LlvmCodegenBackend, ModuleLlvm};
4545

46-
pub fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> FatalError {
46+
pub(crate) fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> FatalError {
4747
match llvm::last_error() {
4848
Some(llvm_err) => dcx.emit_almost_fatal(WithLlvmError(err, llvm_err)),
4949
None => dcx.emit_almost_fatal(err),
5050
}
5151
}
5252

53-
pub fn write_output_file<'ll>(
53+
fn write_output_file<'ll>(
5454
dcx: DiagCtxtHandle<'_>,
5555
target: &'ll llvm::TargetMachine,
5656
pm: &llvm::PassManager<'ll>,
@@ -95,7 +95,7 @@ pub fn write_output_file<'ll>(
9595
}
9696
}
9797

98-
pub fn create_informational_target_machine(
98+
pub(crate) fn create_informational_target_machine(
9999
sess: &Session,
100100
only_base_features: bool,
101101
) -> OwnedTargetMachine {
@@ -107,7 +107,7 @@ pub fn create_informational_target_machine(
107107
.unwrap_or_else(|err| llvm_err(sess.dcx(), err).raise())
108108
}
109109

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

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

182-
pub fn target_machine_factory(
180+
pub(crate) fn target_machine_factory(
183181
sess: &Session,
184182
optlvl: config::OptLevel,
185183
target_features: &[String],
@@ -320,7 +318,7 @@ pub(crate) fn save_temp_bitcode(
320318
}
321319

322320
/// In what context is a dignostic handler being attached to a codegen unit?
323-
pub enum CodegenDiagnosticsStage {
321+
pub(crate) enum CodegenDiagnosticsStage {
324322
/// Prelink optimization stage.
325323
Opt,
326324
/// LTO/ThinLTO postlink optimization stage.
@@ -329,14 +327,14 @@ pub enum CodegenDiagnosticsStage {
329327
Codegen,
330328
}
331329

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

338336
impl<'a> DiagnosticHandlers<'a> {
339-
pub fn new(
337+
pub(crate) fn new(
340338
cgcx: &'a CodegenContext<LlvmCodegenBackend>,
341339
dcx: DiagCtxtHandle<'a>,
342340
llcx: &'a llvm::Context,

compiler/rustc_codegen_llvm/src/base.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::context::CodegenCx;
3232
use crate::value::Value;
3333
use crate::{attributes, llvm};
3434

35-
pub struct ValueIter<'ll> {
35+
pub(crate) struct ValueIter<'ll> {
3636
cur: Option<&'ll Value>,
3737
step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>,
3838
}
@@ -49,11 +49,14 @@ impl<'ll> Iterator for ValueIter<'ll> {
4949
}
5050
}
5151

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

56-
pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen<ModuleLlvm>, u64) {
56+
pub(crate) fn compile_codegen_unit(
57+
tcx: TyCtxt<'_>,
58+
cgu_name: Symbol,
59+
) -> (ModuleCodegen<ModuleLlvm>, u64) {
5760
let start_time = Instant::now();
5861

5962
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
@@ -140,15 +143,15 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
140143
(module, cost)
141144
}
142145

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

151-
pub fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
154+
pub(crate) fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
152155
match linkage {
153156
Linkage::External => llvm::Linkage::ExternalLinkage,
154157
Linkage::AvailableExternally => llvm::Linkage::AvailableExternallyLinkage,
@@ -164,7 +167,7 @@ pub fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
164167
}
165168
}
166169

167-
pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
170+
pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
168171
match linkage {
169172
Visibility::Default => llvm::Visibility::Default,
170173
Visibility::Hidden => llvm::Visibility::Hidden,

0 commit comments

Comments
 (0)