diff options
| author | bors <bors@rust-lang.org> | 2016-12-01 15:21:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-12-01 15:21:11 +0000 |
| commit | 908dba0c9477b7dd022a236cb1514ddfca9369f2 (patch) | |
| tree | a616d31780537a8a3d6bf2e9fcd027bcf8d7ebcf /src/rustllvm/RustWrapper.cpp | |
| parent | 149e76f12cea86338785050165b65965b1b524a9 (diff) | |
| parent | 85dc08e525622365909cdaae27f4b89179321a92 (diff) | |
| download | rust-908dba0c9477b7dd022a236cb1514ddfca9369f2.tar.gz rust-908dba0c9477b7dd022a236cb1514ddfca9369f2.zip | |
Auto merge of #38048 - rkruppe:llvm-stringref-fixes, r=alexcrichton
[LLVM 4.0] Don't assume llvm::StringRef is null terminated StringRefs have a length and their contents are not usually null-terminated. The solution is to either copy the string data (in `rustc_llvm::diagnostic`) or take the size into account (in LLVMRustPrintPasses). I couldn't trigger a bug caused by this (apparently all the strings returned in practice are actually null-terminated) but this is more correct and more future-proof. cc #37609
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 9f0e38b53ff..818737dfe7c 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -872,7 +872,7 @@ LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) { extern "C" void LLVMRustUnpackOptimizationDiagnostic( LLVMDiagnosticInfoRef di, - const char **pass_name_out, + RustStringRef pass_name_out, LLVMValueRef *function_out, LLVMDebugLocRef *debugloc_out, RustStringRef message_out) @@ -881,15 +881,12 @@ LLVMRustUnpackOptimizationDiagnostic( 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 + raw_rust_string_ostream pass_name_os(pass_name_out); + pass_name_os << opt->getPassName(); *function_out = wrap(&opt->getFunction()); *debugloc_out = wrap(&opt->getDebugLoc()); - raw_rust_string_ostream os(message_out); - os << opt->getMsg(); + raw_rust_string_ostream message_os(message_out); + message_os << opt->getMsg(); } extern "C" void |
