Skip to content

Commit b200dfc

Browse files
committed
[clang][Interp] Fix calling invalid function pointers
Checking for isConstexpr() is wrong; we need to (try to) call the function and let later code diagnose the failure accordingly.
1 parent 6c74a6f commit b200dfc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,8 +2071,7 @@ inline bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize) {
20712071
const FunctionPointer &FuncPtr = S.Stk.pop<FunctionPointer>();
20722072

20732073
const Function *F = FuncPtr.getFunction();
2074-
if (!F || !F->isConstexpr())
2075-
return false;
2074+
assert(F);
20762075

20772076
assert(ArgSize >= F->getWrittenArgSize());
20782077
uint32_t VarArgSize = ArgSize - F->getWrittenArgSize();

clang/test/AST/Interp/functions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ namespace FunctionReturnType {
187187
static_assert(!!op, "");
188188
constexpr int (*op2)(int, int) = nullptr;
189189
static_assert(!op2, "");
190+
191+
int m() { return 5;} // ref-note {{declared here}} \
192+
// expected-note {{declared here}}
193+
constexpr int (*invalidFnPtr)() = m;
194+
static_assert(invalidFnPtr() == 5, ""); // ref-error {{not an integral constant expression}} \
195+
// ref-note {{non-constexpr function 'm'}} \
196+
// expected-error {{not an integral constant expression}} \
197+
// expected-note {{non-constexpr function 'm'}}
190198
}
191199

192200
namespace Comparison {

0 commit comments

Comments
 (0)