@@ -337,12 +337,10 @@ static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
337337// / \param Sidx The attribute argument index to start checking with.
338338// / \param ParamIdxOk Whether an argument can be indexing into a function
339339// / parameter list.
340- static void checkAttrArgsAreCapabilityObjs (Sema &S, Decl *D,
341- const ParsedAttr &AL,
342- SmallVectorImpl<Expr *> &Args,
343- unsigned Sidx = 0 ,
344- bool ParamIdxOk = false ) {
345- if (Sidx == AL.getNumArgs ()) {
340+ void Sema::checkAttrArgsAreCapabilityObjs (Decl *D, const ParsedAttr &AL,
341+ SmallVectorImpl<Expr *> &Args,
342+ unsigned Sidx, bool ParamIdxOk) {
343+ if (D && Sidx == AL.getNumArgs ()) {
346344 // If we don't have any capability arguments, the attribute implicitly
347345 // refers to 'this'. So we need to make sure that 'this' exists, i.e. we're
348346 // a non-static method, and that the class is a (scoped) capability.
@@ -352,11 +350,10 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
352350 // FIXME -- need to check this again on template instantiation
353351 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
354352 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
355- S.Diag (AL.getLoc (),
356- diag::warn_thread_attribute_not_on_capability_member)
353+ Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_capability_member)
357354 << AL << MD->getParent ();
358355 } else {
359- S. Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_non_static_member)
356+ Diag (AL.getLoc (), diag::warn_thread_attribute_not_on_non_static_member)
360357 << AL;
361358 }
362359 }
@@ -381,7 +378,7 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
381378
382379 // We allow constant strings to be used as a placeholder for expressions
383380 // that are not valid C++ syntax, but warn that they are ignored.
384- S. Diag (AL.getLoc (), diag::warn_thread_attribute_ignored) << AL;
381+ Diag (AL.getLoc (), diag::warn_thread_attribute_ignored) << AL;
385382 Args.push_back (ArgExp);
386383 continue ;
387384 }
@@ -400,7 +397,7 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
400397 const RecordType *RT = getRecordType (ArgTy);
401398
402399 // Now check if we index into a record type function param.
403- if ( !RT && ParamIdxOk) {
400+ if (D && !RT && ParamIdxOk) {
404401 const auto *FD = dyn_cast<FunctionDecl>(D);
405402 const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
406403 if (FD && IL) {
@@ -409,8 +406,8 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
409406 uint64_t ParamIdxFromOne = ArgValue.getZExtValue ();
410407 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1 ;
411408 if (!ArgValue.isStrictlyPositive () || ParamIdxFromOne > NumParams) {
412- S. Diag (AL.getLoc (),
413- diag::err_attribute_argument_out_of_bounds_extra_info)
409+ Diag (AL.getLoc (),
410+ diag::err_attribute_argument_out_of_bounds_extra_info)
414411 << AL << Idx + 1 << NumParams;
415412 continue ;
416413 }
@@ -422,8 +419,8 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
422419 // expression have capabilities. This allows for writing C code where the
423420 // capability may be on the type, and the expression is a capability
424421 // boolean logic expression. Eg) requires_capability(A || B && !C)
425- if (!typeHasCapability (S , ArgTy) && !isCapabilityExpr (S , ArgExp))
426- S. Diag (AL.getLoc (), diag::warn_thread_attribute_argument_not_lockable)
422+ if (!typeHasCapability (* this , ArgTy) && !isCapabilityExpr (* this , ArgExp))
423+ Diag (AL.getLoc (), diag::warn_thread_attribute_argument_not_lockable)
427424 << AL << ArgTy;
428425
429426 Args.push_back (ArgExp);
@@ -458,7 +455,7 @@ static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
458455 Expr *&Arg) {
459456 SmallVector<Expr *, 1 > Args;
460457 // check that all arguments are lockable objects
461- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
458+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
462459 unsigned Size = Args.size ();
463460 if (Size != 1 )
464461 return false ;
@@ -500,7 +497,7 @@ static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
500497 }
501498
502499 // Check that all arguments are lockable objects.
503- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
500+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
504501 if (Args.empty ())
505502 return false ;
506503
@@ -531,7 +528,7 @@ static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
531528 SmallVectorImpl<Expr *> &Args) {
532529 // zero or more arguments ok
533530 // check that all arguments are lockable objects
534- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 0 , /* ParamIdxOk=*/ true );
531+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 0 , /* ParamIdxOk=*/ true );
535532
536533 return true ;
537534}
@@ -633,7 +630,7 @@ static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
633630 }
634631
635632 // check that all arguments are lockable objects
636- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 1 );
633+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 1 );
637634
638635 return true ;
639636}
@@ -661,7 +658,7 @@ static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D,
661658static void handleLockReturnedAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
662659 // check that the argument is lockable object
663660 SmallVector<Expr*, 1 > Args;
664- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
661+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
665662 unsigned Size = Args.size ();
666663 if (Size == 0 )
667664 return ;
@@ -679,7 +676,7 @@ static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
679676
680677 // check that all arguments are lockable objects
681678 SmallVector<Expr*, 1 > Args;
682- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
679+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
683680 unsigned Size = Args.size ();
684681 if (Size == 0 )
685682 return ;
@@ -6020,7 +6017,7 @@ static void handleReleaseCapabilityAttr(Sema &S, Decl *D,
60206017 return ;
60216018 // Check that all arguments are lockable objects.
60226019 SmallVector<Expr *, 1 > Args;
6023- checkAttrArgsAreCapabilityObjs (S, D, AL, Args, 0 , true );
6020+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args, 0 , true );
60246021
60256022 D->addAttr (::new (S.Context ) ReleaseCapabilityAttr (S.Context , AL, Args.data (),
60266023 Args.size ()));
@@ -6037,7 +6034,7 @@ static void handleRequiresCapabilityAttr(Sema &S, Decl *D,
60376034
60386035 // check that all arguments are lockable objects
60396036 SmallVector<Expr*, 1 > Args;
6040- checkAttrArgsAreCapabilityObjs (S, D, AL, Args);
6037+ S. checkAttrArgsAreCapabilityObjs (D, AL, Args);
60416038 if (Args.empty ())
60426039 return ;
60436040
0 commit comments