r321428 - [AST] Convert AttributedStmt to llvm::TrailingObjects.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 24 08:24:11 PST 2017


Author: d0k
Date: Sun Dec 24 08:24:11 2017
New Revision: 321428

URL: http://llvm.org/viewvc/llvm-project?rev=321428&view=rev
Log:
[AST] Convert AttributedStmt to llvm::TrailingObjects.

No functionality change intended.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=321428&r1=321427&r2=321428&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sun Dec 24 08:24:11 2017
@@ -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<AttributedStmt, const Attr *> {
   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<const Attr *const *>(this + 1);
-  }
-  const Attr **getAttrArrayPtr() {
-    return reinterpret_cast<const Attr **>(this + 1);
+    return getTrailingObjects<const Attr *>();
   }
+  const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
 
 public:
   static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=321428&r1=321427&r2=321428&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Sun Dec 24 08:24:11 2017
@@ -334,7 +334,7 @@ AttributedStmt *AttributedStmt::Create(c
                                        ArrayRef<const Attr*> 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<const Attr *>(Attrs.size()),
                          alignof(AttributedStmt));
   return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
 }
@@ -342,7 +342,7 @@ AttributedStmt *AttributedStmt::Create(c
 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<const Attr *>(NumAttrs),
                          alignof(AttributedStmt));
   return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
 }




More information about the cfe-commits mailing list