[llvm] Fix potential Out-of-order Evaluation in DebugInfo (PR #124385)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 19:02:17 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Elvin Wang (NaiveWang)

<details>
<summary>Changes</summary>

In DebugTypeInfoRemoval, DenseMap Replacements's assignment's rvalue is a recursive function that may access Replacements itself. Since C++17 such an "right to left" order cannot get guaranteed. This change is to separate 1 line into 2, avoid such a case.

---
Full diff: https://github.com/llvm/llvm-project/pull/124385.diff


1 Files Affected:

- (modified) llvm/lib/IR/DebugInfo.cpp (+2-1) 


``````````diff
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 4ce518009bd3ea..f4080ce532ef38 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -798,7 +798,8 @@ class DebugTypeInfoRemoval {
 
       return getReplacementMDNode(N);
     };
-    Replacements[N] = doRemap(N);
+    auto value = doRemap(N);
+    Replacements[N] = value;
   }
 
   /// Do the remapping traversal.

``````````

</details>


https://github.com/llvm/llvm-project/pull/124385


More information about the llvm-commits mailing list