diff options
-rw-r--r-- | clang/include/clang/AST/Stmt.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/Stmt.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 2 |
3 files changed, 9 insertions, 8 deletions
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 5c0e091a10b..16dde19fda9 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -558,7 +558,7 @@ public: CompoundStmtBits.NumStmts = 0; } - void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts); + void setStmts(const ASTContext &C, ArrayRef<Stmt *> Stmts); bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } unsigned size() const { return CompoundStmtBits.NumStmts; } diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index 8775198a564..a060be11371 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -295,14 +295,15 @@ CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, std::copy(Stmts.begin(), Stmts.end(), Body); } -void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, - unsigned NumStmts) { - if (this->Body) +void CompoundStmt::setStmts(const ASTContext &C, ArrayRef<Stmt *> Stmts) { + if (Body) C.Deallocate(Body); - this->CompoundStmtBits.NumStmts = NumStmts; + CompoundStmtBits.NumStmts = Stmts.size(); + assert(CompoundStmtBits.NumStmts == Stmts.size() && + "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); - Body = new (C) Stmt*[NumStmts]; - memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); + Body = new (C) Stmt*[Stmts.size()]; + std::copy(Stmts.begin(), Stmts.end(), Body); } const char *LabelStmt::getName() const { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 36c93eed9c9..d6101390091 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -134,7 +134,7 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { unsigned NumStmts = Record[Idx++]; while (NumStmts--) Stmts.push_back(Reader.ReadSubStmt()); - S->setStmts(Reader.getContext(), Stmts.data(), Stmts.size()); + S->setStmts(Reader.getContext(), Stmts); S->LBraceLoc = ReadSourceLocation(Record, Idx); S->RBraceLoc = ReadSourceLocation(Record, Idx); } |