@@ -60,23 +60,26 @@ static bool isOSLogDynamicObject(NominalTypeDecl *nominal) {
6060// / Return true iff the parameter \p param of function \c funDecl is required to
6161// / be a constant. This is true if either the function is an os_log function or
6262// / it is an atomics operation and the parameter represents the ordering.
63- static bool isParamRequiredToBeConstant (FuncDecl *funcDecl, ParamDecl *param) {
63+ static bool isParamRequiredToBeConstant (AbstractFunctionDecl *funcDecl, ParamDecl *param) {
6464 assert (funcDecl && param && " funcDecl and param must not be null" );
65+ Type paramType;
66+ NominalTypeDecl *nominal;
67+ StructDecl *structDecl;
6568 if (hasSemanticsAttr (funcDecl, semantics::OSLOG_REQUIRES_CONSTANT_ARGUMENTS))
6669 return true ;
6770 if (hasSemanticsAttr (funcDecl, semantics::OSLOG_LOG_WITH_LEVEL)) {
6871 // We are looking at a top-level os_log function that accepts level and
6972 // possibly custom log object. Those need not be constants, but every other
7073 // parameter must be.
71- Type paramType = param->getType ();
72- NominalTypeDecl * nominal = paramType->getNominalOrBoundGenericNominal ();
74+ paramType = param->getType ();
75+ nominal = paramType->getNominalOrBoundGenericNominal ();
7376 return !nominal || !isOSLogDynamicObject (nominal);
7477 }
7578 if (!hasSemanticsAttr (funcDecl,
7679 semantics::ATOMICS_REQUIRES_CONSTANT_ORDERINGS))
7780 return false ;
78- Type paramType = param->getType ();
79- StructDecl * structDecl = paramType->getStructOrBoundGenericStruct ();
81+ paramType = param->getType ();
82+ structDecl = paramType->getStructOrBoundGenericStruct ();
8083 if (!structDecl)
8184 return false ;
8285 return isAtomicOrderingDecl (structDecl);
@@ -160,7 +163,7 @@ static Expr *checkConstantness(Expr *expr) {
160163 Decl *declContext = paramDecl->getDeclContext ()->getAsDecl ();
161164 if (!declContext)
162165 return expr;
163- FuncDecl *funcDecl = dyn_cast<FuncDecl >(declContext);
166+ AbstractFunctionDecl *funcDecl = dyn_cast<AbstractFunctionDecl >(declContext);
164167 if (!funcDecl || !isParamRequiredToBeConstant (funcDecl, paramDecl))
165168 return expr;
166169 continue ;
@@ -247,7 +250,7 @@ static bool isStringType(Type type) {
247250// / Otherwise, if the expression is a nominal type, report that it must be
248251// / static member of the type.
249252static void diagnoseError (Expr *errorExpr, const ASTContext &astContext,
250- FuncDecl *funcDecl) {
253+ AbstractFunctionDecl *funcDecl) {
251254 DiagnosticEngine &diags = astContext.Diags ;
252255 Type exprType = errorExpr->getType ();
253256 SourceLoc errorLoc = errorExpr->getLoc ();
@@ -322,9 +325,9 @@ static void diagnoseConstantArgumentRequirementOfCall(const CallExpr *callExpr,
322325 assert (callExpr && callExpr->getType () &&
323326 " callExpr should have a valid type" );
324327 ValueDecl *calledDecl = callExpr->getCalledValue ();
325- if (!calledDecl || !isa<FuncDecl >(calledDecl))
328+ if (!calledDecl || !isa<AbstractFunctionDecl >(calledDecl))
326329 return ;
327- FuncDecl *callee = cast<FuncDecl >(calledDecl);
330+ AbstractFunctionDecl *callee = cast<AbstractFunctionDecl >(calledDecl);
328331
329332 // Collect argument indices that are required to be constants.
330333 SmallVector<unsigned , 4 > constantArgumentIndices;
0 commit comments