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
28 changes: 8 additions & 20 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,13 +2263,17 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
}
} else {
assert(Initializing);
if (!isa<CXXMemberCallExpr>(E)) {
if (!this->emitDupPtr(E))
return false;
}
if (!this->emitDupPtr(E))
return false;
}
}

// Add the (optional, implicit) This pointer.
if (const auto *MC = dyn_cast<CXXMemberCallExpr>(E)) {
if (!this->visit(MC->getImplicitObjectArgument()))
return false;
}

// Put arguments on the stack.
for (const auto *Arg : E->arguments()) {
if (!this->visit(Arg))
Expand Down Expand Up @@ -2326,22 +2330,6 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
return true;
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXMemberCallExpr(
const CXXMemberCallExpr *E) {
if (Initializing) {
// If we're initializing, the current stack top is the pointer to
// initialize, so dup that so this call has its own version.
if (!this->emitDupPtr(E))
return false;
}

if (!this->visit(E->getImplicitObjectArgument()))
return false;

return VisitCallExpr(E);
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXDefaultInitExpr(
const CXXDefaultInitExpr *E) {
Expand Down
1 change: 0 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
bool VisitCallExpr(const CallExpr *E);
bool VisitBuiltinCallExpr(const CallExpr *E);
bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *E);
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/Interp/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ inline bool CheckGlobalCtor(InterpState &S, CodePtr OpPC) {
inline bool Call(InterpState &S, CodePtr OpPC, const Function *Func) {
if (Func->hasThisPointer()) {
size_t ThisOffset =
Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
Func->getArgSize() - (Func->hasRVO() ? primSize(PT_Ptr) : 0);

const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);

Expand Down Expand Up @@ -1904,7 +1904,7 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func) {
assert(Func->hasThisPointer());
assert(Func->isVirtual());
size_t ThisOffset =
Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
Func->getArgSize() - (Func->hasRVO() ? primSize(PT_Ptr) : 0);
Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);

const CXXRecordDecl *DynamicDecl =
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ namespace DiscardExprs {
}
static_assert(foo<3>() == 3, "");

struct ATemp {
consteval ATemp ret_a() const { return ATemp{}; }
};

void test() {
int k = (ATemp().ret_a(), 0);
}

#pragma clang diagnostic pop
}
#endif
Expand Down