Skip to content

Commit

Permalink
[CodeGen] Stabilize C2/D2 to C1/D1 replacement order
Browse files Browse the repository at this point in the history
The conversion iterates over CodeGenModule::Replacements (a StringMap)
and replaces C2/D2 and moves C1/D1 (
commit 0196a1d 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.
  • Loading branch information
MaskRay committed Jul 22, 2023
1 parent 2b0f5df commit e6a9b06
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion clang/test/CodeGenCXX/destructors.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit e6a9b06

Please sign in to comment.