Skip to content

Commit

Permalink
Auto merge of #37982 - rkruppe:llvm-diagnostic-fwdcompat, r=alexcrichton
Browse files Browse the repository at this point in the history
[LLVM 4.0] OptimizationDiagnostic FFI forward compatibility

- getMsg() changed to return std::string by-value. Fix: copy the data to a rust String during unpacking.
- getPassName() changed to return StringRef

cc #37609
  • Loading branch information
bors authored Nov 25, 2016
2 parents c78cc52 + 7304001 commit ebc0373
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
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

0 comments on commit ebc0373

Please sign in to comment.