Skip to content

[clang][Interp] Fix function pointer callexpr eval order #101821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2024
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
22 changes: 13 additions & 9 deletions clang/lib/AST/Interp/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4003,6 +4003,13 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
} else if (!this->visit(MC->getImplicitObjectArgument())) {
return false;
}
} else if (!FuncDecl) {
const Expr *Callee = E->getCallee();
CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false);
if (!this->visit(Callee))
return false;
if (!this->emitSetLocal(PT_FnPtr, *CalleeOffset, E))
return false;
}

llvm::BitVector NonNullArgs = collectNonNullArgs(FuncDecl, Args);
Expand Down Expand Up @@ -4071,22 +4078,19 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
ArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));

// Get the callee, either from a member pointer saved in CalleeOffset,
// or by just visiting the Callee expr.
if (CalleeOffset) {
// Get the callee, either from a member pointer or function pointer saved in
// CalleeOffset.
if (isa<CXXMemberCallExpr>(E) && CalleeOffset) {
if (!this->emitGetLocal(PT_MemberPtr, *CalleeOffset, E))
return false;
if (!this->emitGetMemberPtrDecl(E))
return false;
if (!this->emitCallPtr(ArgSize, E, E))
return false;
} else {
if (!this->visit(E->getCallee()))
return false;

if (!this->emitCallPtr(ArgSize, E, E))
if (!this->emitGetLocal(PT_FnPtr, *CalleeOffset, E))
return false;
}
if (!this->emitCallPtr(ArgSize, E, E))
return false;
}

// Cleanup for discarded return values.
Expand Down
5 changes: 2 additions & 3 deletions clang/test/AST/Interp/eval-order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace EvalOrder {
}
template <typename T> constexpr T &&b(T &&v) {
if (!done_a)
throw "wrong"; // expected-note 5{{not valid}}
throw "wrong"; // expected-note 4{{not valid}}
done_b = true;
return (T &&)v;
}
Expand Down Expand Up @@ -75,8 +75,7 @@ namespace EvalOrder {
SEQ(A(&ud)->*B(&UserDefined::n));

// Rule 4: a(b1, b2, b3)
SEQ(A(f)(B(1), B(2), B(3))); // expected-error {{not an integral constant expression}} FIXME \
// expected-note 2{{in call to}}
SEQ(A(f)(B(1), B(2), B(3)));

// Rule 5: b = a, b @= a
SEQ(B(lvalue<int>().get()) = A(0)); // expected-error {{not an integral constant expression}} FIXME \
Expand Down
Loading