[clang] e6a9b06 - [CodeGen] Stabilize C2/D2 to C1/D1 replacement order

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 22 15:29:42 PDT 2023


Author: Fangrui Song
Date: 2023-07-22T15:29:38-07:00
New Revision: e6a9b06dc0b974eb16186a71099b88a631afdf52

URL: https://github.com/llvm/llvm-project/commit/e6a9b06dc0b974eb16186a71099b88a631afdf52
DIFF: https://github.com/llvm/llvm-project/commit/e6a9b06dc0b974eb16186a71099b88a631afdf52.diff

LOG: [CodeGen] Stabilize C2/D2 to C1/D1 replacement order

The conversion iterates over CodeGenModule::Replacements (a StringMap)
and replaces C2/D2 and moves C1/D1 (
commit 0196a1d98f8a206259a4b5ce93c21807243af92f in 2013, to make the
output look nicer). The iteration order is not guaranteed to be
deterministic, and may cause destructors.cpp to exhibit different
function orders. Use a MapVector instead.

While here, fix an IWYU issue by adding an explicit include, though
MapVector is already used in CodeGenModule.h.

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/lib/CodeGen/CodeGenModule.h
    clang/test/CodeGenCXX/destructors.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index bb5d1800b30c8a..e2beb77d196fa4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -497,7 +497,7 @@ void CodeGenModule::addReplacement(StringRef Name, llvm::Constant *C) {
 
 void CodeGenModule::applyReplacements() {
   for (auto &I : Replacements) {
-    StringRef MangledName = I.first();
+    StringRef MangledName = I.first;
     llvm::Constant *Replacement = I.second;
     llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
     if (!Entry)

diff  --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 4903f096381e7a..05cb217e2bee4e 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -30,6 +30,7 @@
 #include "clang/Basic/XRayLists.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
@@ -378,8 +379,7 @@ class CodeGenModule : public CodeGenTypeCache {
   /// multiversion function resolvers and ifuncs are defined and emitted.
   std::vector<GlobalDecl> MultiVersionFuncs;
 
-  typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
-  ReplacementsTy Replacements;
+  llvm::MapVector<StringRef, llvm::TrackingVH<llvm::Constant>> Replacements;
 
   /// List of global values to be replaced with something else. Used when we
   /// want to replace a GlobalValue but can't identify it by its mangled name

diff  --git a/clang/test/CodeGenCXX/destructors.cpp b/clang/test/CodeGenCXX/destructors.cpp
index 9fc605175f6d01..99c82ec76989ac 100644
--- a/clang/test/CodeGenCXX/destructors.cpp
+++ b/clang/test/CodeGenCXX/destructors.cpp
@@ -12,7 +12,6 @@
 // RUN: FileCheck --check-prefixes=CHECK5,CHECK5v11 --input-file=%t2 %s
 // RUN: FileCheck --check-prefix=CHECK6    --input-file=%t2 %s
 // REQUIRES: asserts
-// UNSUPPORTED: reverse_iteration
 
 struct A {
   int a;


        


More information about the cfe-commits mailing list