From: Nico Weber Date: Sat, 29 Dec 2012 20:03:39 +0000 (+0000) Subject: ArrayRefize a CompoundStmt constructor. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d36aa359e2f45cd22c7366a015ad94de08044dbb;p=clang ArrayRefize a CompoundStmt constructor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171238 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index b1233816e0..ad3889185f 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -537,7 +537,7 @@ class CompoundStmt : public Stmt { Stmt** Body; SourceLocation LBracLoc, RBracLoc; public: - CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, + CompoundStmt(ASTContext &C, ArrayRef Stmts, SourceLocation LB, SourceLocation RB); // \brief Build an empty compound statment with a location. diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 1ef80c95c4..ac6d224fae 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -251,20 +251,20 @@ SourceLocation Stmt::getLocEnd() const { llvm_unreachable("unknown statement kind"); } -CompoundStmt::CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, +CompoundStmt::CompoundStmt(ASTContext &C, ArrayRef Stmts, SourceLocation LB, SourceLocation RB) : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { - CompoundStmtBits.NumStmts = NumStmts; - assert(CompoundStmtBits.NumStmts == NumStmts && + CompoundStmtBits.NumStmts = Stmts.size(); + assert(CompoundStmtBits.NumStmts == Stmts.size() && "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); - if (NumStmts == 0) { + if (Stmts.size() == 0) { Body = 0; return; } - Body = new (C) Stmt*[NumStmts]; - memcpy(Body, StmtStart, NumStmts * sizeof(*Body)); + Body = new (C) Stmt*[Stmts.size()]; + std::copy(Stmts.begin(), Stmts.end(), Body); } void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) { diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index d038cf1ecd..98010d3cb0 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -103,9 +103,7 @@ BinaryOperator *ASTMaker::makeComparison(const Expr *LHS, const Expr *RHS, } CompoundStmt *ASTMaker::makeCompound(ArrayRef Stmts) { - return new (C) CompoundStmt(C, const_cast(Stmts.data()), - Stmts.size(), - SourceLocation(), SourceLocation()); + return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation()); } DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) { diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8385e8541c..7036cc71ea 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -9410,7 +9410,7 @@ void Sema::DefineImplicitLambdaToFunctionPointerConversion( VK_LValue, Conv->getLocation()).take(); assert(FunctionRef && "Can't refer to __invoke function?"); Stmt *Return = ActOnReturnStmt(Conv->getLocation(), FunctionRef).take(); - Conv->setBody(new (Context) CompoundStmt(Context, &Return, 1, + Conv->setBody(new (Context) CompoundStmt(Context, Return, Conv->getLocation(), Conv->getLocation())); @@ -9469,7 +9469,7 @@ void Sema::DefineImplicitLambdaToBlockPointerConversion( // Set the body of the conversion function. Stmt *ReturnS = Return.take(); - Conv->setBody(new (Context) CompoundStmt(Context, &ReturnS, 1, + Conv->setBody(new (Context) CompoundStmt(Context, ReturnS, Conv->getLocation(), Conv->getLocation())); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 629c9b210a..65d72eca83 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4774,7 +4774,7 @@ Stmt *Sema::MaybeCreateStmtWithCleanups(Stmt *SubStmt) { // a StmtExpr; currently this is only used for asm statements. // This is hacky, either create a new CXXStmtWithTemporaries statement or // a new AsmStmtWithTemporaries. - CompoundStmt *CompStmt = new (Context) CompoundStmt(Context, &SubStmt, 1, + CompoundStmt *CompStmt = new (Context) CompoundStmt(Context, SubStmt, SourceLocation(), SourceLocation()); Expr *E = new (Context) StmtExpr(CompStmt, Context.VoidTy, SourceLocation(), diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 472338a541..df6b8283b7 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -298,7 +298,9 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]); } - return Owned(new (Context) CompoundStmt(Context, Elts, NumElts, L, R)); + return Owned(new (Context) CompoundStmt(Context, + llvm::makeArrayRef(Elts, NumElts), + L, R)); } StmtResult @@ -1937,8 +1939,7 @@ Sema::BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation ColonLoc, Expr *Range = BEFFailure ? EndRangeRef.get() : BeginRangeRef.get(); Diag(Range->getLocStart(), diag::err_for_range_invalid) << RangeLoc << Range->getType() << BEFFailure; - CandidateSet.NoteCandidates(*this, OCD_AllCandidates, - llvm::makeArrayRef(&Range, /*NumArgs=*/1)); + CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Range); } // Return an error if no fix was discovered. if (RangeStatus != FRS_Success)