[clang] 9d0616c - [clang][bytecode] Ignore explicit calls to trivial dtors (#112841)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 18 00:45:06 PDT 2024


Author: Timm Baeder
Date: 2024-10-18T09:45:02+02:00
New Revision: 9d0616ce52fc2a75c8e4808adec41d5189f4240c

URL: https://github.com/llvm/llvm-project/commit/9d0616ce52fc2a75c8e4808adec41d5189f4240c
DIFF: https://github.com/llvm/llvm-project/commit/9d0616ce52fc2a75c8e4808adec41d5189f4240c.diff

LOG: [clang][bytecode] Ignore explicit calls to trivial dtors (#112841)

This is what the current interpreter does as well.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/placement-new.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8ca63bf64aa0ef..a71c0dcc9381e8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4535,6 +4535,10 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
       return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_delete);
     }
   }
+  // Explicit calls to trivial destructors
+  if (const auto *DD = dyn_cast_if_present<CXXDestructorDecl>(FuncDecl);
+      DD && DD->isTrivial())
+    return true;
 
   QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
   std::optional<PrimType> T = classify(ReturnType);

diff  --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp
index 8e6d802e93295c..5673b5cba3f700 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -311,3 +311,16 @@ constexpr bool change_union_member() {
   return u.b == 2;
 }
 static_assert(change_union_member());
+
+namespace PR48606 {
+  struct A { mutable int n = 0; };
+
+  constexpr bool f() {
+    A a;
+    A *p = &a;
+    p->~A();
+    std::construct_at<A>(p);
+    return true;
+  }
+  static_assert(f());
+}


        


More information about the cfe-commits mailing list