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

[LLVM 4.0] OptimizationDiagnostic FFI forward compatibility #37982

Merged
merged 1 commit into from
Nov 25, 2016
Merged
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
35 changes: 19 additions & 16 deletions src/librustc_llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,32 @@ pub struct OptimizationDiagnostic {
pub pass_name: *const c_char,
pub function: ValueRef,
pub debug_loc: DebugLocRef,
pub message: TwineRef,
pub message: String,
}

impl OptimizationDiagnostic {
unsafe fn unpack(kind: OptimizationDiagnosticKind,
di: DiagnosticInfoRef)
-> OptimizationDiagnostic {

let mut opt = OptimizationDiagnostic {
let mut pass_name = ptr::null();
let mut function = ptr::null_mut();
let mut debug_loc = ptr::null_mut();

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

OptimizationDiagnostic {
kind: kind,
pass_name: ptr::null(),
function: ptr::null_mut(),
debug_loc: ptr::null_mut(),
message: ptr::null_mut(),
};

super::LLVMRustUnpackOptimizationDiagnostic(di,
&mut opt.pass_name,
&mut opt.function,
&mut opt.debug_loc,
&mut opt.message);

opt
pass_name: pass_name,
function: function,
debug_loc: debug_loc,
message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ extern "C" {
pass_name_out: *mut *const c_char,
function_out: *mut ValueRef,
debugloc_out: *mut DebugLocRef,
message_out: *mut TwineRef);
message_out: RustStringRef);
pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
cookie_out: *mut c_uint,
message_out: *mut TwineRef,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo
opt.kind.describe(),
pass_name,
if loc.is_empty() { "[unknown]" } else { &*loc },
llvm::twine_to_string(opt.message)));
opt.message));
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,16 +871,21 @@ LLVMRustUnpackOptimizationDiagnostic(
const char **pass_name_out,
LLVMValueRef *function_out,
LLVMDebugLocRef *debugloc_out,
LLVMTwineRef *message_out)
RustStringRef message_out)
{
// Undefined to call this not on an optimization diagnostic!
llvm::DiagnosticInfoOptimizationBase *opt
= static_cast<llvm::DiagnosticInfoOptimizationBase*>(unwrap(di));

#if LLVM_VERSION_GE(4, 0)
*pass_name_out = opt->getPassName().data();
#else
*pass_name_out = opt->getPassName();
#endif
*function_out = wrap(&opt->getFunction());
*debugloc_out = wrap(&opt->getDebugLoc());
*message_out = wrap(&opt->getMsg());
raw_rust_string_ostream os(message_out);
os << opt->getMsg();
}

extern "C" void
Expand Down