Skip to content

Commit 87920ee

Browse files
committed
Auto merge of rust-lang#132177 - jieyouxu:rollup-3z4oi8c, r=jieyouxu
Rollup of 4 pull requests Successful merges: - rust-lang#132124 (coverage: Consolidate creation of covmap/covfun records) - rust-lang#132167 (Replace some LLVMRust wrappers with calls to the LLVM C API) - rust-lang#132169 (Deny calls to non-`#[const_trait]` methods in MIR constck) - rust-lang#132174 (x86 target features: make pclmulqdq imply sse2) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 80d0d92 + 4867569 commit 87920ee

File tree

96 files changed

+861
-699
lines changed

Some content is hidden

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

96 files changed

+861
-699
lines changed

Diff for: compiler/rustc_codegen_llvm/src/allocator.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,14 @@ pub(crate) unsafe fn codegen(
7777
// __rust_alloc_error_handler_should_panic
7878
let name = OomStrategy::SYMBOL;
7979
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
80-
llvm::LLVMRustSetVisibility(
81-
ll_g,
82-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
83-
);
80+
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
8481
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
8582
let llval = llvm::LLVMConstInt(i8, val as u64, False);
8683
llvm::LLVMSetInitializer(ll_g, llval);
8784

8885
let name = NO_ALLOC_SHIM_IS_UNSTABLE;
8986
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
90-
llvm::LLVMRustSetVisibility(
91-
ll_g,
92-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
93-
);
87+
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
9488
let llval = llvm::LLVMConstInt(i8, 0, False);
9589
llvm::LLVMSetInitializer(ll_g, llval);
9690
}
@@ -134,10 +128,7 @@ fn create_wrapper_function(
134128
None
135129
};
136130

137-
llvm::LLVMRustSetVisibility(
138-
llfn,
139-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
140-
);
131+
llvm::set_visibility(llfn, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
141132

142133
if tcx.sess.must_emit_unwind_tables() {
143134
let uwtable =
@@ -151,7 +142,7 @@ fn create_wrapper_function(
151142
// -> ! DIFlagNoReturn
152143
attributes::apply_to_llfn(callee, llvm::AttributePlace::Function, &[no_return]);
153144
}
154-
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);
145+
llvm::set_visibility(callee, llvm::Visibility::Hidden);
155146

156147
let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, c"entry".as_ptr());
157148

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ unsafe fn embed_bitcode(
10431043

10441044
let section = bitcode_section_name(cgcx);
10451045
llvm::LLVMSetSection(llglobal, section.as_ptr().cast());
1046-
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
1046+
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
10471047
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
10481048

10491049
let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
@@ -1061,7 +1061,7 @@ unsafe fn embed_bitcode(
10611061
c".llvmcmd"
10621062
};
10631063
llvm::LLVMSetSection(llglobal, section.as_ptr());
1064-
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
1064+
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
10651065
} else {
10661066
// We need custom section flags, so emit module-level inline assembly.
10671067
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
@@ -1096,7 +1096,7 @@ fn create_msvc_imps(
10961096
let ptr_ty = Type::ptr_llcx(llcx);
10971097
let globals = base::iter_globals(llmod)
10981098
.filter(|&val| {
1099-
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage
1099+
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
11001100
&& llvm::LLVMIsDeclaration(val) == 0
11011101
})
11021102
.filter_map(|val| {
@@ -1115,7 +1115,7 @@ fn create_msvc_imps(
11151115
for (imp_name, val) in globals {
11161116
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
11171117
llvm::LLVMSetInitializer(imp, val);
1118-
llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage);
1118+
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
11191119
}
11201120
}
11211121

Diff for: compiler/rustc_codegen_llvm/src/callee.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
9595
// whether we are sharing generics or not. The important thing here is
9696
// that the visibility we apply to the declaration is the same one that
9797
// has been applied to the definition (wherever that definition may be).
98-
unsafe {
99-
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);
10098

99+
llvm::set_linkage(llfn, llvm::Linkage::ExternalLinkage);
100+
unsafe {
101101
let is_generic = instance.args.non_erasable_generics().next().is_some();
102102

103103
let is_hidden = if is_generic {
@@ -135,7 +135,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
135135
|| !cx.tcx.is_reachable_non_generic(instance_def_id))
136136
};
137137
if is_hidden {
138-
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
138+
llvm::set_visibility(llfn, llvm::Visibility::Hidden);
139139
}
140140

141141
// MinGW: For backward compatibility we rely on the linker to decide whether it

Diff for: compiler/rustc_codegen_llvm/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
219219
llvm::LLVMSetInitializer(g, sc);
220220
llvm::LLVMSetGlobalConstant(g, True);
221221
llvm::LLVMSetUnnamedAddress(g, llvm::UnnamedAddr::Global);
222-
llvm::LLVMRustSetLinkage(g, llvm::Linkage::InternalLinkage);
223222
}
223+
llvm::set_linkage(g, llvm::Linkage::InternalLinkage);
224224
(s.to_owned(), g)
225225
})
226226
.1;

Diff for: compiler/rustc_codegen_llvm/src/consts.rs

+42-48
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,27 @@ fn check_and_apply_linkage<'ll, 'tcx>(
172172
if let Some(linkage) = attrs.import_linkage {
173173
debug!("get_static: sym={} linkage={:?}", sym, linkage);
174174

175-
unsafe {
176-
// Declare a symbol `foo` with the desired linkage.
177-
let g1 = cx.declare_global(sym, cx.type_i8());
178-
llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage));
179-
180-
// Declare an internal global `extern_with_linkage_foo` which
181-
// is initialized with the address of `foo`. If `foo` is
182-
// discarded during linking (for example, if `foo` has weak
183-
// linkage and there are no definitions), then
184-
// `extern_with_linkage_foo` will instead be initialized to
185-
// zero.
186-
let mut real_name = "_rust_extern_with_linkage_".to_string();
187-
real_name.push_str(sym);
188-
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
189-
cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
190-
span: cx.tcx.def_span(def_id),
191-
symbol_name: sym,
192-
})
193-
});
194-
llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage);
195-
llvm::LLVMSetInitializer(g2, g1);
196-
g2
197-
}
175+
// Declare a symbol `foo` with the desired linkage.
176+
let g1 = cx.declare_global(sym, cx.type_i8());
177+
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));
178+
179+
// Declare an internal global `extern_with_linkage_foo` which
180+
// is initialized with the address of `foo`. If `foo` is
181+
// discarded during linking (for example, if `foo` has weak
182+
// linkage and there are no definitions), then
183+
// `extern_with_linkage_foo` will instead be initialized to
184+
// zero.
185+
let mut real_name = "_rust_extern_with_linkage_".to_string();
186+
real_name.push_str(sym);
187+
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
188+
cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
189+
span: cx.tcx.def_span(def_id),
190+
symbol_name: sym,
191+
})
192+
});
193+
llvm::set_linkage(g2, llvm::Linkage::InternalLinkage);
194+
unsafe { llvm::LLVMSetInitializer(g2, g1) };
195+
g2
198196
} else if cx.tcx.sess.target.arch == "x86"
199197
&& let Some(dllimport) = crate::common::get_dllimport(cx.tcx, def_id, sym)
200198
{
@@ -224,23 +222,21 @@ impl<'ll> CodegenCx<'ll, '_> {
224222
align: Align,
225223
kind: Option<&str>,
226224
) -> &'ll Value {
227-
unsafe {
228-
let gv = match kind {
229-
Some(kind) if !self.tcx.sess.fewer_names() => {
230-
let name = self.generate_local_symbol_name(kind);
231-
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
232-
bug!("symbol `{}` is already defined", name);
233-
});
234-
llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
235-
gv
236-
}
237-
_ => self.define_private_global(self.val_ty(cv)),
238-
};
239-
llvm::LLVMSetInitializer(gv, cv);
240-
set_global_alignment(self, gv, align);
241-
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
242-
gv
243-
}
225+
let gv = match kind {
226+
Some(kind) if !self.tcx.sess.fewer_names() => {
227+
let name = self.generate_local_symbol_name(kind);
228+
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
229+
bug!("symbol `{}` is already defined", name);
230+
});
231+
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
232+
gv
233+
}
234+
_ => self.define_private_global(self.val_ty(cv)),
235+
};
236+
unsafe { llvm::LLVMSetInitializer(gv, cv) };
237+
set_global_alignment(self, gv, align);
238+
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
239+
gv
244240
}
245241

246242
#[instrument(level = "debug", skip(self))]
@@ -292,9 +288,7 @@ impl<'ll> CodegenCx<'ll, '_> {
292288
let g = self.declare_global(sym, llty);
293289

294290
if !self.tcx.is_reachable_non_generic(def_id) {
295-
unsafe {
296-
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
297-
}
291+
llvm::set_visibility(g, llvm::Visibility::Hidden);
298292
}
299293

300294
g
@@ -312,7 +306,7 @@ impl<'ll> CodegenCx<'ll, '_> {
312306
llvm::set_thread_local_mode(g, self.tls_model);
313307
}
314308

315-
let dso_local = unsafe { self.should_assume_dso_local(g, true) };
309+
let dso_local = self.should_assume_dso_local(g, true);
316310
if dso_local {
317311
unsafe {
318312
llvm::LLVMRustSetDSOLocal(g, true);
@@ -401,8 +395,8 @@ impl<'ll> CodegenCx<'ll, '_> {
401395
let name = llvm::get_value_name(g).to_vec();
402396
llvm::set_value_name(g, b"");
403397

404-
let linkage = llvm::LLVMRustGetLinkage(g);
405-
let visibility = llvm::LLVMRustGetVisibility(g);
398+
let linkage = llvm::get_linkage(g);
399+
let visibility = llvm::get_visibility(g);
406400

407401
let new_g = llvm::LLVMRustGetOrInsertGlobal(
408402
self.llmod,
@@ -411,8 +405,8 @@ impl<'ll> CodegenCx<'ll, '_> {
411405
val_llty,
412406
);
413407

414-
llvm::LLVMRustSetLinkage(new_g, linkage);
415-
llvm::LLVMRustSetVisibility(new_g, visibility);
408+
llvm::set_linkage(new_g, linkage);
409+
llvm::set_visibility(new_g, visibility);
416410

417411
// The old global has had its name removed but is returned by
418412
// get_static since it is in the instance cache. Provide an

Diff for: compiler/rustc_codegen_llvm/src/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub(crate) struct CodegenCx<'ll, 'tcx> {
8080

8181
pub isize_ty: &'ll Type,
8282

83+
/// Extra codegen state needed when coverage instrumentation is enabled.
8384
pub coverage_cx: Option<coverageinfo::CrateCoverageContext<'ll, 'tcx>>,
8485
pub dbg_cx: Option<debuginfo::CodegenUnitDebugContext<'ll, 'tcx>>,
8586

@@ -592,11 +593,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
592593
&self.statics_to_rauw
593594
}
594595

596+
/// Extra state that is only available when coverage instrumentation is enabled.
595597
#[inline]
596-
pub(crate) fn coverage_context(
597-
&self,
598-
) -> Option<&coverageinfo::CrateCoverageContext<'ll, 'tcx>> {
599-
self.coverage_cx.as_ref()
598+
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
599+
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
600600
}
601601

602602
pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) {
@@ -605,7 +605,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
605605
unsafe {
606606
let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
607607
llvm::LLVMSetInitializer(g, array);
608-
llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
608+
llvm::set_linkage(g, llvm::Linkage::AppendingLinkage);
609609
llvm::LLVMSetSection(g, c"llvm.metadata".as_ptr());
610610
}
611611
}

0 commit comments

Comments
 (0)