@@ -339,12 +339,10 @@ static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
339339// / \param Sidx The attribute argument index to start checking with.
340340// / \param ParamIdxOk Whether an argument can be indexing into a function
341341// / parameter list.
342- static void checkAttrArgsAreCapabilityObjs (Sema &S, Decl *D,
343- const ParsedAttr &AL,
344- SmallVectorImpl<Expr *> &Args,
345- unsigned Sidx = 0 ,
346- bool ParamIdxOk = false ) {
347- if (Sidx == AL.getNumArgs ()) {
342+ void Sema::checkAttrArgsAreCapabilityObjs (Decl *D, const ParsedAttr &AL,
343+ SmallVectorImpl<Expr *> &Args,
344+ unsigned Sidx, bool ParamIdxOk) {
345+ if (D && Sidx == AL.getNumArgs ()) {
348346 // If we don't have any capability arguments, the attribute implicitly
349347 // refers to 'this'. So we need to make sure that 'this' exists, i.e. we're
350348 // a non-static method, and that the class is a (scoped) capability.
@@ -354,11 +352,10 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
354352 // FIXME -- need to check this again on template instantiation
355353 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
356354 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
357- S.Diag (AL.getLoc (),
358- diag::warn_thread_attribute_not_on_capability_member)
355+ Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_capability_member)
359356 << AL << MD->getParent ();
360357 } else {
361- S. Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_non_static_member)
358+ Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_non_static_member)
362359 << AL;
363360 }
364361 }
@@ -383,7 +380,7 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
383380
384381 // We allow constant strings to be used as a placeholder for expressions
385382 // that are not valid C++ syntax, but warn that they are ignored.
386- S. Diag (AL.getLoc (), diag::warn_thread_attribute_ignored) << AL;
383+ Diag (AL.getLoc (), diag::warn_thread_attribute_ignored) << AL;
387384 Args.push_back (ArgExp);
388385 continue ;
389386 }
@@ -402,7 +399,7 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
402399 const RecordType *RT = getRecordType (ArgTy);
403400
404401 // Now check if we index into a record type function param.
405- if ( !RT && ParamIdxOk) {
402+ if (D && !RT && ParamIdxOk) {
406403 const auto *FD = dyn_cast<FunctionDecl>(D);
407404 const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
408405 if (FD && IL) {
@@ -411,8 +408,8 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
411408 uint64_t ParamIdxFromOne = ArgValue.getZExtValue ();
412409 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1 ;
413410 if (!ArgValue.isStrictlyPositive () || ParamIdxFromOne > NumParams) {
414- S. Diag (AL.getLoc (),
415- diag::err_attribute_argument_out_of_bounds_extra_info)
411+ Diag (AL.getLoc (),
412+ diag::err_attribute_argument_out_of_bounds_extra_info)
416413 << AL << Idx + 1 << NumParams;
417414 continue ;
418415 }
@@ -424,8 +421,8 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
424421 // expression have capabilities. This allows for writing C code where the
425422 // capability may be on the type, and the expression is a capability
426423 // boolean logic expression. Eg) requires_capability(A || B && !C)
427- if (!typeHasCapability (S , ArgTy) && !isCapabilityExpr (S , ArgExp))
428- S. Diag (AL.getLoc (), diag::warn_thread_attribute_argument_not_lockable)
424+ if (!typeHasCapability (* this , ArgTy) && !isCapabilityExpr (* this , ArgExp))
425+ Diag (AL.getLoc (), diag::warn_thread_attribute_argument_not_lockable)
429426 << AL << ArgTy;
430427
431428 Args.push_back (ArgExp);
@@ -460,7 +457,7 @@ static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
460457 Expr *&Arg) {
461458 SmallVector<Expr *, 1 > Args;
462459 // check that all arguments are lockable objects
463- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
460+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
464461 unsigned Size = Args.size ();
465462 if (Size != 1 )
466463 return false ;
@@ -502,7 +499,7 @@ static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
502499 }
503500
504501 // Check that all arguments are lockable objects.
505- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
502+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
506503 if (Args.empty ())
507504 return false ;
508505
@@ -533,7 +530,7 @@ static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
533530 SmallVectorImpl<Expr *> &Args) {
534531 // zero or more arguments ok
535532 // check that all arguments are lockable objects
536- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 0 , /* ParamIdxOk=*/ true );
533+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 0 , /* ParamIdxOk=*/ true );
537534
538535 return true ;
539536}
@@ -612,15 +609,15 @@ static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
612609 }
613610
614611 // check that all arguments are lockable objects
615- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 1 );
612+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 1 );
616613
617614 return true ;
618615}
619616
620617static void handleLockReturnedAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
621618 // check that the argument is lockable object
622619 SmallVector<Expr*, 1 > Args;
623- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
620+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
624621 unsigned Size = Args.size ();
625622 if (Size == 0 )
626623 return ;
@@ -638,7 +635,7 @@ static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
638635
639636 // check that all arguments are lockable objects
640637 SmallVector<Expr*, 1 > Args;
641- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
638+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
642639 unsigned Size = Args.size ();
643640 if (Size == 0 )
644641 return ;
@@ -6269,7 +6266,7 @@ static void handleReleaseCapabilityAttr(Sema &S, Decl *D,
62696266 return ;
62706267 // Check that all arguments are lockable objects.
62716268 SmallVector<Expr *, 1 > Args;
6272- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 0 , true );
6269+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 0 , true );
62736270
62746271 D->addAttr (::new (S.Context ) ReleaseCapabilityAttr (S.Context , AL, Args.data (),
62756272 Args.size ()));
@@ -6286,7 +6283,7 @@ static void handleRequiresCapabilityAttr(Sema &S, Decl *D,
62866283
62876284 // check that all arguments are lockable objects
62886285 SmallVector<Expr*, 1 > Args;
6289- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
6286+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
62906287 if (Args.empty ())
62916288 return ;
62926289
0 commit comments