Skip to content
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
13 changes: 9 additions & 4 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,14 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
return false;
}

static bool checkDestructor(InterpState &S, CodePtr OpPC, const Function *Func,
const Pointer &ThisPtr) {
return CheckActive(S, OpPC, ThisPtr, AK_Destroy);
bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
// Can't call a dtor on a global variable.
if (Ptr.block()->isStatic()) {
const SourceInfo &E = S.Current->getSource(OpPC);
S.FFDiag(E, diag::note_constexpr_modify_global);
return false;
}
return CheckActive(S, OpPC, Ptr, AK_Destroy);
}

static void compileFunction(InterpState &S, const Function *Func) {
Expand Down Expand Up @@ -1486,7 +1491,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,

if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr))
return false;
if (Func->isDestructor() && !checkDestructor(S, OpPC, Func, ThisPtr))
if (Func->isDestructor() && !CheckDestructor(S, OpPC, ThisPtr))
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index);
bool CheckBitCast(InterpState &S, CodePtr OpPC, bool HasIndeterminateBits,
bool TargetIsUCharOrByte);
bool CheckBCPResult(InterpState &S, const Pointer &Ptr);
bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr);

template <typename T>
static bool handleOverflow(InterpState &S, CodePtr OpPC, const T &SrcValue) {
Expand Down Expand Up @@ -3242,7 +3243,7 @@ bool DiagTypeid(InterpState &S, CodePtr OpPC);

inline bool CheckDestruction(InterpState &S, CodePtr OpPC) {
const auto &Ptr = S.Stk.peek<Pointer>();
return CheckActive(S, OpPC, Ptr, AK_Destroy);
return CheckDestructor(S, OpPC, Ptr);
}

//===----------------------------------------------------------------------===//
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/ByteCode/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,3 +1810,12 @@ namespace AccessMismatch {
static_assert(B().cmp(), ""); // both-error {{constant expression}} \
// both-note {{in call}}
}

namespace GlobalDtor {
struct A {
};
constexpr A a = {};
constexpr void destroy1() { // both-error {{constexpr}}
a.~A(); // both-note {{cannot modify an object that is visible outside}}
}
}