Skip to content

Commit 91ffc12

Browse files
authored
[clang][Interp] Pass callee decl to null_callee diagnostics (#104426)
The callee is null, not the full call expression.
1 parent 43ba109 commit 91ffc12

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,9 +2702,9 @@ inline bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
27022702

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

clang/test/AST/Interp/functions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ namespace Comparison {
221221
static_assert(pg == &g, "");
222222
}
223223

224+
constexpr int Double(int n) { return 2 * n; }
225+
constexpr int Triple(int n) { return 3 * n; }
226+
constexpr int Twice(int (*F)(int), int n) { return F(F(n)); }
227+
constexpr int Quadruple(int n) { return Twice(Double, n); }
228+
constexpr auto Select(int n) -> int (*)(int) {
229+
return n == 2 ? &Double : n == 3 ? &Triple : n == 4 ? &Quadruple : 0;
230+
}
231+
constexpr int Apply(int (*F)(int), int n) { return F(n); } // both-note {{'F' evaluates to a null function pointer}}
232+
233+
constexpr int Invalid = Apply(Select(0), 0); // both-error {{must be initialized by a constant expression}} \
234+
// both-note {{in call to 'Apply(nullptr, 0)'}}
224235
}
225236

226237
struct F {

0 commit comments

Comments
 (0)