@@ -60,23 +60,26 @@ static bool isOSLogDynamicObject(NominalTypeDecl *nominal) {
60
60
// / Return true iff the parameter \p param of function \c funDecl is required to
61
61
// / be a constant. This is true if either the function is an os_log function or
62
62
// / 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) {
64
64
assert (funcDecl && param && " funcDecl and param must not be null" );
65
+ Type paramType;
66
+ NominalTypeDecl *nominal;
67
+ StructDecl *structDecl;
65
68
if (hasSemanticsAttr (funcDecl, semantics::OSLOG_REQUIRES_CONSTANT_ARGUMENTS))
66
69
return true ;
67
70
if (hasSemanticsAttr (funcDecl, semantics::OSLOG_LOG_WITH_LEVEL)) {
68
71
// We are looking at a top-level os_log function that accepts level and
69
72
// possibly custom log object. Those need not be constants, but every other
70
73
// parameter must be.
71
- Type paramType = param->getType ();
72
- NominalTypeDecl * nominal = paramType->getNominalOrBoundGenericNominal ();
74
+ paramType = param->getType ();
75
+ nominal = paramType->getNominalOrBoundGenericNominal ();
73
76
return !nominal || !isOSLogDynamicObject (nominal);
74
77
}
75
78
if (!hasSemanticsAttr (funcDecl,
76
79
semantics::ATOMICS_REQUIRES_CONSTANT_ORDERINGS))
77
80
return false ;
78
- Type paramType = param->getType ();
79
- StructDecl * structDecl = paramType->getStructOrBoundGenericStruct ();
81
+ paramType = param->getType ();
82
+ structDecl = paramType->getStructOrBoundGenericStruct ();
80
83
if (!structDecl)
81
84
return false ;
82
85
return isAtomicOrderingDecl (structDecl);
@@ -160,7 +163,7 @@ static Expr *checkConstantness(Expr *expr) {
160
163
Decl *declContext = paramDecl->getDeclContext ()->getAsDecl ();
161
164
if (!declContext)
162
165
return expr;
163
- FuncDecl *funcDecl = dyn_cast<FuncDecl >(declContext);
166
+ AbstractFunctionDecl *funcDecl = dyn_cast<AbstractFunctionDecl >(declContext);
164
167
if (!funcDecl || !isParamRequiredToBeConstant (funcDecl, paramDecl))
165
168
return expr;
166
169
continue ;
@@ -247,7 +250,7 @@ static bool isStringType(Type type) {
247
250
// / Otherwise, if the expression is a nominal type, report that it must be
248
251
// / static member of the type.
249
252
static void diagnoseError (Expr *errorExpr, const ASTContext &astContext,
250
- FuncDecl *funcDecl) {
253
+ AbstractFunctionDecl *funcDecl) {
251
254
DiagnosticEngine &diags = astContext.Diags ;
252
255
Type exprType = errorExpr->getType ();
253
256
SourceLoc errorLoc = errorExpr->getLoc ();
@@ -322,9 +325,9 @@ static void diagnoseConstantArgumentRequirementOfCall(const CallExpr *callExpr,
322
325
assert (callExpr && callExpr->getType () &&
323
326
" callExpr should have a valid type" );
324
327
ValueDecl *calledDecl = callExpr->getCalledValue ();
325
- if (!calledDecl || !isa<FuncDecl >(calledDecl))
328
+ if (!calledDecl || !isa<AbstractFunctionDecl >(calledDecl))
326
329
return ;
327
- FuncDecl *callee = cast<FuncDecl >(calledDecl);
330
+ AbstractFunctionDecl *callee = cast<AbstractFunctionDecl >(calledDecl);
328
331
329
332
// Collect argument indices that are required to be constants.
330
333
SmallVector<unsigned , 4 > constantArgumentIndices;
0 commit comments