Skip to content

Commit ef19bd1

Browse files
committed
Auto merge of #43387 - TimNN:rustllvm50, r=alexcrichton
Update Rust LLVM bindings for LLVM 5.0 This is the initial set of changes to update the rust llvm bindings for 5.0. The llvm commits necessitating these changes are linked from the tracking issue, #43370.
2 parents c35a0c1 + 38e40ce commit ef19bd1

File tree

7 files changed

+194
-105
lines changed

7 files changed

+194
-105
lines changed

src/librustc_llvm/diagnostic.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use libc::c_uint;
1717
use std::ptr;
1818

1919
use {DiagnosticInfoRef, TwineRef, ValueRef};
20-
use ffi::DebugLocRef;
2120

2221
#[derive(Copy, Clone)]
2322
pub enum OptimizationDiagnosticKind {
@@ -47,7 +46,9 @@ pub struct OptimizationDiagnostic {
4746
pub kind: OptimizationDiagnosticKind,
4847
pub pass_name: String,
4948
pub function: ValueRef,
50-
pub debug_loc: DebugLocRef,
49+
pub line: c_uint,
50+
pub column: c_uint,
51+
pub filename: String,
5152
pub message: String,
5253
}
5354

@@ -56,24 +57,37 @@ impl OptimizationDiagnostic {
5657
di: DiagnosticInfoRef)
5758
-> OptimizationDiagnostic {
5859
let mut function = ptr::null_mut();
59-
let mut debug_loc = ptr::null_mut();
60+
let mut line = 0;
61+
let mut column = 0;
6062

6163
let mut message = None;
64+
let mut filename = None;
6265
let pass_name = super::build_string(|pass_name|
6366
message = super::build_string(|message|
64-
super::LLVMRustUnpackOptimizationDiagnostic(di,
65-
pass_name,
66-
&mut function,
67-
&mut debug_loc,
68-
message)
67+
filename = super::build_string(|filename|
68+
super::LLVMRustUnpackOptimizationDiagnostic(di,
69+
pass_name,
70+
&mut function,
71+
&mut line,
72+
&mut column,
73+
filename,
74+
message)
75+
)
6976
)
7077
);
7178

79+
let mut filename = filename.unwrap_or(String::new());
80+
if filename.is_empty() {
81+
filename.push_str("<unknown file>");
82+
}
83+
7284
OptimizationDiagnostic {
7385
kind: kind,
7486
pass_name: pass_name.expect("got a non-UTF8 pass name from LLVM"),
7587
function: function,
76-
debug_loc: debug_loc,
88+
line: line,
89+
column: column,
90+
filename: filename,
7791
message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM")
7892
}
7993
}

src/librustc_llvm/ffi.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,9 @@ extern "C" {
16331633
pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
16341634
pass_name_out: RustStringRef,
16351635
function_out: *mut ValueRef,
1636-
debugloc_out: *mut DebugLocRef,
1636+
loc_line_out: *mut c_uint,
1637+
loc_column_out: *mut c_uint,
1638+
loc_filename_out: RustStringRef,
16371639
message_out: RustStringRef);
16381640
pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
16391641
cookie_out: *mut c_uint,

src/librustc_trans/back/write.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, OutputTypes, Pas
1616
AllPasses, Sanitizer};
1717
use rustc::session::Session;
1818
use llvm;
19-
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
19+
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef};
2020
use llvm::SMDiagnosticRef;
2121
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
2222
use rustc::hir::def_id::CrateNum;
@@ -307,7 +307,6 @@ pub struct CodegenContext<'a> {
307307
}
308308

309309
struct HandlerFreeVars<'a> {
310-
llcx: ContextRef,
311310
cgcx: &'a CodegenContext<'a>,
312311
}
313312

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

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

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

347346
if enabled {
348-
let loc = llvm::debug_loc_to_string(llcx, opt.debug_loc);
349-
cgcx.handler.note_without_error(&format!("optimization {} for {} at {}: {}",
347+
cgcx.handler.note_without_error(&format!("optimization {} for {} at {}:{}:{}: {}",
350348
opt.kind.describe(),
351349
opt.pass_name,
352-
if loc.is_empty() { "[unknown]" } else { &*loc },
350+
opt.filename,
351+
opt.line,
352+
opt.column,
353353
opt.message));
354354
}
355355
}
@@ -370,9 +370,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
370370
let llcx = mllvm.llcx;
371371
let tm = config.tm;
372372

373-
// llcx doesn't outlive this function, so we can put this on the stack.
374373
let fv = HandlerFreeVars {
375-
llcx: llcx,
376374
cgcx: cgcx,
377375
};
378376
let fv = &fv as *const HandlerFreeVars as *mut c_void;

src/rustllvm/ArchiveWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/Object/Archive.h"
1414
#include "llvm/Object/ArchiveWriter.h"
15+
#include "llvm/Support/Path.h"
1516

1617
using namespace llvm;
1718
using namespace llvm::object;
@@ -256,6 +257,9 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
256257
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
257258
return LLVMRustResult::Failure;
258259
}
260+
#if LLVM_VERSION_GE(5, 0)
261+
MOrErr->MemberName = sys::path::filename(MOrErr->MemberName);
262+
#endif
259263
Members.push_back(std::move(*MOrErr));
260264
#elif LLVM_VERSION_EQ(3, 8)
261265
Members.push_back(NewArchiveIterator(Member->Filename));

0 commit comments

Comments
 (0)