aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2024-08-03 08:04:24 +0200
committerGitHub <noreply@github.com>2024-08-03 08:04:24 +0200
commit5d64b37f3403dc1683bd4f8166f4286e6562c6cf (patch)
tree688956173883275436af4de00aacce94334d8dd0
parent8f39502b85d34998752193e85f36c408d3c99248 (diff)
downloadllvm-5d64b37f3403dc1683bd4f8166f4286e6562c6cf.zip
llvm-5d64b37f3403dc1683bd4f8166f4286e6562c6cf.tar.gz
llvm-5d64b37f3403dc1683bd4f8166f4286e6562c6cf.tar.bz2
[clang][Interp] Convert blocks to DeadBlocks when destroying frames (#101794)
This doesn't fix the attached test case, but at least we're not crashing anymore.
-rw-r--r--clang/lib/AST/Interp/InterpFrame.cpp4
-rw-r--r--clang/test/AST/Interp/new-delete.cpp21
2 files changed, 22 insertions, 3 deletions
diff --git a/clang/lib/AST/Interp/InterpFrame.cpp b/clang/lib/AST/Interp/InterpFrame.cpp
index 1c37450..9e7bf99 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 ae76950..ddf9100 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