Support LLVM 4.0 in OptimizationDiagnostic FFI

- getMsg() changed to return std::string by-value. Fix: copy the data to a rust String during unpacking.
- getPassName() changed to return StringRef
This commit is contained in:
Robin Kruppe 2016-11-24 17:33:47 +01:00
parent 29abe6f9e8
commit 730400167a
4 changed files with 27 additions and 19 deletions

View File

@ -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 pass_name = ptr::null();
let mut function = ptr::null_mut();
let mut debug_loc = ptr::null_mut();
let mut opt = OptimizationDiagnostic {
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")
}
}
}

View File

@ -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,

View File

@ -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));
}
}

View File

@ -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