[clang] 1002079 - [clang][Interp] Call invalid destructors

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 25 22:31:14 PDT 2023


Author: Timm Bäder
Date: 2023-07-26T07:19:02+02:00
New Revision: 10020791b18f344dc480b60712f6f3a5d63e86a2

URL: https://github.com/llvm/llvm-project/commit/10020791b18f344dc480b60712f6f3a5d63e86a2
DIFF: https://github.com/llvm/llvm-project/commit/10020791b18f344dc480b60712f6f3a5d63e86a2.diff

LOG: [clang][Interp] Call invalid destructors

We need to call them like any other function, so we can generate proper
diagnostics.

Differential Revision: https://reviews.llvm.org/D150040

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/records.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index c7c87d966cbe7f..d700a3e9be72bc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2158,8 +2158,7 @@ bool ByteCodeExprGen<Emitter>::emitRecordDestruction(const Descriptor *Desc) {
   // Now emit the destructor and recurse into base classes.
   if (const CXXDestructorDecl *Dtor = R->getDestructor();
       Dtor && !Dtor->isTrivial()) {
-    const Function *DtorFunc = getFunction(Dtor);
-    if (DtorFunc && DtorFunc->isConstexpr()) {
+    if (const Function *DtorFunc = getFunction(Dtor)) {
       assert(DtorFunc->hasThisPointer());
       assert(DtorFunc->getNumParams() == 1);
       if (!this->emitDupPtr(SourceInfo{}))

diff  --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index fcdf75cfa9502b..d315e31a13e525 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -566,6 +566,25 @@ namespace Destructors {
     return i;
   }
   static_assert(test() == 1);
+
+  struct S {
+    constexpr S() {}
+    constexpr ~S() { // expected-error {{never produces a constant expression}} \
+                     // ref-error {{never produces a constant expression}}
+      int i = 1 / 0; // expected-warning {{division by zero}} \
+                     // expected-note {{division by zero}} \
+                     // ref-warning {{division by zero}} \
+                     // ref-note 2{{division by zero}}
+    }
+  };
+  constexpr int testS() {
+    S{}; // ref-note {{in call to 'S{}.~S()'}}
+    return 1;
+              // FIXME: ^ Wrong line
+  }
+  static_assert(testS() == 1); // expected-error {{not an integral constant expression}} \
+                               // ref-error {{not an integral constant expression}} \
+                               // ref-note {{in call to 'testS()'}}
 }
 
 


        


More information about the cfe-commits mailing list