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

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 22:40:13 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

This is what the current interpreter does as well.

---
Full diff: https://github.com/llvm/llvm-project/pull/112841.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4) 
- (modified) clang/test/AST/ByteCode/placement-new.cpp (+13) 


``````````diff
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());
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/112841


More information about the cfe-commits mailing list