From: Craig Topper Date: Thu, 22 Oct 2015 04:59:59 +0000 (+0000) Subject: Use an ArrayRef instead of pointer and size throughout offsetof... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0885ebf487e1fbc54103cc9fc14614bfa0d9c3c;p=clang Use an ArrayRef instead of pointer and size throughout offsetof handling code. Also use a range-based for loop. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250989 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 957d9fa93b..d64a2c8ac0 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3966,15 +3966,13 @@ public: /// __builtin_offsetof(type, a.b[123][456].c) ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, - OffsetOfComponent *CompPtr, - unsigned NumComponents, + ArrayRef Components, SourceLocation RParenLoc); ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, SourceLocation TypeLoc, ParsedType ParsedArgTy, - OffsetOfComponent *CompPtr, - unsigned NumComponents, + ArrayRef Components, SourceLocation RParenLoc); // __builtin_choose_expr(constExpr, expr1, expr2) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index ec1edbcde2..4b42a73dd2 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1997,7 +1997,7 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() { } else { PT.consumeClose(); Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc, - Ty.get(), &Comps[0], Comps.size(), + Ty.get(), Comps, PT.getCloseLocation()); } break; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f326285285..1b43f92128 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11137,8 +11137,7 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, - OffsetOfComponent *CompPtr, - unsigned NumComponents, + ArrayRef Components, SourceLocation RParenLoc) { QualType ArgTy = TInfo->getType(); bool Dependent = ArgTy->isDependentType(); @@ -11162,17 +11161,16 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, // GCC extension, diagnose them. // FIXME: This diagnostic isn't actually visible because the location is in // a system header! - if (NumComponents != 1) + if (Components.size() != 1) Diag(BuiltinLoc, diag::ext_offsetof_extended_field_designator) - << SourceRange(CompPtr[1].LocStart, CompPtr[NumComponents-1].LocEnd); + << SourceRange(Components[1].LocStart, Components.back().LocEnd); bool DidWarnAboutNonPOD = false; QualType CurrentType = ArgTy; typedef OffsetOfExpr::OffsetOfNode OffsetOfNode; SmallVector Comps; SmallVector Exprs; - for (unsigned i = 0; i != NumComponents; ++i) { - const OffsetOfComponent &OC = CompPtr[i]; + for (const OffsetOfComponent &OC : Components) { if (OC.isBrackets) { // Offset of an array sub-field. TODO: Should we allow vector elements? if (!CurrentType->isDependentType()) { @@ -11240,7 +11238,7 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, if (!IsSafe && !DidWarnAboutNonPOD && DiagRuntimeBehavior(BuiltinLoc, nullptr, PDiag(DiagID) - << SourceRange(CompPtr[0].LocStart, OC.LocEnd) + << SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType)) DidWarnAboutNonPOD = true; } @@ -11313,8 +11311,7 @@ ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, SourceLocation TypeLoc, ParsedType ParsedArgTy, - OffsetOfComponent *CompPtr, - unsigned NumComponents, + ArrayRef Components, SourceLocation RParenLoc) { TypeSourceInfo *ArgTInfo; @@ -11325,8 +11322,7 @@ ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, if (!ArgTInfo) ArgTInfo = Context.getTrivialTypeSourceInfo(ArgTy, TypeLoc); - return BuildBuiltinOffsetOf(BuiltinLoc, ArgTInfo, CompPtr, NumComponents, - RParenLoc); + return BuildBuiltinOffsetOf(BuiltinLoc, ArgTInfo, Components, RParenLoc); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 513c6285e9..29073debcd 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1850,12 +1850,11 @@ public: /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, - TypeSourceInfo *Type, - Sema::OffsetOfComponent *Components, - unsigned NumComponents, - SourceLocation RParenLoc) { + TypeSourceInfo *Type, + ArrayRef Components, + SourceLocation RParenLoc) { return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, - NumComponents, RParenLoc); + RParenLoc); } /// \brief Build a new sizeof, alignof or vec_step expression with a @@ -7816,8 +7815,7 @@ TreeTransform::TransformOffsetOfExpr(OffsetOfExpr *E) { // Build a new offsetof expression. return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, - Components.data(), Components.size(), - E->getRParenLoc()); + Components, E->getRParenLoc()); } template