Skip to content

Commit 5d64b37

Browse files
authored
[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.
1 parent 8f39502 commit 5d64b37

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

clang/lib/AST/Interp/InterpFrame.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ InterpFrame::~InterpFrame() {
7575
if (Func) {
7676
for (auto &Scope : Func->scopes()) {
7777
for (auto &Local : Scope.locals()) {
78-
Block *B = localBlock(Local.Offset);
79-
if (B->isInitialized())
80-
B->invokeDtor();
78+
S.deallocate(localBlock(Local.Offset));
8179
}
8280
}
8381
}

clang/test/AST/Interp/new-delete.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,27 @@ namespace DeleteThis {
564564
// both-note {{in call to 'super_secret_double_delete()'}}
565565
}
566566

567+
/// FIXME: This is currently diagnosed, but should work.
568+
/// If the destructor for S is _not_ virtual however, it should fail.
569+
namespace CastedDelete {
570+
struct S {
571+
constexpr S(int *p) : p(p) {}
572+
constexpr virtual ~S() { *p = 1; }
573+
int *p;
574+
};
575+
struct T: S {
576+
// implicit destructor defined eagerly because it is constexpr and virtual
577+
using S::S;
578+
};
579+
580+
constexpr int vdtor_1() {
581+
int a;
582+
delete (S*)new T(&a); // expected-note {{delete of pointer to subobject}}
583+
return a;
584+
}
585+
static_assert(vdtor_1() == 1); // expected-error {{not an integral constant expression}} \
586+
// expected-note {{in call to}}
587+
}
567588

568589
#else
569590
/// Make sure we reject this prior to C++20

0 commit comments

Comments
 (0)