Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #136654

Closed
wants to merge 101 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
dfd76c1
disallow `repr()` on invalid items
folkertdev Dec 5, 2024
a4bb0d4
fix issue 132391
folkertdev Dec 5, 2024
a7adb82
Move `format_push_string` and `format_collect` to pedantic
smoelius Dec 29, 2024
65b95a2
fix escaping problem in `write_literal` and `print_literal` lint
lapla-cogito Jan 12, 2025
87f7e21
Address review comments
smoelius Jan 14, 2025
bbd58d1
Do not trigger `[size_of_in_element_count]` for `u8`
samueltardieu Jan 16, 2025
5bd989a
Update version for unneeded_struct_pattern
alex-semenyuk Jan 19, 2025
7aae4f4
auto-fix for redundant_else lint
lapla-cogito Jan 3, 2025
f0b99b2
`needless_option_take`: add autofix
samueltardieu Jan 20, 2025
5be8b78
Remove an unsafe closure invariant by inlining the closure wrapper in…
oli-obk Jan 14, 2025
0a374b0
Add a safe wrapper for `WriteBitcodeToFile`
oli-obk Jan 14, 2025
0a8da9b
Document some safety constraints and use more safe wrappers
oli-obk Jan 14, 2025
e485cc5
Simplify slice indexing in next trait solver
yotamofek Jan 25, 2025
13be95a
new `manual_option_as_slice` lint
llogiq Dec 29, 2024
885278b
Stabilize `HashMap::get_many_mut` as `HashMap::get_disjoint_mut`
Urgau Jan 27, 2025
6b7b547
Adjust compiler for `HashMap::get_many_mut` stabilization
Urgau Jan 27, 2025
9da9ddb
Merge commit '51d49c1ae2785b24ef18a46ef233fc1d91844666' into clippy-s…
flip1995 Jan 28, 2025
9ede32f
`needless_option_take`: add autofix (#14042)
llogiq Jan 28, 2025
abb3e8e
Make item self/non-self bound naming less whack
compiler-errors Jan 22, 2025
d7874f4
Refactor FnKind variant to hold &Fn
celinval Jan 28, 2025
6a209cd
Fix escaping problem in `write_literal` and `print_literal` lint sugg…
Centri3 Jan 28, 2025
e02c885
Move `format_push_string` and `format_collect` to pedantic (#13894)
Centri3 Jan 28, 2025
0baa100
rustc_hir: replace `is_empty()`+indexing with `first()`
yotamofek Jan 28, 2025
3802225
rustc_hir: use box patterns to flatten some nested pattern matches
yotamofek Jan 28, 2025
1d4a419
rustc_hir: don't open-code `Iterator::eq`
yotamofek Jan 28, 2025
8aba730
rustc_hir: fix typo in comment
yotamofek Jan 28, 2025
6c1df36
rustc_hir: flatten nested `if`s
yotamofek Jan 28, 2025
056fe96
rustc_hir: remove some uneeded refs and derefs
yotamofek Jan 28, 2025
e84c8b8
Rollup merge of #135902 - compiler-errors:item-non-self-bound-in-new-…
fmease Jan 29, 2025
a4eff9d
Rollup merge of #136164 - celinval:chores-fnkind, r=oli-obk
fmease Jan 29, 2025
7eefa76
Eliminate PatKind::Path
oli-obk Dec 12, 2024
84fb6b1
Add new lint `return_and_then`
aaron-ang Jan 26, 2025
78d6b2e
Do not remove semicolon if it changes the block type
samueltardieu Jan 29, 2025
e4505fb
Include generic arguments when suggesting a closure η-reduction
samueltardieu Jan 29, 2025
88a00a8
autofix for `redundant_else` lint (#13936)
blyxyas Jan 30, 2025
ad05bc0
Include generic arguments when suggesting a closure η-reduction (#14105)
llogiq Jan 30, 2025
f8be518
Move mutex_integer to restriction and improve mutex_{integer,atomic} …
taiki-e Jan 30, 2025
8db9ecf
New lint: `precedence_bits`, with recent additions to `precedence`
samueltardieu Jan 30, 2025
7399338
introduce `ty::Value`
Jan 27, 2025
33bb8af
Fix expand/collapse all on site, make highlightjs lazier
Alexendoo Jan 19, 2025
d49b1ff
Implement --perf flag to lintcheck for benchmarking
blyxyas Jan 30, 2025
fc00cdc
Actually make --perf imply -j=1, review comments
blyxyas Jan 30, 2025
f51e18d
feat: new lint for `and_then` when returning Option or Result (#14051)
Centri3 Jan 30, 2025
5aa8bc1
`sliced_string_as_bytes`: fix typo in lint description
samueltardieu Jan 30, 2025
398a5c2
New lint: `precedence_bits`, with recent additions to `precedence` (#…
llogiq Jan 30, 2025
e188c7d
`sliced_string_as_bytes`: fix typo in lint description (#14117)
Centri3 Jan 30, 2025
d79f862
Do not remove semicolon if it changes the block type (#14103)
dswij Jan 31, 2025
27454db
Insert null checks for pointer dereferences when debug assertions are…
1c3t3a Dec 17, 2024
48ae7ec
Adress review comments
blyxyas Jan 31, 2025
9c8fe30
Auto merge of #134424 - 1c3t3a:null-checks, r=saethlin
bors Jan 31, 2025
62c68e1
Implement MIR, CTFE, and codegen for unsafe binders
compiler-errors Jan 31, 2025
a9434c0
Enforce unsafe binders must be Copy (for now)
compiler-errors Jan 31, 2025
64fcb00
Rename `tcx.ensure()` to `tcx.ensure_ok()`
Zalathar Jan 30, 2025
7848488
Use a better message for `toplevel_ref_arg` lint
samueltardieu Feb 1, 2025
7e5cfbe
Use a better message for `toplevel_ref_arg` lint (#14132)
Manishearth Feb 1, 2025
984cc68
Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obk
matthiaskrgr Feb 1, 2025
c607f78
Fix expand/collapse all on site, make highlightjs lazier (#14038)
blyxyas Feb 1, 2025
3155dab
add autofix for `cmp_null`
lapla-cogito Jan 31, 2025
b8d0b16
autofix for `cmp_null` (#14122)
Alexendoo Feb 1, 2025
d30f045
Convert two `rustc_middle::lint` functions to `Span` methods.
nnethercote Feb 2, 2025
56b5d11
Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obk
matthiaskrgr Feb 2, 2025
af18dce
remove "Known problems" of `verbose_bit_mask`
lapla-cogito Feb 2, 2025
0d3fd98
remove "Known problems" of `verbose_bit_mask` (#14137)
llogiq Feb 2, 2025
6d1482c
Implement --perf flag to lintcheck for benchmarking (#14116)
Alexendoo Feb 2, 2025
abdee77
Some cleanups around EarlyDiagCtxt
bjorn3 Feb 2, 2025
f8d702b
Rollup merge of #136422 - nnethercote:convert-lint-functions, r=Norat…
matthiaskrgr Feb 2, 2025
1a8e9b9
Rollup merge of #136445 - bjorn3:diag_ctxt_cleanup, r=oli-obk
matthiaskrgr Feb 2, 2025
3d6e090
add `SLICE_FILL` to msrv
lapla-cogito Jan 27, 2025
e82b1f4
add `manual_slice_fill` lint
lapla-cogito Jan 27, 2025
07ede9c
ignore `manual_slice_fill` in other test files
lapla-cogito Jan 30, 2025
2c51951
add `manual_slice_fill` lint (#14082)
llogiq Feb 3, 2025
c1e4249
Use a different hir type for patterns in pattern types than we use in…
oli-obk Jan 7, 2025
1112801
Contracts core intrinsics.
pnkfelix Dec 2, 2024
0a8331f
Express contracts as part of function header and lower it to the cont…
celinval Jan 9, 2025
c5218d5
new `manual_option_as_slice` lint (#13901)
blyxyas Feb 3, 2025
75e3a2e
Move mutex_integer to restriction and improve mutex_{integer,atomic} …
Jarcho Feb 4, 2025
270e52f
fix: manual_unwrap_or_default
profetia Feb 5, 2025
4c11087
Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk
fmease Feb 5, 2025
e6d9641
fix: `manual_unwrap_or_default` suggests falsely when condition type …
llogiq Feb 5, 2025
e27495c
Couple of changes to run rustc in miri
bjorn3 Feb 5, 2025
390286d
Update version for unneeded_struct_pattern (#14031)
Alexendoo Feb 5, 2025
c718ae8
Add Nursery and Deprecated lints section at Book
alex-semenyuk Dec 26, 2024
f09701a
Do not trigger `[size_of_in_element_count]` for `u8` (#14011)
blyxyas Feb 5, 2025
694b245
Fix docs for `#[clippy::format_args]`
nyurik Feb 6, 2025
ee1c15e
Add Nursery and Deprecated groups section at Book (#13926)
flip1995 Feb 6, 2025
660d861
Fix docs for `#[clippy::format_args]` (#14161)
flip1995 Feb 6, 2025
f549562
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Feb 6, 2025
9f31768
Bump nightly version -> 2025-02-06
flip1995 Feb 6, 2025
3e3715c
Rustup (#14163)
flip1995 Feb 6, 2025
daa82a1
Merge commit '3e3715c31236bff56f1c63a1de2c7bbdfcfb0923' into clippy-s…
flip1995 Feb 6, 2025
9a833de
Construct DiagCtxt a bit earlier in build_session
bjorn3 Feb 5, 2025
8a0adec
Avoid manually producing FatalError in a couple of places
bjorn3 Feb 5, 2025
b9b2c3a
Stop passing the same resource multiple times when building ParseSess
bjorn3 Feb 5, 2025
c4f768f
Rollup merge of #133925 - folkertdev:improve-repr-warnings, r=compile…
matthiaskrgr Feb 6, 2025
2724684
Rollup merge of #135549 - oli-obk:push-tmxtpnrloyqu, r=compiler-errors
matthiaskrgr Feb 6, 2025
1e60a70
Rollup merge of #136069 - yotamofek:next-solver-slice, r=compiler-errors
matthiaskrgr Feb 6, 2025
6df1002
Rollup merge of #136152 - Urgau:stabilize-map_many_mut, r=joshtriplett
matthiaskrgr Feb 6, 2025
9315bdc
Rollup merge of #136219 - yotamofek:pr/hir-cleanup, r=compiler-errors
matthiaskrgr Feb 6, 2025
53923c7
Rollup merge of #136580 - bjorn3:miri_fixes, r=lqd
matthiaskrgr Feb 6, 2025
1d7505a
Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors
matthiaskrgr Feb 6, 2025
bace62d
Rollup merge of #136645 - flip1995:clippy-subtree-update, r=Manishearth
matthiaskrgr Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ pub(crate) unsafe fn codegen(
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
let llval = llvm::LLVMConstInt(i8, val as u64, False);
llvm::LLVMSetInitializer(ll_g, llval);
llvm::set_initializer(ll_g, llval);

let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_c_char_ptr(), name.len(), i8);
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);
llvm::set_initializer(ll_g, llval);
}

if tcx.sess.opts.debuginfo != DebugInfo::None {
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_codegen_ssa::back::archive::{
use rustc_session::Session;

use crate::llvm::archive_ro::{ArchiveRO, Child};
use crate::llvm::{self, ArchiveKind};
use crate::llvm::{self, ArchiveKind, last_error};

/// Helper for adding many files to an archive.
#[must_use = "must call build() to finish building the archive"]
Expand Down Expand Up @@ -169,6 +169,8 @@ impl<'a> LlvmArchiveBuilder<'a> {
.unwrap_or_else(|kind| self.sess.dcx().emit_fatal(UnknownArchiveKind { kind }));

let mut additions = mem::take(&mut self.additions);
// Values in the `members` list below will contain pointers to the strings allocated here.
// So they need to get dropped after all elements of `members` get freed.
let mut strings = Vec::new();
let mut members = Vec::new();

Expand Down Expand Up @@ -229,12 +231,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
self.sess.target.arch == "arm64ec",
);
let ret = if r.into_result().is_err() {
let err = llvm::LLVMRustGetLastError();
let msg = if err.is_null() {
"failed to write archive".into()
} else {
String::from_utf8_lossy(CStr::from_ptr(err).to_bytes())
};
let msg = last_error().unwrap_or_else(|| "failed to write archive".into());
Err(io::Error::new(io::ErrorKind::Other, msg))
} else {
Ok(!members.is_empty())
Expand Down
212 changes: 88 additions & 124 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::errors::{
WithLlvmError, WriteBytecode,
};
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
use crate::llvm::{self, DiagnosticInfo, PassManager};
use crate::llvm::{self, DiagnosticInfo};
use crate::type_::Type;
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};

Expand All @@ -54,7 +54,7 @@ pub(crate) fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> Fatal
fn write_output_file<'ll>(
dcx: DiagCtxtHandle<'_>,
target: &'ll llvm::TargetMachine,
pm: &llvm::PassManager<'ll>,
no_builtins: bool,
m: &'ll llvm::Module,
output: &Path,
dwo_output: Option<&Path>,
Expand All @@ -63,39 +63,42 @@ fn write_output_file<'ll>(
verify_llvm_ir: bool,
) -> Result<(), FatalError> {
debug!("write_output_file output={:?} dwo_output={:?}", output, dwo_output);
unsafe {
let output_c = path_to_c_string(output);
let dwo_output_c;
let dwo_output_ptr = if let Some(dwo_output) = dwo_output {
dwo_output_c = path_to_c_string(dwo_output);
dwo_output_c.as_ptr()
} else {
std::ptr::null()
};
let result = llvm::LLVMRustWriteOutputFile(
let output_c = path_to_c_string(output);
let dwo_output_c;
let dwo_output_ptr = if let Some(dwo_output) = dwo_output {
dwo_output_c = path_to_c_string(dwo_output);
dwo_output_c.as_ptr()
} else {
std::ptr::null()
};
let result = unsafe {
let pm = llvm::LLVMCreatePassManager();
llvm::LLVMAddAnalysisPasses(target, pm);
llvm::LLVMRustAddLibraryInfo(pm, m, no_builtins);
llvm::LLVMRustWriteOutputFile(
target,
pm,
m,
output_c.as_ptr(),
dwo_output_ptr,
file_type,
verify_llvm_ir,
);
)
};

// Record artifact sizes for self-profiling
if result == llvm::LLVMRustResult::Success {
let artifact_kind = match file_type {
llvm::FileType::ObjectFile => "object_file",
llvm::FileType::AssemblyFile => "assembly_file",
};
record_artifact_size(self_profiler_ref, artifact_kind, output);
if let Some(dwo_file) = dwo_output {
record_artifact_size(self_profiler_ref, "dwo_file", dwo_file);
}
// Record artifact sizes for self-profiling
if result == llvm::LLVMRustResult::Success {
let artifact_kind = match file_type {
llvm::FileType::ObjectFile => "object_file",
llvm::FileType::AssemblyFile => "assembly_file",
};
record_artifact_size(self_profiler_ref, artifact_kind, output);
if let Some(dwo_file) = dwo_output {
record_artifact_size(self_profiler_ref, "dwo_file", dwo_file);
}

result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteOutput { path: output }))
}

result.into_result().map_err(|()| llvm_err(dcx, LlvmError::WriteOutput { path: output }))
}

pub(crate) fn create_informational_target_machine(
Expand Down Expand Up @@ -325,13 +328,17 @@ pub(crate) fn save_temp_bitcode(
if !cgcx.save_temps {
return;
}
let ext = format!("{name}.bc");
let cgu = Some(&module.name[..]);
let path = cgcx.output_filenames.temp_path_ext(&ext, cgu);
write_bitcode_to_file(module, &path)
}

fn write_bitcode_to_file(module: &ModuleCodegen<ModuleLlvm>, path: &Path) {
unsafe {
let ext = format!("{name}.bc");
let cgu = Some(&module.name[..]);
let path = cgcx.output_filenames.temp_path_ext(&ext, cgu);
let cstr = path_to_c_string(&path);
let path = path_to_c_string(&path);
let llmod = module.module_llvm.llmod();
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
llvm::LLVMWriteBitcodeToFile(llmod, path.as_ptr());
}
}

Expand Down Expand Up @@ -661,7 +668,6 @@ pub(crate) unsafe fn optimize(
) -> Result<(), FatalError> {
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &*module.name);

let llmod = module.module_llvm.llmod();
let llcx = &*module.module_llvm.llcx;
let _handlers = DiagnosticHandlers::new(cgcx, dcx, llcx, module, CodegenDiagnosticsStage::Opt);

Expand All @@ -670,8 +676,7 @@ pub(crate) unsafe fn optimize(

if config.emit_no_opt_bc {
let out = cgcx.output_filenames.temp_path_ext("no-opt.bc", module_name);
let out = path_to_c_string(&out);
unsafe { llvm::LLVMWriteBitcodeToFile(llmod, out.as_ptr()) };
write_bitcode_to_file(module, &out)
}

// FIXME(ZuseZ4): support SanitizeHWAddress and prevent illegal/unsupported opts
Expand Down Expand Up @@ -744,31 +749,6 @@ pub(crate) unsafe fn codegen(
create_msvc_imps(cgcx, llcx, llmod);
}

// A codegen-specific pass manager is used to generate object
// files for an LLVM module.
//
// Apparently each of these pass managers is a one-shot kind of
// thing, so we create a new one for each type of output. The
// pass manager passed to the closure should be ensured to not
// escape the closure itself, and the manager should only be
// used once.
unsafe fn with_codegen<'ll, F, R>(
tm: &'ll llvm::TargetMachine,
llmod: &'ll llvm::Module,
no_builtins: bool,
f: F,
) -> R
where
F: FnOnce(&'ll mut PassManager<'ll>) -> R,
{
unsafe {
let cpm = llvm::LLVMCreatePassManager();
llvm::LLVMAddAnalysisPasses(tm, cpm);
llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins);
f(cpm)
}
}

// Note that if object files are just LLVM bitcode we write bitcode,
// copy it to the .o file, and delete the bitcode if it wasn't
// otherwise requested.
Expand Down Expand Up @@ -887,21 +867,17 @@ pub(crate) unsafe fn codegen(
} else {
llmod
};
unsafe {
with_codegen(tm, llmod, config.no_builtins, |cpm| {
write_output_file(
dcx,
tm,
cpm,
llmod,
&path,
None,
llvm::FileType::AssemblyFile,
&cgcx.prof,
config.verify_llvm_ir,
)
})?;
}
write_output_file(
dcx,
tm,
config.no_builtins,
llmod,
&path,
None,
llvm::FileType::AssemblyFile,
&cgcx.prof,
config.verify_llvm_ir,
)?;
}

match config.emit_obj {
Expand All @@ -925,21 +901,17 @@ pub(crate) unsafe fn codegen(
(_, SplitDwarfKind::Split) => Some(dwo_out.as_path()),
};

unsafe {
with_codegen(tm, llmod, config.no_builtins, |cpm| {
write_output_file(
dcx,
tm,
cpm,
llmod,
&obj_out,
dwo_out,
llvm::FileType::ObjectFile,
&cgcx.prof,
config.verify_llvm_ir,
)
})?;
}
write_output_file(
dcx,
tm,
config.no_builtins,
llmod,
&obj_out,
dwo_out,
llvm::FileType::ObjectFile,
&cgcx.prof,
config.verify_llvm_ir,
)?;
}

EmitObj::Bitcode => {
Expand Down Expand Up @@ -1066,24 +1038,18 @@ unsafe fn embed_bitcode(
{
// We don't need custom section flags, create LLVM globals.
let llconst = common::bytes_in_context(llcx, bitcode);
let llglobal = llvm::LLVMAddGlobal(
llmod,
common::val_ty(llconst),
c"rustc.embedded.module".as_ptr(),
);
llvm::LLVMSetInitializer(llglobal, llconst);
let llglobal =
llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.module");
llvm::set_initializer(llglobal, llconst);

llvm::set_section(llglobal, bitcode_section_name(cgcx));
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);

let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
let llglobal = llvm::LLVMAddGlobal(
llmod,
common::val_ty(llconst),
c"rustc.embedded.cmdline".as_ptr(),
);
llvm::LLVMSetInitializer(llglobal, llconst);
let llglobal =
llvm::add_global(llmod, common::val_ty(llconst), c"rustc.embedded.cmdline");
llvm::set_initializer(llglobal, llconst);
let section = if cgcx.target_is_like_osx {
c"__LLVM,__cmdline"
} else if cgcx.target_is_like_aix {
Expand Down Expand Up @@ -1123,31 +1089,29 @@ fn create_msvc_imps(
// underscores added in front).
let prefix = if cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" };

unsafe {
let ptr_ty = Type::ptr_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
&& llvm::LLVMIsDeclaration(val) == 0
})
.filter_map(|val| {
// Exclude some symbols that we know are not Rust symbols.
let name = llvm::get_value_name(val);
if ignored(name) { None } else { Some((val, name)) }
})
.map(move |(val, name)| {
let mut imp_name = prefix.as_bytes().to_vec();
imp_name.extend(name);
let imp_name = CString::new(imp_name).unwrap();
(imp_name, val)
})
.collect::<Vec<_>>();
let ptr_ty = Type::ptr_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage && llvm::is_declaration(val)
})
.filter_map(|val| {
// Exclude some symbols that we know are not Rust symbols.
let name = llvm::get_value_name(val);
if ignored(name) { None } else { Some((val, name)) }
})
.map(move |(val, name)| {
let mut imp_name = prefix.as_bytes().to_vec();
imp_name.extend(name);
let imp_name = CString::new(imp_name).unwrap();
(imp_name, val)
})
.collect::<Vec<_>>();

for (imp_name, val) in globals {
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
llvm::LLVMSetInitializer(imp, val);
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
}
for (imp_name, val) in globals {
let imp = llvm::add_global(llmod, ptr_ty, &imp_name);

llvm::set_initializer(imp, val);
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
}

// Use this function to exclude certain symbols from `__imp` generation.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let g = self.define_global(&sym, self.val_ty(sc)).unwrap_or_else(|| {
bug!("symbol `{}` is already defined", sym);
});
llvm::set_initializer(g, sc);
unsafe {
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetUnnamedAddress(g, llvm::UnnamedAddr::Global);
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
})
});
llvm::set_linkage(g2, llvm::Linkage::InternalLinkage);
unsafe { llvm::LLVMSetInitializer(g2, g1) };
llvm::set_initializer(g2, g1);
g2
} else if cx.tcx.sess.target.arch == "x86"
&& common::is_mingw_gnu_toolchain(&cx.tcx.sess.target)
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<'ll> CodegenCx<'ll, '_> {
}
_ => self.define_private_global(self.val_ty(cv)),
};
unsafe { llvm::LLVMSetInitializer(gv, cv) };
llvm::set_initializer(gv, cv);
set_global_alignment(self, gv, align);
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
gv
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'ll> CodegenCx<'ll, '_> {
new_g
};
set_global_alignment(self, g, alloc.align);
llvm::LLVMSetInitializer(g, v);
llvm::set_initializer(g, v);

if self.should_assume_dso_local(g, true) {
llvm::LLVMRustSetDSOLocal(g, true);
Expand Down
Loading
Loading