diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2018-07-23 12:45:24 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2018-07-23 12:45:24 +0000 |
commit | c0a0fb356319891e5a9c31a140e821778b4addc7 (patch) | |
tree | 0504456109cb51343dc28f26fff2f959eeb553a2 /clang/lib/AST/StmtCXX.cpp | |
parent | 3828c6ff9414ca3f83efa6d9b0b69c9f48e4e761 (diff) | |
download | bcm5719-llvm-c0a0fb356319891e5a9c31a140e821778b4addc7.tar.gz bcm5719-llvm-c0a0fb356319891e5a9c31a140e821778b4addc7.zip |
[AST] Use llvm::TrailingObjects in CXXTryStmt
1. Use llvm::TrailingObjects in CXXTryStmt instead of manually doing the reinterpret_casts + pointer arithmetic. This is more consistent with other classes using this idiom and this make it clearer that this class has trailing objects.
2. Make the class CXXTryStmt final since it has trailing objects.
3. Move the friend declarations together.
No functional changes.
Patch by Bruno Ricci!
Differential Revision: https://reviews.llvm.org/D48873
llvm-svn: 337688
Diffstat (limited to 'clang/lib/AST/StmtCXX.cpp')
-rw-r--r-- | clang/lib/AST/StmtCXX.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/clang/lib/AST/StmtCXX.cpp b/clang/lib/AST/StmtCXX.cpp index 666f5dcc9d9..bf2d6a16fb5 100644 --- a/clang/lib/AST/StmtCXX.cpp +++ b/clang/lib/AST/StmtCXX.cpp @@ -25,18 +25,14 @@ QualType CXXCatchStmt::getCaughtType() const { CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef<Stmt *> handlers) { - std::size_t Size = sizeof(CXXTryStmt); - Size += ((handlers.size() + 1) * sizeof(Stmt *)); - + const size_t Size = totalSizeToAlloc<Stmt *>(handlers.size() + 1); void *Mem = C.Allocate(Size, alignof(CXXTryStmt)); return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); } CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, unsigned numHandlers) { - std::size_t Size = sizeof(CXXTryStmt); - Size += ((numHandlers + 1) * sizeof(Stmt *)); - + const size_t Size = totalSizeToAlloc<Stmt *>(numHandlers + 1); void *Mem = C.Allocate(Size, alignof(CXXTryStmt)); return new (Mem) CXXTryStmt(Empty, numHandlers); } @@ -44,7 +40,7 @@ CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, ArrayRef<Stmt *> handlers) : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { - Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); + Stmt **Stmts = getStmts(); Stmts[0] = tryBlock; std::copy(handlers.begin(), handlers.end(), Stmts + 1); } |