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())) {
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())) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits