Skip to content

[clang][Interp] Pass callee decl to null_callee diagnostics #104426

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 15, 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
4 changes: 2 additions & 2 deletions clang/lib/AST/Interp/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2702,9 +2702,9 @@ inline bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,

const Function *F = FuncPtr.getFunction();
if (!F) {
const Expr *E = S.Current->getExpr(OpPC);
const auto *E = cast<CallExpr>(S.Current->getExpr(OpPC));
S.FFDiag(E, diag::note_constexpr_null_callee)
<< const_cast<Expr *>(E) << E->getSourceRange();
<< const_cast<Expr *>(E->getCallee()) << E->getSourceRange();
return false;
}

Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/Interp/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ namespace Comparison {
static_assert(pg == &g, "");
}

constexpr int Double(int n) { return 2 * n; }
constexpr int Triple(int n) { return 3 * n; }
constexpr int Twice(int (*F)(int), int n) { return F(F(n)); }
constexpr int Quadruple(int n) { return Twice(Double, n); }
constexpr auto Select(int n) -> int (*)(int) {
return n == 2 ? &Double : n == 3 ? &Triple : n == 4 ? &Quadruple : 0;
}
constexpr int Apply(int (*F)(int), int n) { return F(n); } // both-note {{'F' evaluates to a null function pointer}}

constexpr int Invalid = Apply(Select(0), 0); // both-error {{must be initialized by a constant expression}} \
// both-note {{in call to 'Apply(nullptr, 0)'}}
}

struct F {
Expand Down
Loading