@@ -463,8 +463,8 @@ HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
463
463
}
464
464
465
465
bool 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 ) {
468
468
NamedDecl *IncompleteTyDecl = nullptr ;
469
469
const CountAttributedType *CATy = nullptr ;
470
470
QualType PointeeTy;
@@ -481,13 +481,20 @@ bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
481
481
Action != AssignmentAction::Casting &&
482
482
Action != AssignmentAction::Passing_CFAudited);
483
483
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
+ }
487
492
{
488
493
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 )
491
498
<< /* 3*/ isa<ImplicitValueInitExpr>(RHSExpr) << /* 4*/ LHSTy
492
499
<< /* 5*/ CATy->GetAttributeName (/* WithMacroPrefix=*/ true )
493
500
<< /* 6*/ PointeeTy << /* 7*/ CATy->isOrNull ();
@@ -501,13 +508,13 @@ bool Sema::BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
501
508
}
502
509
503
510
bool 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 ) {
506
513
if (!getLangOpts ().hasBoundsSafety ())
507
514
return true ;
508
515
509
516
return BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy (
510
- LHSTy, RHSExpr, Action, Loc, ComputeAssignee );
517
+ LHSTy, RHSExpr, Action, Loc, Assignee, ShowFullyQualifiedAssigneeName );
511
518
}
512
519
513
520
bool Sema::BoundsSafetyCheckInitialization (const InitializedEntity &Entity,
@@ -531,13 +538,10 @@ bool Sema::BoundsSafetyCheckInitialization(const InitializedEntity &Entity,
531
538
Entity.getKind () != InitializedEntity::EK_Variable) {
532
539
533
540
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
+
541
545
ChecksPassed = false ;
542
546
543
547
// It's not necessarily bad if this assert fails but we should catch
@@ -629,13 +633,12 @@ bool Sema::BoundsSafetyCheckResolvedCall(FunctionDecl *FDecl, CallExpr *Call,
629
633
630
634
for (size_t ArgIdx = 0 ; ArgIdx < MinNumArgs; ++ArgIdx) {
631
635
Expr *CallArg = Call->getArg (ArgIdx); // FIXME: IgnoreImpCast()?
632
- StringRef ParamName ;
636
+ const ValueDecl *ParamVarDecl = nullptr ;
633
637
QualType ParamTy;
634
638
if (FDecl) {
635
639
// Direct call
636
- auto * ParamVarDecl = FDecl->getParamDecl (ArgIdx);
640
+ ParamVarDecl = FDecl->getParamDecl (ArgIdx);
637
641
ParamTy = ParamVarDecl->getType ();
638
- ParamName = ParamVarDecl->getName ();
639
642
} else {
640
643
// Indirect call. The parameter name isn't known
641
644
ParamTy = ProtoType->getParamType (ArgIdx);
@@ -644,7 +647,7 @@ bool Sema::BoundsSafetyCheckResolvedCall(FunctionDecl *FDecl, CallExpr *Call,
644
647
// Assigning to the parameter type is treated as a "use" of the type.
645
648
if (!BoundsSafetyCheckAssignmentToCountAttrPtr (
646
649
ParamTy, CallArg, AssignmentAction::Passing, CallArg->getBeginLoc (),
647
- [&ParamName]() { return ParamName. str (); } ))
650
+ ParamVarDecl, /* ShowFullQualifiedAssigneeName= */ false ))
648
651
ChecksPassed = false ;
649
652
}
650
653
return ChecksPassed;
0 commit comments