[PATCH] D125635: Move NumStmts from CompoundStmtBitfields to fields of CompoundStmt

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 15 10:10:42 PDT 2022


sepavloff created this revision.
sepavloff added reviewers: aaron.ballman, rsmith, rjmccall.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

Number of statements in CompoundStmt is kept in a bit-field of Stmt
common part. The field has 24 bits for the number. To allocate a new
bit field (as attempted in https://reviews.llvm.org/D123952), this
number must be reduced, maximal number of statements in a compound
statement becomes smaller. It can result in compilation errors of some
programs.

With this change the number of statements is kept in a field of
CompoundStmt rather than in bit-field of the common part.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125635

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


Index: clang/lib/AST/Stmt.cpp
===================================================================
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -363,14 +363,13 @@
 
 CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB,
                            SourceLocation RB)
-    : Stmt(CompoundStmtClass), RBraceLoc(RB) {
-  CompoundStmtBits.NumStmts = Stmts.size();
+    : Stmt(CompoundStmtClass), NumStmts(Stmts.size()), RBraceLoc(RB) {
   setStmts(Stmts);
   CompoundStmtBits.LBraceLoc = LB;
 }
 
 void CompoundStmt::setStmts(ArrayRef<Stmt *> Stmts) {
-  assert(CompoundStmtBits.NumStmts == Stmts.size() &&
+  assert(NumStmts == Stmts.size() &&
          "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
 
   std::copy(Stmts.begin(), Stmts.end(), body_begin());
@@ -388,7 +387,7 @@
   void *Mem =
       C.Allocate(totalSizeToAlloc<Stmt *>(NumStmts), alignof(CompoundStmt));
   CompoundStmt *New = new (Mem) CompoundStmt(EmptyShell());
-  New->CompoundStmtBits.NumStmts = NumStmts;
+  New->NumStmts = NumStmts;
   return New;
 }
 
Index: clang/include/clang/AST/Stmt.h
===================================================================
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -128,8 +128,6 @@
 
     unsigned : NumStmtBits;
 
-    unsigned NumStmts : 32 - NumStmtBits;
-
     /// The location of the opening "{".
     SourceLocation LBraceLoc;
   };
@@ -1406,6 +1404,8 @@
   friend class ASTStmtReader;
   friend TrailingObjects;
 
+  unsigned NumStmts;
+
   /// The location of the closing "}". LBraceLoc is stored in CompoundStmtBits.
   SourceLocation RBraceLoc;
 
@@ -1420,16 +1420,15 @@
 
   // Build an empty compound statement with a location.
   explicit CompoundStmt(SourceLocation Loc)
-      : Stmt(CompoundStmtClass), RBraceLoc(Loc) {
-    CompoundStmtBits.NumStmts = 0;
+      : Stmt(CompoundStmtClass), NumStmts(0), RBraceLoc(Loc) {
     CompoundStmtBits.LBraceLoc = Loc;
   }
 
   // Build an empty compound statement.
   static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts);
 
-  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
-  unsigned size() const { return CompoundStmtBits.NumStmts; }
+  bool body_empty() const { return NumStmts == 0; }
+  unsigned size() const { return NumStmts; }
 
   using body_iterator = Stmt **;
   using body_range = llvm::iterator_range<body_iterator>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125635.429545.patch
Type: text/x-patch
Size: 2411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220515/3e2411a6/attachment.bin>


More information about the cfe-commits mailing list