aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.h
diff options
context:
space:
mode:
authorYuanfang Chen <yuanfang.chen@sony.com>2022-08-22 15:59:51 -0700
committerYuanfang Chen <yuanfang.chen@sony.com>2022-08-22 16:00:14 -0700
commitf9969a3d28e738e9427e371aac06d71269220123 (patch)
treeabdf817d95c1f979c0d8fb9f0b3e9f5b3c46258f /clang/lib/CodeGen/CodeGenModule.h
parentc21dfa9e4931a0a339813a5d384fc2eb0deee235 (diff)
downloadllvm-f9969a3d28e738e9427e371aac06d71269220123.zip
llvm-f9969a3d28e738e9427e371aac06d71269220123.tar.gz
llvm-f9969a3d28e738e9427e371aac06d71269220123.tar.bz2
[CodeGen] Sort llvm.global_ctors by lexing order before emission
Fixes https://github.com/llvm/llvm-project/issues/55804 The lexing order is already bookkept in DelayedCXXInitPosition but we were not using it based on the wrong assumption that inline variable is unordered. This patch fixes it by ordering entries in llvm.global_ctors by orders in DelayedCXXInitPosition. for llvm.global_ctors entries without a lexing order, ordering them by the insertion order. (This *mostly* orders the template instantiation in https://reviews.llvm.org/D126341 intuitively, minus one tweak for which I'll submit a separate patch.) Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D127233
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.h')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 14c791f..f57afdc 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -282,12 +282,15 @@ class CodeGenModule : public CodeGenTypeCache {
public:
struct Structor {
- Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
- Structor(int Priority, llvm::Constant *Initializer,
+ Structor()
+ : Priority(0), LexOrder(~0u), Initializer(nullptr),
+ AssociatedData(nullptr) {}
+ Structor(int Priority, unsigned LexOrder, llvm::Constant *Initializer,
llvm::Constant *AssociatedData)
- : Priority(Priority), Initializer(Initializer),
+ : Priority(Priority), LexOrder(LexOrder), Initializer(Initializer),
AssociatedData(AssociatedData) {}
int Priority;
+ unsigned LexOrder;
llvm::Constant *Initializer;
llvm::Constant *AssociatedData;
};
@@ -1602,6 +1605,7 @@ private:
// FIXME: Hardcoding priority here is gross.
void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
+ unsigned LexOrder = ~0U,
llvm::Constant *AssociatedData = nullptr);
void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
bool IsDtorAttrFunc = false);