Skip to content

[clang][Interp] Convert blocks to DeadBlocks when destroying frames #101794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions clang/lib/AST/Interp/InterpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions clang/test/AST/Interp/new-delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading