[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.
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 77c724f..5bbb9f1 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2071,8 +2071,7 @@
const FunctionPointer &FuncPtr = S.Stk.pop<FunctionPointer>();
const Function *F = FuncPtr.getFunction();
- if (!F || !F->isConstexpr())
- return false;
+ assert(F);
assert(ArgSize >= F->getWrittenArgSize());
uint32_t VarArgSize = ArgSize - F->getWrittenArgSize();
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 7b8278c..34a832c 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -187,6 +187,14 @@
static_assert(!!op, "");
constexpr int (*op2)(int, int) = nullptr;
static_assert(!op2, "");
+
+ int m() { return 5;} // ref-note {{declared here}} \
+ // expected-note {{declared here}}
+ constexpr int (*invalidFnPtr)() = m;
+ static_assert(invalidFnPtr() == 5, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{non-constexpr function 'm'}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{non-constexpr function 'm'}}
}
namespace Comparison {