@@ -3743,9 +3743,9 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD,
37433743
37443744/* TO_UPSTREAM(BoundsSafety) ON*/
37453745// FIXME: Rename to something more accurate
3746- struct TransposeDynamicBoundsExpr
3747- : public TreeTransform<TransposeDynamicBoundsExpr > {
3748- using BaseClass = TreeTransform<TransposeDynamicBoundsExpr >;
3746+ struct CheckSameParameterNames
3747+ : public TreeTransform<CheckSameParameterNames > {
3748+ using BaseClass = TreeTransform<CheckSameParameterNames >;
37493749
37503750 FunctionDecl *NewFD;
37513751 bool Success = true;
@@ -3761,12 +3761,12 @@ struct TransposeDynamicBoundsExpr
37613761 if (Invalid)
37623762 return false;
37633763
3764- TransposeDynamicBoundsExpr Checker(SemaRef, NewFD);
3764+ CheckSameParameterNames Checker(SemaRef, NewFD);
37653765 Checker.TransformExpr(E);
37663766 return Checker.Success;
37673767 }
37683768
3769- TransposeDynamicBoundsExpr (Sema &SemaRef, FunctionDecl *NewFD)
3769+ CheckSameParameterNames (Sema &SemaRef, FunctionDecl *NewFD)
37703770 : BaseClass(SemaRef), NewFD(NewFD) {}
37713771
37723772 ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
@@ -3788,20 +3788,19 @@ struct TransposeDynamicBoundsExpr
37883788 }
37893789};
37903790
3791- struct TransposeDynamicBoundsExprForReal
3792- : public TreeTransform<TransposeDynamicBoundsExprForReal > {
3793- using BaseClass = TreeTransform<TransposeDynamicBoundsExprForReal >;
3791+ struct TransposeDynamicBoundsExpr
3792+ : public TreeTransform<TransposeDynamicBoundsExpr > {
3793+ using BaseClass = TreeTransform<TransposeDynamicBoundsExpr >;
37943794
37953795 FunctionDecl *NewFD;
3796- bool Success = true;
37973796
37983797 /// Rewrite the expr `E` in the context of `NewFD`.
37993798 /// If `E` refers to any function parameters, the rewritten version will refer
38003799 /// to the corresponding parameters in `NewFD`.
38013800 static bool Rewrite(Sema &SemaRef, FunctionDecl *NewFD, Expr *E,
38023801 std::string &Result) {
38033802
3804- TransposeDynamicBoundsExprForReal Rewriter(SemaRef, NewFD);
3803+ TransposeDynamicBoundsExpr Rewriter(SemaRef, NewFD);
38053804 ExprResult ExprRes = Rewriter.TransformExpr(E);
38063805 if (ExprRes.isInvalid())
38073806 return false;
@@ -3812,16 +3811,15 @@ struct TransposeDynamicBoundsExprForReal
38123811 return true;
38133812 }
38143813
3815- TransposeDynamicBoundsExprForReal (Sema &SemaRef, FunctionDecl *NewFD)
3814+ TransposeDynamicBoundsExpr (Sema &SemaRef, FunctionDecl *NewFD)
38163815 : BaseClass(SemaRef), NewFD(NewFD) {}
38173816
38183817 ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
3819- ASTContext &ctx = SemaRef.getASTContext();
3820- assert(isa<ParmVarDecl>(E->getDecl()));
3821- auto *OldParm = cast<ParmVarDecl>(E->getDecl());
3818+ const ASTContext &ctx = SemaRef.getASTContext();
3819+ const auto *OldParm = cast<ParmVarDecl>(E->getDecl());
38223820 auto *NewParm = NewFD->getParamDecl(OldParm->getFunctionScopeIndex());
38233821 if (!ctx.hasSameType(OldParm->getType(), NewParm->getType()))
3824- return {} ;
3822+ return ExprError() ;
38253823 return DeclRefExpr::Create(ctx, NestedNameSpecifierLoc(), SourceLocation(),
38263824 NewParm, false, SourceLocation(),
38273825 NewParm->getType(), E->getValueKind());
@@ -3893,7 +3891,7 @@ static void fixBoundsSafetyTypeLocs(Sema &S, Sema::SemaDiagnosticBuilder &D,
38933891 KS << "__bidi_indexable";
38943892 } else if (auto DCPTA = QA->getAs<CountAttributedType>()) {
38953893 std::string Rewritten;
3896- if (!TransposeDynamicBoundsExpr ::Check(S, BDecl, DCPTA->getCountExpr(),
3894+ if (!CheckSameParameterNames ::Check(S, BDecl, DCPTA->getCountExpr(),
38973895 Rewritten))
38983896 return;
38993897 const char *Keyword =
@@ -3904,7 +3902,7 @@ static void fixBoundsSafetyTypeLocs(Sema &S, Sema::SemaDiagnosticBuilder &D,
39043902 KS << '(' << Rewritten << ')';
39053903 } else if (auto EndPointer = GetEndPointer(QA)) {
39063904 std::string Rewritten;
3907- if (!TransposeDynamicBoundsExpr ::Check(S, BDecl, EndPointer, Rewritten))
3905+ if (!CheckSameParameterNames ::Check(S, BDecl, EndPointer, Rewritten))
39083906 return;
39093907 KS << "__ended_by(" << Rewritten << ')';
39103908 } else {
@@ -3931,10 +3929,10 @@ static void fixBoundsSafetyTypeLocs(Sema &S, Sema::SemaDiagnosticBuilder &D,
39313929/// to be called once for each direction.
39323930void BoundsSafetyFixItUtils::fixCountAttributedTypeLocsInFunctionSignature(
39333931 Sema &S, Sema::SemaDiagnosticBuilder &D, QualType QA, QualType QB,
3934- FunctionDecl *ADecl, FunctionDecl *BDecl, bool ExprMismatch,
3932+ const FunctionDecl *ADecl, FunctionDecl *BDecl, bool ExprMismatch,
39353933 bool KindMismatch) {
3936- auto *ATy = QA->getAs<CountAttributedType>();
3937- auto *BTy = QB->getAs<CountAttributedType>();
3934+ const auto *ATy = QA->getAs<CountAttributedType>();
3935+ const auto *BTy = QB->getAs<CountAttributedType>();
39383936 assert(ATy && BTy);
39393937 if (!ATy || !BTy)
39403938 return;
@@ -3944,7 +3942,7 @@ void BoundsSafetyFixItUtils::fixCountAttributedTypeLocsInFunctionSignature(
39443942
39453943 if (ExprMismatch) {
39463944 std::string Rewritten;
3947- if (!TransposeDynamicBoundsExprForReal ::Rewrite(
3945+ if (!TransposeDynamicBoundsExpr ::Rewrite(
39483946 S, BDecl, ATy->getCountExpr(), Rewritten))
39493947 return; // don't emit a KindMismatch fix-it either if this fails
39503948 D << FixItHint::CreateReplacement(BTy->getCountExpr()->getSourceRange(),
@@ -3979,8 +3977,8 @@ static void fixBoundsSafetyFunctionDecl(Sema &S, Sema::SemaDiagnosticBuilder &D,
39793977 }
39803978}
39813979
3982- static bool diagnoseConflictingAllocSizeAttribute(FunctionDecl *New,
3983- FunctionDecl *Old,
3980+ static bool diagnoseConflictingAllocSizeAttribute(const FunctionDecl *New,
3981+ const FunctionDecl *Old,
39843982 Sema &Self) {
39853983 // System headers that haven't adopted bounds safety are allowed to break
39863984 // the rules for compatibility reasons, since errors there are hard to fix.
@@ -3991,8 +3989,8 @@ static bool diagnoseConflictingAllocSizeAttribute(FunctionDecl *New,
39913989 // return types. Merging of attributes is done after type checking, but we
39923990 // want to emit the root cause of the type error rather than an error for
39933991 // mismatcing (implicit) return types.
3994- if (auto OldASA = Old->getAttr<AllocSizeAttr>()) {
3995- if (auto NewASA = New->getAttr<AllocSizeAttr>()) {
3992+ if (const auto * OldASA = Old->getAttr<AllocSizeAttr>()) {
3993+ if (const auto * NewASA = New->getAttr<AllocSizeAttr>()) {
39963994 if (!OldASA->getElemSizeParam().equals(NewASA->getElemSizeParam()) ||
39973995 !OldASA->getNumElemsParam().equals(NewASA->getNumElemsParam())) {
39983996 Self.Diag(NewASA->getLoc(), diag::err_mismatched_alloc_size)
0 commit comments