Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_span::Symbol;
use rustc_target::spec::{RelocModel, TlsModel};

use crate::llvm::ToLlvmBool;

mod abi;
mod allocator;
mod asm;
Expand Down Expand Up @@ -384,7 +386,8 @@ unsafe impl Sync for ModuleLlvm {}
impl ModuleLlvm {
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm {
llmod_raw,
Expand All @@ -396,7 +399,8 @@ impl ModuleLlvm {

fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, tcx.sess.fewer_names().to_llvm_bool());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm {
llmod_raw,
Expand Down Expand Up @@ -427,7 +431,8 @@ impl ModuleLlvm {
dcx: DiagCtxtHandle<'_>,
) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llcx = llvm::LLVMContextCreate();
llvm::LLVMContextSetDiscardValueNames(llcx, cgcx.fewer_names.to_llvm_bool());
let llmod_raw = back::lto::parse_module(llcx, name, buffer, dcx);
let tm = ModuleLlvm::tm_from_cgcx(cgcx, name.to_str().unwrap(), dcx);

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,9 @@ pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) ->

unsafe extern "C" {
// Create and destroy contexts.
pub(crate) fn LLVMContextCreate() -> &'static mut Context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: Seeing &'static mut is always terrifying, but since the existing LLVMRust binding already does the same thing, I guess this isn't making things any worse.

I've been planning some changes of my own to replace these with raw pointers, but I can just as easily do that after merging this PR, so this is fine.

pub(crate) fn LLVMContextDispose(C: &'static mut Context);
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
pub(crate) fn LLVMGetMDKindIDInContext(
C: &Context,
Name: *const c_char,
Expand Down Expand Up @@ -1925,9 +1927,6 @@ unsafe extern "C" {
pub(crate) fn LLVMRustInstallErrorHandlers();
pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();

// Create and destroy contexts.
pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;

// Operations on all values
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
Val: &'a Value,
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ extern "C" void LLVMRustSetLastError(const char *Err) {
LastError = strdup(Err);
}

extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
auto ctx = new LLVMContext();
ctx->setDiscardValueNames(shouldDiscardNames);
return wrap(ctx);
}

extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
const char *Target) {
#if LLVM_VERSION_GE(21, 0)
Expand Down
Loading