[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission
Yuanfang Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 16 12:18:41 PDT 2022
ychen updated this revision to Diff 453094.
ychen added a comment.
- use correct lexing order for non-deferred constructors.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127233/new/
https://reviews.llvm.org/D127233
Files:
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/static-init-inline-variable.cpp
Index: clang/test/CodeGenCXX/static-init-inline-variable.cpp
===================================================================
--- clang/test/CodeGenCXX/static-init-inline-variable.cpp
+++ clang/test/CodeGenCXX/static-init-inline-variable.cpp
@@ -1,7 +1,14 @@
// RUN: %clang_cc1 -std=c++17 -S -emit-llvm -disable-llvm-passes -o - %s -triple x86_64-linux-gnu | FileCheck %s
+struct A {
+ int x;
+ A(int x) : x(x) {}
+ ~A() {}
+};
+
inline int a = 1;
-inline int b = a + 1;
-inline int c = b + 1;
+inline A b(a + 1);
+inline int c = b.x + 1;
int d = c;
-// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @b }, { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.1, ptr @c }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
+
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @b }, { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @c }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
\ No newline at end of file
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===================================================================
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -578,7 +578,9 @@
// COMDAT group associated with the global, so the initializers get folded
// too.
I = DelayedCXXInitPosition.find(D);
- unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+ // CXXGlobalInits.size() is the lex order for non-deferred emission.
+ unsigned LexOrder =
+ I == DelayedCXXInitPosition.end() ? CXXGlobalInits.size() : I->second;
AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);
if (COMDATKey && (getTriple().isOSBinFormatELF() ||
getTarget().getCXXABI().isMicrosoft())) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127233.453094.patch
Type: text/x-patch
Size: 1977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220816/6981f2f0/attachment.bin>
More information about the cfe-commits
mailing list