================
@@ -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;
+ }
+
+ // __declspec(dllimport) must be handled very carefully:
+ // We must never initialize an expression with the thunk in C++.
+ // Doing otherwise would allow the same id-expression to yield
+ // different addresses for the same function in different translation
+ // units. However, this means that we must dynamically initialize the
+ // expression with the contents of the import address table at runtime.
+ //
+ // The C language has no notion of ODR; furthermore, it has no notion of
+ // dynamic initialization. This means that we are permitted to
+ // perform initialization with the address of the thunk.
+ if (S.getLangOpts().CPlusPlus && !isForManglingOnly(ConstexprKind) &&
+ FD->hasAttr<DLLImportAttr>())
+ // FIXME: Diagnostic!
----------------
tbaederr wrote:
It would break since the current interpreter doesn't produce a diagnostic here
either:
https://github.com/llvm/llvm-project/blob/8a69fb096cb3f3f99ee9bf25247f4b0bc442ca84/clang/lib/AST/ExprConstant.cpp#L2290-L2292
Adding them for both interpreters shouldn't cause a problem I think.
https://github.com/llvm/llvm-project/pull/186045
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits