[clang] 43358cb - [clang][bytecode] Check pointer lifetime in CheckDestructor (#179957)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 5 22:06:22 PST 2026
Author: Timm Baeder
Date: 2026-02-06T07:06:18+01:00
New Revision: 43358cb3d67cbb94566f094ca9c8ec1c4d76975a
URL: https://github.com/llvm/llvm-project/commit/43358cb3d67cbb94566f094ca9c8ec1c4d76975a
DIFF: https://github.com/llvm/llvm-project/commit/43358cb3d67cbb94566f094ca9c8ec1c4d76975a.diff
LOG: [clang][bytecode] Check pointer lifetime in CheckDestructor (#179957)
So we diagnose double-destroy scenarios.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/records.cpp
Removed:
################################################################################
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 {
More information about the cfe-commits
mailing list