mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Remove a couple of uses of interior mutability around statics
This commit is contained in:
@@ -67,7 +67,7 @@ fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) ->
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "master"), allow(unused_mut))]
|
||||
fn codegen_static(&self, def_id: DefId) {
|
||||
fn codegen_static(&mut self, def_id: DefId) {
|
||||
let attrs = self.tcx.codegen_fn_attrs(def_id);
|
||||
|
||||
let Ok((value, alloc)) = codegen_static_initializer(self, def_id) else {
|
||||
@@ -162,11 +162,11 @@ fn codegen_static(&self, def_id: DefId) {
|
||||
}
|
||||
|
||||
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
|
||||
fn add_used_global(&self, _global: RValue<'gcc>) {
|
||||
fn add_used_global(&mut self, _global: RValue<'gcc>) {
|
||||
// TODO(antoyo)
|
||||
}
|
||||
|
||||
fn add_compiler_used_global(&self, global: RValue<'gcc>) {
|
||||
fn add_compiler_used_global(&mut self, global: RValue<'gcc>) {
|
||||
// NOTE: seems like GCC does not make the distinction between compiler.used and used.
|
||||
self.add_used_global(global);
|
||||
}
|
||||
|
||||
@@ -115,14 +115,11 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm
|
||||
}
|
||||
|
||||
// Create the llvm.used and llvm.compiler.used variables.
|
||||
if !cx.used_statics.borrow().is_empty() {
|
||||
cx.create_used_variable_impl(c"llvm.used", &*cx.used_statics.borrow());
|
||||
if !cx.used_statics.is_empty() {
|
||||
cx.create_used_variable_impl(c"llvm.used", &cx.used_statics);
|
||||
}
|
||||
if !cx.compiler_used_statics.borrow().is_empty() {
|
||||
cx.create_used_variable_impl(
|
||||
c"llvm.compiler.used",
|
||||
&*cx.compiler_used_statics.borrow(),
|
||||
);
|
||||
if !cx.compiler_used_statics.is_empty() {
|
||||
cx.create_used_variable_impl(c"llvm.compiler.used", &cx.compiler_used_statics);
|
||||
}
|
||||
|
||||
// Run replace-all-uses-with for statics that need it. This must
|
||||
|
||||
@@ -411,7 +411,7 @@ fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
|
||||
g
|
||||
}
|
||||
|
||||
fn codegen_static_item(&self, def_id: DefId) {
|
||||
fn codegen_static_item(&mut self, def_id: DefId) {
|
||||
unsafe {
|
||||
assert!(
|
||||
llvm::LLVMGetInitializer(
|
||||
@@ -571,18 +571,18 @@ fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'
|
||||
self.const_pointercast(gv, self.type_ptr())
|
||||
}
|
||||
|
||||
fn codegen_static(&self, def_id: DefId) {
|
||||
fn codegen_static(&mut self, def_id: DefId) {
|
||||
self.codegen_static_item(def_id)
|
||||
}
|
||||
|
||||
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr.
|
||||
fn add_used_global(&self, global: &'ll Value) {
|
||||
self.used_statics.borrow_mut().push(global);
|
||||
fn add_used_global(&mut self, global: &'ll Value) {
|
||||
self.used_statics.push(global);
|
||||
}
|
||||
|
||||
/// Add a global value to a list to be stored in the `llvm.compiler.used` variable,
|
||||
/// an array of ptr.
|
||||
fn add_compiler_used_global(&self, global: &'ll Value) {
|
||||
self.compiler_used_statics.borrow_mut().push(global);
|
||||
fn add_compiler_used_global(&mut self, global: &'ll Value) {
|
||||
self.compiler_used_statics.push(global);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::ffi::{CStr, c_char, c_uint};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str;
|
||||
|
||||
use rustc_abi::{HasDataLayout, Size, TargetDataLayout, VariantIdx};
|
||||
@@ -77,6 +77,13 @@ fn deref(&self) -> &Self::Target {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ll, T: Borrow<SCx<'ll>>> DerefMut for GenericCx<'ll, T> {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type SimpleCx<'ll> = GenericCx<'ll, SCx<'ll>>;
|
||||
|
||||
/// There is one `CodegenCx` per codegen unit. Each one has its own LLVM
|
||||
@@ -110,11 +117,11 @@ pub(crate) struct FullCx<'ll, 'tcx> {
|
||||
|
||||
/// Statics that will be placed in the llvm.used variable
|
||||
/// See <https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable> for details
|
||||
pub used_statics: RefCell<Vec<&'ll Value>>,
|
||||
pub used_statics: Vec<&'ll Value>,
|
||||
|
||||
/// Statics that will be placed in the llvm.compiler.used variable
|
||||
/// See <https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable> for details
|
||||
pub compiler_used_statics: RefCell<Vec<&'ll Value>>,
|
||||
pub compiler_used_statics: Vec<&'ll Value>,
|
||||
|
||||
/// Mapping of non-scalar types to llvm types.
|
||||
pub type_lowering: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'ll Type>>,
|
||||
@@ -606,8 +613,8 @@ pub(crate) fn new(
|
||||
const_str_cache: Default::default(),
|
||||
const_globals: Default::default(),
|
||||
statics_to_rauw: RefCell::new(Vec::new()),
|
||||
used_statics: RefCell::new(Vec::new()),
|
||||
compiler_used_statics: RefCell::new(Vec::new()),
|
||||
used_statics: Vec::new(),
|
||||
compiler_used_statics: Vec::new(),
|
||||
type_lowering: Default::default(),
|
||||
scalar_lltypes: Default::default(),
|
||||
coverage_cx,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
///
|
||||
/// Those sections are then read and understood by LLVM's `llvm-cov` tool,
|
||||
/// which is distributed in the `llvm-tools` rustup component.
|
||||
pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
|
||||
pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
|
||||
let tcx = cx.tcx;
|
||||
|
||||
// Ensure that LLVM is using a version of the coverage mapping format that
|
||||
@@ -62,6 +62,7 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
|
||||
.sorted_by_cached_key(|&instance| tcx.symbol_name(instance).name)
|
||||
.filter_map(|instance| prepare_covfun_record(tcx, instance, true))
|
||||
.collect::<Vec<_>>();
|
||||
drop(instances_used);
|
||||
|
||||
// In a single designated CGU, also prepare covfun records for functions
|
||||
// in this crate that were instrumented for coverage, but are unused.
|
||||
@@ -206,7 +207,7 @@ fn resolve_all(&self, global_file_table: &GlobalFileTable) -> Option<Vec<u32>> {
|
||||
/// Generates the contents of the covmap record for this CGU, which mostly
|
||||
/// consists of a header and a list of filenames. The record is then stored
|
||||
/// as a global variable in the `__llvm_covmap` section.
|
||||
fn generate_covmap_record<'ll>(cx: &CodegenCx<'ll, '_>, version: u32, filenames_buffer: &[u8]) {
|
||||
fn generate_covmap_record<'ll>(cx: &mut CodegenCx<'ll, '_>, version: u32, filenames_buffer: &[u8]) {
|
||||
// A covmap record consists of four target-endian u32 values, followed by
|
||||
// the encoded filenames table. Two of the header fields are unused in
|
||||
// modern versions of the LLVM coverage mapping format, and are always 0.
|
||||
|
||||
@@ -181,7 +181,7 @@ fn fill_region_tables<'tcx>(
|
||||
/// contains the function's coverage mapping data. The record is then stored
|
||||
/// as a global variable in the `__llvm_covfun` section.
|
||||
pub(crate) fn generate_covfun_record<'tcx>(
|
||||
cx: &CodegenCx<'_, 'tcx>,
|
||||
cx: &mut CodegenCx<'_, 'tcx>,
|
||||
global_file_table: &GlobalFileTable,
|
||||
covfun: &CovfunRecord<'tcx>,
|
||||
) {
|
||||
|
||||
@@ -56,7 +56,7 @@ fn try_get_mcdc_condition_bitmap(
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
|
||||
pub(crate) fn coverageinfo_finalize(&self) {
|
||||
pub(crate) fn coverageinfo_finalize(&mut self) {
|
||||
mapgen::finalize(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
pub trait StaticCodegenMethods: BackendTypes {
|
||||
fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value;
|
||||
fn codegen_static(&self, def_id: DefId);
|
||||
fn codegen_static(&mut self, def_id: DefId);
|
||||
|
||||
/// Mark the given global value as "used", to prevent the compiler and linker from potentially
|
||||
/// removing a static variable that may otherwise appear unused.
|
||||
fn add_used_global(&self, global: Self::Value);
|
||||
fn add_used_global(&mut self, global: Self::Value);
|
||||
|
||||
/// Same as add_used_global(), but only prevent the compiler from potentially removing an
|
||||
/// otherwise unused symbol. The linker is still permitted to drop it.
|
||||
@@ -17,7 +17,7 @@ pub trait StaticCodegenMethods: BackendTypes {
|
||||
/// This corresponds to the documented semantics of the `#[used]` attribute, although
|
||||
/// on some targets (non-ELF), we may use `add_used_global` for `#[used]` statics
|
||||
/// instead.
|
||||
fn add_compiler_used_global(&self, global: Self::Value);
|
||||
fn add_compiler_used_global(&mut self, global: Self::Value);
|
||||
}
|
||||
|
||||
pub trait StaticBuilderMethods: BackendTypes {
|
||||
|
||||
Reference in New Issue
Block a user