Skip to content

Commit ef87c34

Browse files
authored
[clang][bytecode] Check for dummy pointers when calling pseudo dtors (#137437)
1 parent 4050a6a commit ef87c34

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,7 @@ bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
10781078
if (AK == AK_Read || AK == AK_Increment || AK == AK_Decrement)
10791079
return diagnoseUnknownDecl(S, OpPC, D);
10801080

1081-
assert(AK == AK_Assign);
1082-
if (S.getLangOpts().CPlusPlus14) {
1081+
if (AK == AK_Destroy || S.getLangOpts().CPlusPlus14) {
10831082
const SourceInfo &E = S.Current->getSource(OpPC);
10841083
S.FFDiag(E, diag::note_constexpr_modify_global);
10851084
}

clang/lib/AST/ByteCode/Interp.h

+2
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,8 @@ bool GetLocal(InterpState &S, CodePtr OpPC, uint32_t I) {
13201320

13211321
static inline bool Kill(InterpState &S, CodePtr OpPC) {
13221322
const auto &Ptr = S.Stk.pop<Pointer>();
1323+
if (!CheckDummy(S, OpPC, Ptr, AK_Destroy))
1324+
return false;
13231325
Ptr.endLifetime();
13241326
return true;
13251327
}

clang/test/AST/ByteCode/lifetimes.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ namespace PseudoDtor {
8181
}
8282
return true;
8383
}
84+
85+
int k;
86+
struct T {
87+
int n : (k.~I(), 1); // both-error {{constant expression}} \
88+
// both-note {{visible outside that expression}}
89+
};
8490
}

0 commit comments

Comments
 (0)