From 9b12e06da755ea145312312cebb4977f5bc217fa Mon Sep 17 00:00:00 2001 From: Elvin Wang Date: Fri, 24 Jan 2025 18:59:51 -0800 Subject: [PATCH 1/2] Fix potential Out-of-order Evaluation in DebugInfo 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. --- llvm/lib/IR/DebugInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 4ce518009bd3e..f4080ce532ef3 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. From 71e0dc314adf752008bcc9581638cc1c17e135cb Mon Sep 17 00:00:00 2001 From: Elvin Wang Date: Mon, 27 Jan 2025 16:26:57 -0800 Subject: [PATCH 2/2] Update DebugInfo.cpp --- llvm/lib/IR/DebugInfo.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index f4080ce532ef3..89415a1ecd16c 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -798,6 +798,9 @@ class DebugTypeInfoRemoval { return getReplacementMDNode(N); }; + + // Intentionally separate rvalue and lvalue that may access the same memory + // location to guarantee the evaluation order. auto value = doRemap(N); Replacements[N] = value; }