@@ -463,8 +463,8 @@ HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
463463}
464464
465465bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy (
466- QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
467- SourceLocation Loc, std::function<std::string()> ComputeAssignee ) {
466+ QualType LHSTy, Expr *RHSExpr, AssignmentAction Action, SourceLocation Loc,
467+ const ValueDecl *Assignee, bool ShowFullyQualifiedAssigneeName ) {
468468 NamedDecl *IncompleteTyDecl = nullptr ;
469469 const CountAttributedType *CATy = nullptr ;
470470 QualType PointeeTy;
@@ -481,13 +481,20 @@ bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
481481 Action != AssignmentAction::Casting &&
482482 Action != AssignmentAction::Passing_CFAudited);
483483
484- // By having users provide a function we only pay the cost of allocation the
485- // string and computing when a diagnostic is emitted.
486- std::string Assignee = ComputeAssignee ? ComputeAssignee () : " " ;
484+ std::string AssigneeStr;
485+ if (Assignee) {
486+ if (ShowFullyQualifiedAssigneeName) {
487+ AssigneeStr = Assignee->getQualifiedNameAsString ();
488+ } else {
489+ AssigneeStr = Assignee->getNameAsString ();
490+ }
491+ }
487492 {
488493 auto D =
489- Diag (Loc, diag::err_bounds_safety_counted_by_on_incomplete_type_on_assign)
490- << /* 0*/ (int )Action << /* 1*/ Assignee << /* 2*/ (Assignee.size () > 0 )
494+ Diag (Loc,
495+ diag::err_bounds_safety_counted_by_on_incomplete_type_on_assign)
496+ << /* 0*/ (int )Action << /* 1*/ AssigneeStr
497+ << /* 2*/ (AssigneeStr.size () > 0 )
491498 << /* 3*/ isa<ImplicitValueInitExpr>(RHSExpr) << /* 4*/ LHSTy
492499 << /* 5*/ CATy->GetAttributeName (/* WithMacroPrefix=*/ true )
493500 << /* 6*/ PointeeTy << /* 7*/ CATy->isOrNull ();
@@ -501,13 +508,13 @@ bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
501508}
502509
503510bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtr (
504- QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
505- SourceLocation Loc, std::function<std::string()> ComputeAssignee ) {
511+ QualType LHSTy, Expr *RHSExpr, AssignmentAction Action, SourceLocation Loc,
512+ const ValueDecl *Assignee, bool ShowFullyQualifiedAssigneeName ) {
506513 if (!getLangOpts ().hasBoundsSafety ())
507514 return true ;
508515
509516 return BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy (
510- LHSTy, RHSExpr, Action, Loc, ComputeAssignee );
517+ LHSTy, RHSExpr, Action, Loc, Assignee, ShowFullyQualifiedAssigneeName );
511518}
512519
513520bool Sema::BoundsSafetyCheckInitialization (const InitializedEntity &Entity,
@@ -531,13 +538,10 @@ bool Sema::BoundsSafetyCheckInitialization(const InitializedEntity &Entity,
531538 Entity.getKind () != InitializedEntity::EK_Variable) {
532539
533540 if (!BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy (
534- LHSType, RHSExpr, Action, SL, [&Entity]() -> std::string {
535- if (const auto *VD =
536- dyn_cast_or_null<ValueDecl>(Entity.getDecl ())) {
537- return VD->getQualifiedNameAsString ();
538- }
539- return " " ;
540- })) {
541+ LHSType, RHSExpr, Action, SL,
542+ dyn_cast_or_null<ValueDecl>(Entity.getDecl ()),
543+ /* ShowFullQualifiedAssigneeName=*/ true )) {
544+
541545 ChecksPassed = false ;
542546
543547 // It's not necessarily bad if this assert fails but we should catch
@@ -629,13 +633,12 @@ bool Sema::BoundsSafetyCheckResolvedCall(FunctionDecl *FDecl, CallExpr *Call,
629633
630634 for (size_t ArgIdx = 0 ; ArgIdx < MinNumArgs; ++ArgIdx) {
631635 Expr *CallArg = Call->getArg (ArgIdx); // FIXME: IgnoreImpCast()?
632- StringRef ParamName ;
636+ const ValueDecl *ParamVarDecl = nullptr ;
633637 QualType ParamTy;
634638 if (FDecl) {
635639 // Direct call
636- auto * ParamVarDecl = FDecl->getParamDecl (ArgIdx);
640+ ParamVarDecl = FDecl->getParamDecl (ArgIdx);
637641 ParamTy = ParamVarDecl->getType ();
638- ParamName = ParamVarDecl->getName ();
639642 } else {
640643 // Indirect call. The parameter name isn't known
641644 ParamTy = ProtoType->getParamType (ArgIdx);
@@ -644,7 +647,7 @@ bool Sema::BoundsSafetyCheckResolvedCall(FunctionDecl *FDecl, CallExpr *Call,
644647 // Assigning to the parameter type is treated as a "use" of the type.
645648 if (!BoundsSafetyCheckAssignmentToCountAttrPtr (
646649 ParamTy, CallArg, AssignmentAction::Passing, CallArg->getBeginLoc (),
647- [&ParamName]() { return ParamName. str (); } ))
650+ ParamVarDecl, /* ShowFullQualifiedAssigneeName= */ false ))
648651 ChecksPassed = false ;
649652 }
650653 return ChecksPassed;
0 commit comments