From 1b93ddc95b39d8a32dc8605e07594b77f4cfa94d Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 10 Mar 2014 13:43:55 +0000 Subject: [PATCH] Reverting llvm::distance changes to use std::distance with iterators instead, per post-commit review feedback. Replacing llvm::copy changes with SmallVector range-based construction which is a considerably cleaner approach. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203461 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 9 +++++---- lib/CodeGen/CGObjCMac.cpp | 6 ++---- lib/Sema/SemaInit.cpp | 2 +- lib/Sema/SemaLambda.cpp | 6 ++---- lib/Sema/SemaStmt.cpp | 3 +-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 1822eaf2f2..98c946af0b 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -3673,7 +3673,7 @@ static bool HandleConstructorCall(SourceLocation CallLoc, const LValue &This, // Reserve space for the struct members. if (!RD->isUnion() && Result.isUninit()) Result = APValue(APValue::UninitStruct(), RD->getNumBases(), - llvm::distance(RD->fields())); + std::distance(RD->field_begin(), RD->field_end())); if (RD->isInvalidDecl()) return false; const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD); @@ -3733,7 +3733,7 @@ static bool HandleConstructorCall(SourceLocation CallLoc, const LValue &This, *Value = APValue(FD); else *Value = APValue(APValue::UninitStruct(), CD->getNumBases(), - llvm::distance(CD->fields())); + std::distance(CD->field_begin(), CD->field_end())); } if (!HandleLValueMember(Info, (*I)->getInit(), Subobject, FD)) return false; @@ -4930,7 +4930,7 @@ static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E, assert(!RD->isUnion() && "Expected non-union class type"); const CXXRecordDecl *CD = dyn_cast(RD); Result = APValue(APValue::UninitStruct(), CD ? CD->getNumBases() : 0, - llvm::distance(RD->fields())); + std::distance(RD->field_begin(), RD->field_end())); if (RD->isInvalidDecl()) return false; const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD); @@ -5059,7 +5059,8 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) { assert((!isa(RD) || !cast(RD)->getNumBases()) && "initializer list for class with base classes"); - Result = APValue(APValue::UninitStruct(), 0, llvm::distance(RD->fields())); + Result = APValue(APValue::UninitStruct(), 0, + std::distance(RD->field_begin(), RD->field_end())); unsigned ElementNo = 0; bool Success = true; for (const auto *Field : RD->fields()) { diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 13f87e723b..8bc14f6483 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2200,8 +2200,7 @@ void CGObjCCommonMac::BuildRCBlockVarRecordLayout(const RecordType *RT, bool &HasUnion, bool ByrefLayout) { const RecordDecl *RD = RT->getDecl(); - SmallVector Fields; - llvm::copy(RD->fields(), std::back_inserter(Fields)); + SmallVector Fields(RD->fields()); llvm::Type *Ty = CGM.getTypes().ConvertType(QualType(RT, 0)); const llvm::StructLayout *RecLayout = CGM.getDataLayout().getStructLayout(cast(Ty)); @@ -4513,8 +4512,7 @@ void CGObjCCommonMac::BuildAggrIvarRecordLayout(const RecordType *RT, bool &HasUnion) { const RecordDecl *RD = RT->getDecl(); // FIXME - Use iterator. - SmallVector Fields; - llvm::copy(RD->fields(), std::back_inserter(Fields)); + SmallVector Fields(RD->fields()); llvm::Type *Ty = CGM.getTypes().ConvertType(QualType(RT, 0)); const llvm::StructLayout *RecLayout = CGM.getDataLayout().getStructLayout(cast(Ty)); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 711c0c4997..d3b6853109 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -2286,7 +2286,7 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, if (RDecl->isUnion()) NumElements = 1; else - NumElements = llvm::distance(RDecl->fields()); + NumElements = std::distance(RDecl->field_begin(), RDecl->field_end()); } Result->reserveInits(SemaRef.Context, NumElements); diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 4ef23ad72d..158324cb82 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -1146,8 +1146,7 @@ void Sema::ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, LambdaScopeInfo *LSI = getCurLambda(); CXXRecordDecl *Class = LSI->Lambda; Class->setInvalidDecl(); - SmallVector Fields; - llvm::copy(Class->fields(), std::back_inserter(Fields)); + SmallVector Fields(Class->fields()); ActOnFields(0, Class->getLocation(), Class, Fields, SourceLocation(), SourceLocation(), 0); CheckCompletedCXXClass(Class); @@ -1507,8 +1506,7 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, addBlockPointerConversion(*this, IntroducerRange, Class, CallOperator); // Finalize the lambda class. - SmallVector Fields; - llvm::copy(Class->fields(), std::back_inserter(Fields)); + SmallVector Fields(Class->fields()); ActOnFields(0, Class->getLocation(), Class, Fields, SourceLocation(), SourceLocation(), 0); CheckCompletedCXXClass(Class); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 1fce1f1757..d726f5f16c 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -3349,8 +3349,7 @@ void Sema::ActOnCapturedRegionError() { RecordDecl *Record = RSI->TheRecordDecl; Record->setInvalidDecl(); - SmallVector Fields; - llvm::copy(Record->fields(), std::back_inserter(Fields)); + SmallVector Fields(Record->fields()); ActOnFields(/*Scope=*/0, Record->getLocation(), Record, Fields, SourceLocation(), SourceLocation(), /*AttributeList=*/0); -- 2.40.0