================
@@ -236,5 +257,338 @@ bool EvaluationResult::checkReturnValue(InterpState &S,
const Context &Ctx,
return true;
}
+static bool isGlobalLValue(const Pointer &Ptr) {
+ if (Ptr.isBlockPointer() && Ptr.block()->isDynamic())
+ return true;
+ if (Ptr.isTypeidPointer())
+ return true;
+
+ const Descriptor *Desc = Ptr.getDeclDesc();
+ return ::isGlobalLValue(Desc->asValueDecl(), Desc->asExpr());
+}
+
+/// Check if the given function pointer can be returned from an evaluation.
+static bool checkFunctionPtr(InterpState &S, const Pointer &Ptr,
+ QualType PtrType, SourceInfo Info,
+ ConstantExprKind ConstexprKind) {
+ assert(Ptr.isFunctionPointer());
+ const FunctionPointer &FuncPtr = Ptr.asFunctionPointer();
+ const FunctionDecl *FD = FuncPtr.getFunction()->getDecl();
+ // E.g. ObjC block pointers.
+ if (!FD)
+ return true;
+ if (FD->isImmediateFunction()) {
+ S.FFDiag(Info, diag::note_consteval_address_accessible)
+ << !PtrType->isAnyPointerType();
+ S.Note(FD->getLocation(), diag::note_declared_at);
+ return false;
----------------
erichkeane wrote:
Typically our `check` functions return `true` on error.
https://github.com/llvm/llvm-project/pull/186045
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits