[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 27 05:57:19 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c10c9d8e800: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112542/new/

https://reviews.llvm.org/D112542

Files:
  clang/include/clang/AST/StmtObjC.h
  clang/lib/AST/StmtObjC.cpp


Index: clang/lib/AST/StmtObjC.cpp
===================================================================
--- clang/lib/AST/StmtObjC.cpp
+++ clang/lib/AST/StmtObjC.cpp
@@ -46,9 +46,8 @@
                                      SourceLocation atTryLoc, Stmt *atTryStmt,
                                      Stmt **CatchStmts, unsigned NumCatchStmts,
                                      Stmt *atFinallyStmt) {
-  unsigned Size =
-      sizeof(ObjCAtTryStmt) +
-      (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
+  size_t Size =
+      totalSizeToAlloc<Stmt *>(1 + NumCatchStmts + (atFinallyStmt != nullptr));
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
                                  atFinallyStmt);
@@ -57,8 +56,7 @@
 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
                                           unsigned NumCatchStmts,
                                           bool HasFinally) {
-  unsigned Size =
-      sizeof(ObjCAtTryStmt) + (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
+  size_t Size = totalSizeToAlloc<Stmt *>(1 + NumCatchStmts + HasFinally);
   void *Mem = Context.Allocate(Size, alignof(ObjCAtTryStmt));
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
Index: clang/include/clang/AST/StmtObjC.h
===================================================================
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -162,8 +162,14 @@
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
-class ObjCAtTryStmt : public Stmt {
-private:
+class ObjCAtTryStmt final
+    : public Stmt,
+      private llvm::TrailingObjects<ObjCAtTryStmt, Stmt *> {
+  friend TrailingObjects;
+  size_t numTrailingObjects(OverloadToken<Stmt *>) const {
+    return 1 + NumCatchStmts + HasFinally;
+  }
+
   // The location of the @ in the \@try.
   SourceLocation AtTryLoc;
 
@@ -178,10 +184,8 @@
   /// The order of the statements in memory follows the order in the source,
   /// with the \@try body first, followed by the \@catch statements (if any)
   /// and, finally, the \@finally (if it exists).
-  Stmt **getStmts() { return reinterpret_cast<Stmt **> (this + 1); }
-  const Stmt* const *getStmts() const {
-    return reinterpret_cast<const Stmt * const*> (this + 1);
-  }
+  Stmt **getStmts() { return getTrailingObjects<Stmt *>(); }
+  Stmt *const *getStmts() const { return getTrailingObjects<Stmt *>(); }
 
   ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
                 Stmt **CatchStmts, unsigned NumCatchStmts,
@@ -257,8 +261,8 @@
   }
 
   child_range children() {
-    return child_range(getStmts(),
-                       getStmts() + 1 + NumCatchStmts + HasFinally);
+    return child_range(
+        getStmts(), getStmts() + numTrailingObjects(OverloadToken<Stmt *>()));
   }
 
   const_child_range children() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112542.382633.patch
Type: text/x-patch
Size: 2986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211027/388a20dc/attachment-0001.bin>


More information about the cfe-commits mailing list