[clang] [clang][Interp] Convert bocks to DeadBlocks when destroying frames (PR #101794)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 22:18:38 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This doesn't fix the attached test case, but at least we're not crashing anymore.
---
Full diff: https://github.com/llvm/llvm-project/pull/101794.diff
2 Files Affected:
- (modified) clang/lib/AST/Interp/InterpFrame.cpp (+1-3)
- (modified) clang/test/AST/Interp/new-delete.cpp (+21)
``````````diff
diff --git a/clang/lib/AST/Interp/InterpFrame.cpp b/clang/lib/AST/Interp/InterpFrame.cpp
index 1c37450ae1c6e..9e7bf9972a578 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -75,9 +75,7 @@ InterpFrame::~InterpFrame() {
if (Func) {
for (auto &Scope : Func->scopes()) {
for (auto &Local : Scope.locals()) {
- Block *B = localBlock(Local.Offset);
- if (B->isInitialized())
- B->invokeDtor();
+ S.deallocate(localBlock(Local.Offset));
}
}
}
diff --git a/clang/test/AST/Interp/new-delete.cpp b/clang/test/AST/Interp/new-delete.cpp
index ae76950f13731..ddf91005c61d9 100644
--- a/clang/test/AST/Interp/new-delete.cpp
+++ b/clang/test/AST/Interp/new-delete.cpp
@@ -564,6 +564,27 @@ namespace DeleteThis {
// both-note {{in call to 'super_secret_double_delete()'}}
}
+/// FIXME: This is currently diagnosed, but should work.
+/// If the destructor for S is _not_ virtual however, it should fail.
+namespace CastedDelete {
+ struct S {
+ constexpr S(int *p) : p(p) {}
+ constexpr virtual ~S() { *p = 1; }
+ int *p;
+ };
+ struct T: S {
+ // implicit destructor defined eagerly because it is constexpr and virtual
+ using S::S;
+ };
+
+ constexpr int vdtor_1() {
+ int a;
+ delete (S*)new T(&a); // expected-note {{delete of pointer to subobject}}
+ return a;
+ }
+ static_assert(vdtor_1() == 1); // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to}}
+}
#else
/// Make sure we reject this prior to C++20
``````````
</details>
https://github.com/llvm/llvm-project/pull/101794
More information about the cfe-commits
mailing list