From: Bruno Ricci Date: Sat, 17 Nov 2018 12:53:56 +0000 (+0000) Subject: [AST][NFC] Pack CXXThrowExpr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2756a5d4e0f8646b96adcd2ab5cddc730071654d;p=clang [AST][NFC] Pack CXXThrowExpr Use the newly available space in the bit-fields of Stmt. This saves 8 bytes per CXXThrowExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347136 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 94fba581c1..847a9fe2a1 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1003,42 +1003,43 @@ public: class CXXThrowExpr : public Expr { friend class ASTStmtReader; - Stmt *Op; - SourceLocation ThrowLoc; - - /// Whether the thrown variable (if any) is in scope. - unsigned IsThrownVariableInScope : 1; + /// The optional expression in the throw statement. + Stmt *Operand; public: // \p Ty is the void type which is used as the result type of the - // expression. The \p l is the location of the throw keyword. \p expr - // can by null, if the optional expression to throw isn't present. - CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, + // expression. The \p Loc is the location of the throw keyword. + // \p Operand is the expression in the throw statement, and can be + // null if not present. + CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc, bool IsThrownVariableInScope) : Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, - expr && expr->isInstantiationDependent(), - expr && expr->containsUnexpandedParameterPack()), - Op(expr), ThrowLoc(l), - IsThrownVariableInScope(IsThrownVariableInScope) {} + Operand && Operand->isInstantiationDependent(), + Operand && Operand->containsUnexpandedParameterPack()), + Operand(Operand) { + CXXThrowExprBits.ThrowLoc = Loc; + CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope; + } CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} - const Expr *getSubExpr() const { return cast_or_null(Op); } - Expr *getSubExpr() { return cast_or_null(Op); } + const Expr *getSubExpr() const { return cast_or_null(Operand); } + Expr *getSubExpr() { return cast_or_null(Operand); } - SourceLocation getThrowLoc() const { return ThrowLoc; } + SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; } /// Determines whether the variable thrown by this expression (if any!) /// is within the innermost try block. /// /// This information is required to determine whether the NRVO can apply to /// this variable. - bool isThrownVariableInScope() const { return IsThrownVariableInScope; } - - SourceLocation getBeginLoc() const LLVM_READONLY { return ThrowLoc; } + bool isThrownVariableInScope() const { + return CXXThrowExprBits.IsThrownVariableInScope; + } + SourceLocation getBeginLoc() const { return getThrowLoc(); } SourceLocation getEndLoc() const LLVM_READONLY { if (!getSubExpr()) - return ThrowLoc; + return getThrowLoc(); return getSubExpr()->getEndLoc(); } @@ -1048,7 +1049,7 @@ public: // Iterators child_range children() { - return child_range(&Op, Op ? &Op+1 : &Op); + return child_range(&Operand, Operand ? &Operand + 1 : &Operand); } }; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index b3394a81f4..34667d1df5 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -535,6 +535,19 @@ protected: SourceLocation Loc; }; + class CXXThrowExprBitfields { + friend class ASTStmtReader; + friend class CXXThrowExpr; + + unsigned : NumExprBits; + + /// Whether the thrown variable (if any) is in scope. + unsigned IsThrownVariableInScope : 1; + + /// The location of the "throw". + SourceLocation ThrowLoc; + }; + class TypeTraitExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -636,6 +649,7 @@ protected: CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits; CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits; CXXThisExprBitfields CXXThisExprBits; + CXXThrowExprBitfields CXXThrowExprBits; TypeTraitExprBitfields TypeTraitExprBits; ExprWithCleanupsBitfields ExprWithCleanupsBits; diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 15e89db209..184ae37223 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1473,9 +1473,9 @@ void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) { void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { VisitExpr(E); - E->ThrowLoc = ReadSourceLocation(); - E->Op = Record.readSubExpr(); - E->IsThrownVariableInScope = Record.readInt(); + E->CXXThrowExprBits.ThrowLoc = ReadSourceLocation(); + E->Operand = Record.readSubExpr(); + E->CXXThrowExprBits.IsThrownVariableInScope = Record.readInt(); } void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {