llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> So we diagnose double-destroy scenarios. --- Full diff: https://github.com/llvm/llvm-project/pull/179957.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+2) - (modified) clang/test/AST/ByteCode/records.cpp (+9) ``````````diff diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index d095e6f862fc5..8eaff4bb07f7d 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1549,6 +1549,8 @@ bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckRange(S, OpPC, Ptr, AK_Destroy)) return false; + if (!CheckLifetime(S, OpPC, Ptr.getLifetime(), AK_Destroy)) + return false; // Can't call a dtor on a global variable. if (Ptr.block()->isStatic()) { diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 4799ebe25dde1..804b4c6ea466a 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -602,6 +602,15 @@ namespace Destructors { } static_assert(testS() == 1); // both-error {{not an integral constant expression}} \ // both-note {{in call to 'testS()'}} + + struct A { int n; }; + constexpr void double_destroy() { + A a; + a.~A(); + a.~A(); // both-note {{destruction of object outside its lifetime}} + } + static_assert((double_destroy(), true)); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} } namespace BaseToDerived { `````````` </details> https://github.com/llvm/llvm-project/pull/179957 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
