[PATCH] D145369: Emit const globals with constexpr destructor as constant LLVM values
Hans Wennborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 6 04:53:07 PST 2023
hans created this revision.
hans added reviewers: rsmith, ilya-biryukov.
Herald added a project: All.
hans requested review of this revision.
Herald added a project: clang.
This follows 2b4fa53 which made Clang not emit destructor calls for such objects. However, they would still not get emitted as constants since CodeGenModule::isTypeConstant() only checked whether the destructor was trivial, not if it's constexpr.
Fixes Issue #61212
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145369
Files:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/const-init-cxx2a.cpp
Index: clang/test/CodeGenCXX/const-init-cxx2a.cpp
===================================================================
--- clang/test/CodeGenCXX/const-init-cxx2a.cpp
+++ clang/test/CodeGenCXX/const-init-cxx2a.cpp
@@ -11,10 +11,10 @@
constexpr ~B() { n *= 5; }
int n = 123;
};
-// CHECK: @b ={{.*}} global {{.*}} i32 123
+// CHECK: @b ={{.*}} constant {{.*}} i32 123
extern constexpr B b = B();
-// CHECK: @_ZL1c = internal global {{.*}} i32 123
+// CHECK: @_ZL1c = internal constant {{.*}} i32 123
const B c;
int use_c() { return c.n; }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4320,7 +4320,8 @@
if (const CXXRecordDecl *Record
= Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
return ExcludeCtor && !Record->hasMutableFields() &&
- Record->hasTrivialDestructor();
+ (Record->hasTrivialDestructor() ||
+ Record->hasConstexprDestructor());
}
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145369.502593.patch
Type: text/x-patch
Size: 1095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230306/2200590c/attachment.bin>
More information about the cfe-commits
mailing list