Skip to content

Commit 9a26dff

Browse files
authored
[clang][bytecode] Check dtor calls for one-past-end pointers (llvm#140047)
1 parent 636628d commit 9a26dff

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,8 @@ bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
13751375
return false;
13761376
if (!CheckTemporary(S, OpPC, Ptr, AK_Destroy))
13771377
return false;
1378+
if (!CheckRange(S, OpPC, Ptr, AK_Destroy))
1379+
return false;
13781380

13791381
// Can't call a dtor on a global variable.
13801382
if (Ptr.block()->isStatic()) {

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,11 @@ namespace TempDtor {
10071007
a_ref.~A(); // both-note {{destruction of temporary is not allowed in a constant expression outside the expression that created the temporary}}
10081008
}
10091009
}
1010+
1011+
namespace OnePastEndDtor {
1012+
struct A {int n; };
1013+
constexpr void destroy_past_end() { // both-error {{never produces a constant expression}}
1014+
A a;
1015+
(&a+1)->~A(); // both-note {{destruction of dereferenced one-past-the-end pointer}}
1016+
}
1017+
}

0 commit comments

Comments
 (0)