From: Benjamin Kramer Date: Sun, 24 Dec 2017 16:24:11 +0000 (+0000) Subject: [AST] Convert AttributedStmt to llvm::TrailingObjects. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cdb5ae94df2213571a0dd4a5ffd45cb4d54856db;p=clang [AST] Convert AttributedStmt to llvm::TrailingObjects. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321428 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 6bd07af1af..d470392e1a 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -875,8 +875,11 @@ public: /// /// Represents an attribute applied to a statement. For example: /// [[omp::for(...)]] for (...) { ... } -class AttributedStmt : public Stmt { +class AttributedStmt final + : public Stmt, + private llvm::TrailingObjects { friend class ASTStmtReader; + friend TrailingObjects; Stmt *SubStmt; SourceLocation AttrLoc; @@ -894,11 +897,9 @@ class AttributedStmt : public Stmt { } const Attr *const *getAttrArrayPtr() const { - return reinterpret_cast(this + 1); - } - const Attr **getAttrArrayPtr() { - return reinterpret_cast(this + 1); + return getTrailingObjects(); } + const Attr **getAttrArrayPtr() { return getTrailingObjects(); } public: static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc, diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 8d240c1336..773b4da940 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -334,7 +334,7 @@ AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, ArrayRef Attrs, Stmt *SubStmt) { assert(!Attrs.empty() && "Attrs should not be empty"); - void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), + void *Mem = C.Allocate(totalSizeToAlloc(Attrs.size()), alignof(AttributedStmt)); return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); } @@ -342,7 +342,7 @@ AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, unsigned NumAttrs) { assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); - void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, + void *Mem = C.Allocate(totalSizeToAlloc(NumAttrs), alignof(AttributedStmt)); return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); }