about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-02 06:03:16 +0000
committerbors <bors@rust-lang.org>2023-08-02 06:03:16 +0000
commitf1280576ec204f1cf9060e6c3918c22a2f185ee5 (patch)
tree535cb16a7a96d1046a48966e8a5a0812b0a63ac3 /compiler/rustc_llvm/llvm-wrapper
parent320cd7d55111dc8acc4b2f4e6d4c51c4eba60d3e (diff)
parent2d01258c122f2218ca79bfd75ae6cd2354e12cb1 (diff)
downloadrust-f1280576ec204f1cf9060e6c3918c22a2f185ee5.tar.gz
rust-f1280576ec204f1cf9060e6c3918c22a2f185ee5.zip
Auto merge of #3003 - rust-lang:rustup-2023-08-02, r=RalfJung
Automatic sync from rustc
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index f509e2911f3..8ef39a6c866 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -1892,12 +1892,19 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
           LlvmRemarkStreamer(std::move(LlvmRemarkStreamer)) {}
 
     virtual bool handleDiagnostics(const DiagnosticInfo &DI) override {
-      if (this->LlvmRemarkStreamer) {
-        if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
-          if (OptDiagBase->isEnabled()) {
+      // If this diagnostic is one of the optimization remark kinds, we can check if it's enabled
+      // before emitting it. This can avoid many short-lived allocations when unpacking the
+      // diagnostic and converting its various C++ strings into rust strings.
+      // FIXME: some diagnostic infos still allocate before we get here, and avoiding that would be
+      // good in the future. That will require changing a few call sites in LLVM.
+      if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
+        if (OptDiagBase->isEnabled()) {
+          if (this->LlvmRemarkStreamer) {
             this->LlvmRemarkStreamer->emit(*OptDiagBase);
             return true;
           }
+        } else {
+          return true;
         }
       }
       if (DiagnosticHandlerCallback) {