Skip to content

Commit ebc0373

Browse files
authored
Auto merge of #37982 - rkruppe:llvm-diagnostic-fwdcompat, r=alexcrichton
[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
2 parents c78cc52 + 7304001 commit ebc0373

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/librustc_llvm/diagnostic.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,32 @@ pub struct OptimizationDiagnostic {
4848
pub pass_name: *const c_char,
4949
pub function: ValueRef,
5050
pub debug_loc: DebugLocRef,
51-
pub message: TwineRef,
51+
pub message: String,
5252
}
5353

5454
impl OptimizationDiagnostic {
5555
unsafe fn unpack(kind: OptimizationDiagnosticKind,
5656
di: DiagnosticInfoRef)
5757
-> OptimizationDiagnostic {
58-
59-
let mut opt = OptimizationDiagnostic {
58+
let mut pass_name = ptr::null();
59+
let mut function = ptr::null_mut();
60+
let mut debug_loc = ptr::null_mut();
61+
62+
let message = super::build_string(|message|
63+
super::LLVMRustUnpackOptimizationDiagnostic(di,
64+
&mut pass_name,
65+
&mut function,
66+
&mut debug_loc,
67+
message)
68+
);
69+
70+
OptimizationDiagnostic {
6071
kind: kind,
61-
pass_name: ptr::null(),
62-
function: ptr::null_mut(),
63-
debug_loc: ptr::null_mut(),
64-
message: ptr::null_mut(),
65-
};
66-
67-
super::LLVMRustUnpackOptimizationDiagnostic(di,
68-
&mut opt.pass_name,
69-
&mut opt.function,
70-
&mut opt.debug_loc,
71-
&mut opt.message);
72-
73-
opt
72+
pass_name: pass_name,
73+
function: function,
74+
debug_loc: debug_loc,
75+
message: message.expect("got a non-UTF8 OptimizationDiagnostic message from LLVM")
76+
}
7477
}
7578
}
7679

src/librustc_llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ extern "C" {
18231823
pass_name_out: *mut *const c_char,
18241824
function_out: *mut ValueRef,
18251825
debugloc_out: *mut DebugLocRef,
1826-
message_out: *mut TwineRef);
1826+
message_out: RustStringRef);
18271827
pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
18281828
cookie_out: *mut c_uint,
18291829
message_out: *mut TwineRef,

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ unsafe extern "C" fn diagnostic_handler(info: DiagnosticInfoRef, user: *mut c_vo
417417
opt.kind.describe(),
418418
pass_name,
419419
if loc.is_empty() { "[unknown]" } else { &*loc },
420-
llvm::twine_to_string(opt.message)));
420+
opt.message));
421421
}
422422
}
423423

src/rustllvm/RustWrapper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -871,16 +871,21 @@ LLVMRustUnpackOptimizationDiagnostic(
871871
const char **pass_name_out,
872872
LLVMValueRef *function_out,
873873
LLVMDebugLocRef *debugloc_out,
874-
LLVMTwineRef *message_out)
874+
RustStringRef message_out)
875875
{
876876
// Undefined to call this not on an optimization diagnostic!
877877
llvm::DiagnosticInfoOptimizationBase *opt
878878
= static_cast<llvm::DiagnosticInfoOptimizationBase*>(unwrap(di));
879879

880+
#if LLVM_VERSION_GE(4, 0)
881+
*pass_name_out = opt->getPassName().data();
882+
#else
880883
*pass_name_out = opt->getPassName();
884+
#endif
881885
*function_out = wrap(&opt->getFunction());
882886
*debugloc_out = wrap(&opt->getDebugLoc());
883-
*message_out = wrap(&opt->getMsg());
887+
raw_rust_string_ostream os(message_out);
888+
os << opt->getMsg();
884889
}
885890

886891
extern "C" void

0 commit comments

Comments
 (0)