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

Update Rust LLVM bindings for LLVM 5.0 #43387

Merged
merged 9 commits into from
Jul 23, 2017
Merged
32 changes: 23 additions & 9 deletions src/librustc_llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use libc::c_uint;
use std::ptr;

use {DiagnosticInfoRef, TwineRef, ValueRef};
use ffi::DebugLocRef;

#[derive(Copy, Clone)]
pub enum OptimizationDiagnosticKind {
Expand Down Expand Up @@ -47,7 +46,9 @@ pub struct OptimizationDiagnostic {
pub kind: OptimizationDiagnosticKind,
pub pass_name: String,
pub function: ValueRef,
pub debug_loc: DebugLocRef,
pub line: c_uint,
pub column: c_uint,
pub filename: String,
pub message: String,
}

Expand All @@ -56,24 +57,37 @@ impl OptimizationDiagnostic {
di: DiagnosticInfoRef)
-> OptimizationDiagnostic {
let mut function = ptr::null_mut();
let mut debug_loc = ptr::null_mut();
let mut line = 0;
let mut column = 0;

let mut message = None;
let mut filename = None;
let pass_name = super::build_string(|pass_name|
message = super::build_string(|message|
super::LLVMRustUnpackOptimizationDiagnostic(di,
pass_name,
&mut function,
&mut debug_loc,
message)
filename = super::build_string(|filename|
super::LLVMRustUnpackOptimizationDiagnostic(di,
pass_name,
&mut function,
&mut line,
&mut column,
filename,
message)
)
)
);

let mut filename = filename.unwrap_or(String::new());
if filename.is_empty() {
filename.push_str("<unknown file>");
}

OptimizationDiagnostic {
kind: kind,
pass_name: pass_name.expect("got a non-UTF8 pass name from LLVM"),
function: function,
debug_loc: debug_loc,
line: line,
column: column,
filename: filename,
message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM")
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,9 @@ extern "C" {
pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
pass_name_out: RustStringRef,
function_out: *mut ValueRef,
debugloc_out: *mut DebugLocRef,
loc_line_out: *mut c_uint,
loc_column_out: *mut c_uint,
loc_filename_out: RustStringRef,
message_out: RustStringRef);
pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
cookie_out: *mut c_uint,
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, OutputTypes, Pas
AllPasses, Sanitizer};
use rustc::session::Session;
use llvm;
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef};
use llvm::SMDiagnosticRef;
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
use rustc::hir::def_id::CrateNum;
Expand Down Expand Up @@ -307,7 +307,6 @@ pub struct CodegenContext<'a> {
}

struct HandlerFreeVars<'a> {
llcx: ContextRef,
cgcx: &'a CodegenContext<'a>,
}

Expand All @@ -329,7 +328,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
}

unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_void) {
let HandlerFreeVars { llcx, cgcx } = *(user as *const HandlerFreeVars);
let HandlerFreeVars { cgcx, .. } = *(user as *const HandlerFreeVars);

match llvm::diagnostic::Diagnostic::unpack(info) {
llvm::diagnostic::InlineAsm(inline) => {
Expand All @@ -345,11 +344,12 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo
};

if enabled {
let loc = llvm::debug_loc_to_string(llcx, opt.debug_loc);
cgcx.handler.note_without_error(&format!("optimization {} for {} at {}: {}",
cgcx.handler.note_without_error(&format!("optimization {} for {} at {}:{}:{}: {}",
opt.kind.describe(),
opt.pass_name,
if loc.is_empty() { "[unknown]" } else { &*loc },
opt.filename,
opt.line,
opt.column,
opt.message));
}
}
Expand All @@ -370,9 +370,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
let llcx = mllvm.llcx;
let tm = config.tm;

// llcx doesn't outlive this function, so we can put this on the stack.
let fv = HandlerFreeVars {
llcx: llcx,
cgcx: cgcx,
};
let fv = &fv as *const HandlerFreeVars as *mut c_void;
Expand Down
4 changes: 4 additions & 0 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Support/Path.h"

using namespace llvm;
using namespace llvm::object;
Expand Down Expand Up @@ -256,6 +257,9 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
return LLVMRustResult::Failure;
}
#if LLVM_VERSION_GE(5, 0)
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
#endif
Members.push_back(std::move(*MOrErr));
#elif LLVM_VERSION_EQ(3, 8)
Members.push_back(NewArchiveIterator(Member->Filename));
Expand Down
Loading