Author: Serge Pavlov Date: 2022-05-20T14:20:09+07:00 New Revision: 5537b22ccbdc562929949844f9f816cf720e5205
URL: https://github.com/llvm/llvm-project/commit/5537b22ccbdc562929949844f9f816cf720e5205 DIFF: https://github.com/llvm/llvm-project/commit/5537b22ccbdc562929949844f9f816cf720e5205.diff LOG: Make CompoundStmtBitfields::NumStmts not a bit-field Number of statements in CompoundStmt is kept in a bit-field of the common part of Stmt. 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 type 'unsigned int' rather than in bit-field. To make room in CompoundStmtBitfields LBraceLoc is moved to fields of CompoundStmt. Differential Revision: https://reviews.llvm.org/D125635 Added: Modified: clang/include/clang/AST/Stmt.h clang/lib/AST/Stmt.cpp clang/lib/Serialization/ASTReaderStmt.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 1135981319c1a..653ce4b4b90c5 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -128,10 +128,7 @@ class alignas(void *) Stmt { unsigned : NumStmtBits; - unsigned NumStmts : 32 - NumStmtBits; - - /// The location of the opening "{". - SourceLocation LBraceLoc; + unsigned NumStmts; }; class LabelStmtBitfields { @@ -1406,7 +1403,10 @@ class CompoundStmt final : public Stmt, friend class ASTStmtReader; friend TrailingObjects; - /// The location of the closing "}". LBraceLoc is stored in CompoundStmtBits. + /// The location of the opening "{". + SourceLocation LBraceLoc; + + /// The location of the closing "}". SourceLocation RBraceLoc; CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, SourceLocation RB); @@ -1420,9 +1420,8 @@ class CompoundStmt final : public Stmt, // Build an empty compound statement with a location. explicit CompoundStmt(SourceLocation Loc) - : Stmt(CompoundStmtClass), RBraceLoc(Loc) { + : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) { CompoundStmtBits.NumStmts = 0; - CompoundStmtBits.LBraceLoc = Loc; } // Build an empty compound statement. @@ -1505,10 +1504,10 @@ class CompoundStmt final : public Stmt, return const_cast<CompoundStmt *>(this)->getStmtExprResult(); } - SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; } + SourceLocation getBeginLoc() const { return LBraceLoc; } SourceLocation getEndLoc() const { return RBraceLoc; } - SourceLocation getLBracLoc() const { return CompoundStmtBits.LBraceLoc; } + SourceLocation getLBracLoc() const { return LBraceLoc; } SourceLocation getRBracLoc() const { return RBraceLoc; } static bool classof(const Stmt *T) { diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index be19d3b2cce2c..d562717bf6b22 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -363,10 +363,9 @@ int64_t Stmt::getID(const ASTContext &Context) const { CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, SourceLocation RB) - : Stmt(CompoundStmtClass), RBraceLoc(RB) { + : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) { CompoundStmtBits.NumStmts = Stmts.size(); setStmts(Stmts); - CompoundStmtBits.LBraceLoc = LB; } void CompoundStmt::setStmts(ArrayRef<Stmt *> Stmts) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 77ea1b95d5be5..09342de1eee96 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -155,7 +155,7 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { while (NumStmts--) Stmts.push_back(Record.readSubStmt()); S->setStmts(Stmts); - S->CompoundStmtBits.LBraceLoc = readSourceLocation(); + S->LBraceLoc = readSourceLocation(); S->RBraceLoc = readSourceLocation(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits