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;


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

Reply via email to