diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1535,9 +1535,6 @@ }; class FixedPointLiteral : public Expr, public APIntStorage { - SourceLocation Loc; - unsigned Scale; - /// \brief Construct an empty fixed-point literal. explicit FixedPointLiteral(EmptyShell Empty) : Expr(FixedPointLiteralClass, Empty) {} @@ -1555,16 +1552,22 @@ /// Returns an empty fixed-point literal. static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty); - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return FixedPointLiteralBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return FixedPointLiteralBits.Loc; + } /// \brief Retrieve the location of the literal. - SourceLocation getLocation() const { return Loc; } + SourceLocation getLocation() const { return FixedPointLiteralBits.Loc; } - void setLocation(SourceLocation Location) { Loc = Location; } + void setLocation(SourceLocation Location) { + FixedPointLiteralBits.Loc = Location; + } - unsigned getScale() const { return Scale; } - void setScale(unsigned S) { Scale = S; } + unsigned getScale() const { return FixedPointLiteralBits.Scale; } + void setScale(unsigned S) { FixedPointLiteralBits.Scale = S; } static bool classof(const Stmt *T) { return T->getStmtClass() == FixedPointLiteralClass; @@ -1592,15 +1595,15 @@ }; private: - unsigned Value; SourceLocation Loc; + public: // type should be IntTy CharacterLiteral(unsigned value, CharacterKind kind, QualType type, SourceLocation l) - : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary), - Value(value), Loc(l) { + : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l) { CharacterLiteralBits.Kind = kind; + CharacterLiteralBits.Value = value; setDependence(ExprDependence::None); } @@ -1615,11 +1618,11 @@ SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } - unsigned getValue() const { return Value; } + unsigned getValue() const { return CharacterLiteralBits.Value; } void setLocation(SourceLocation Location) { Loc = Location; } void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; } - void setValue(unsigned Val) { Value = Val; } + void setValue(unsigned Val) { CharacterLiteralBits.Value = Val; } static bool classof(const Stmt *T) { return T->getStmtClass() == CharacterLiteralClass; @@ -1637,8 +1640,6 @@ }; class FloatingLiteral : public Expr, private APFloatStorage { - SourceLocation Loc; - FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L); @@ -1691,11 +1692,15 @@ /// debugging dumps, etc. double getValueAsApproximateDouble() const; - SourceLocation getLocation() const { return Loc; } - void setLocation(SourceLocation L) { Loc = L; } + SourceLocation getLocation() const { return FloatingLiteralBits.Loc; } + void setLocation(SourceLocation L) { FloatingLiteralBits.Loc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return FloatingLiteralBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return FloatingLiteralBits.Loc; + } static bool classof(const Stmt *T) { return T->getStmtClass() == FloatingLiteralClass; @@ -2055,7 +2060,7 @@ // kernels. class SYCLUniqueStableNameExpr final : public Expr { friend class ASTStmtReader; - SourceLocation OpLoc, LParen, RParen; + SourceLocation LParen, RParen; TypeSourceInfo *TypeInfo; SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy); @@ -2065,7 +2070,7 @@ void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; } - void setLocation(SourceLocation L) { OpLoc = L; } + void setLocation(SourceLocation L) { ExprWithSLocBits.Loc = L; } void setLParenLocation(SourceLocation L) { LParen = L; } void setRParenLocation(SourceLocation L) { RParen = L; } @@ -2082,7 +2087,7 @@ SourceLocation getBeginLoc() const { return getLocation(); } SourceLocation getEndLoc() const { return RParen; } - SourceLocation getLocation() const { return OpLoc; } + SourceLocation getLocation() const { return ExprWithSLocBits.Loc; } SourceLocation getLParenLocation() const { return LParen; } SourceLocation getRParenLocation() const { return RParen; } @@ -2110,13 +2115,14 @@ /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This /// AST node is only formed if full location information is requested. class ParenExpr : public Expr { - SourceLocation L, R; + SourceLocation R; Stmt *Val; public: ParenExpr(SourceLocation l, SourceLocation r, Expr *val) : Expr(ParenExprClass, val->getType(), val->getValueKind(), val->getObjectKind()), - L(l), R(r), Val(val) { + R(r), Val(val) { + ExprWithSLocBits.Loc = l; setDependence(computeDependence(this)); } @@ -2128,12 +2134,14 @@ Expr *getSubExpr() { return cast(Val); } void setSubExpr(Expr *E) { Val = E; } - SourceLocation getBeginLoc() const LLVM_READONLY { return L; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return R; } /// Get the location of the left parentheses '('. - SourceLocation getLParen() const { return L; } - void setLParen(SourceLocation Loc) { L = Loc; } + SourceLocation getLParen() const { return ExprWithSLocBits.Loc; } + void setLParen(SourceLocation Loc) { ExprWithSLocBits.Loc = Loc; } /// Get the location of the right parentheses ')'. SourceLocation getRParen() const { return R; } @@ -2447,13 +2455,9 @@ SourceLocation OperatorLoc, RParenLoc; // Base type; TypeSourceInfo *TSInfo; - // Number of sub-components (i.e. instances of OffsetOfNode). - unsigned NumComps; - // Number of sub-expressions (i.e. array subscript expressions). - unsigned NumExprs; size_t numTrailingObjects(OverloadToken) const { - return NumComps; + return OffsetOfExprBits.NumComps; } OffsetOfExpr(const ASTContext &C, QualType type, @@ -2462,8 +2466,10 @@ SourceLocation RParenLoc); explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) - : Expr(OffsetOfExprClass, EmptyShell()), - TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {} + : Expr(OffsetOfExprClass, EmptyShell()), TSInfo(nullptr) { + OffsetOfExprBits.NumComps = numComps; + OffsetOfExprBits.NumExprs = numExprs; + } public: @@ -2491,37 +2497,33 @@ } const OffsetOfNode &getComponent(unsigned Idx) const { - assert(Idx < NumComps && "Subscript out of range"); + assert(Idx < OffsetOfExprBits.NumComps && "Subscript out of range"); return getTrailingObjects()[Idx]; } void setComponent(unsigned Idx, OffsetOfNode ON) { - assert(Idx < NumComps && "Subscript out of range"); + assert(Idx < OffsetOfExprBits.NumComps && "Subscript out of range"); getTrailingObjects()[Idx] = ON; } - unsigned getNumComponents() const { - return NumComps; - } + unsigned getNumComponents() const { return OffsetOfExprBits.NumComps; } Expr* getIndexExpr(unsigned Idx) { - assert(Idx < NumExprs && "Subscript out of range"); + assert(Idx < OffsetOfExprBits.NumExprs && "Subscript out of range"); return getTrailingObjects()[Idx]; } const Expr *getIndexExpr(unsigned Idx) const { - assert(Idx < NumExprs && "Subscript out of range"); + assert(Idx < OffsetOfExprBits.NumExprs && "Subscript out of range"); return getTrailingObjects()[Idx]; } void setIndexExpr(unsigned Idx, Expr* E) { - assert(Idx < NumComps && "Subscript out of range"); + assert(Idx < OffsetOfExprBits.NumComps && "Subscript out of range"); getTrailingObjects()[Idx] = E; } - unsigned getNumExpressions() const { - return NumExprs; - } + unsigned getNumExpressions() const { return OffsetOfExprBits.NumExprs; } SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } @@ -2533,12 +2535,12 @@ // Iterators child_range children() { Stmt **begin = reinterpret_cast(getTrailingObjects()); - return child_range(begin, begin + NumExprs); + return child_range(begin, begin + OffsetOfExprBits.NumExprs); } const_child_range children() const { Stmt *const *begin = reinterpret_cast(getTrailingObjects()); - return const_child_range(begin, begin + NumExprs); + return const_child_range(begin, begin + OffsetOfExprBits.NumExprs); } friend TrailingObjects; }; @@ -2551,7 +2553,7 @@ TypeSourceInfo *Ty; Stmt *Ex; } Argument; - SourceLocation OpLoc, RParenLoc; + SourceLocation RParenLoc; public: UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, @@ -2559,9 +2561,10 @@ SourceLocation rp) : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue, OK_Ordinary), - OpLoc(op), RParenLoc(rp) { + RParenLoc(rp) { assert(ExprKind <= UETT_Last && "invalid enum value!"); UnaryExprOrTypeTraitExprBits.Kind = ExprKind; + UnaryExprOrTypeTraitExprBits.OpLoc = op; assert(static_cast(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind && "UnaryExprOrTypeTraitExprBits.Kind overflow!"); @@ -2619,13 +2622,19 @@ return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); } - SourceLocation getOperatorLoc() const { return OpLoc; } - void setOperatorLoc(SourceLocation L) { OpLoc = L; } + SourceLocation getOperatorLoc() const { + return UnaryExprOrTypeTraitExprBits.OpLoc; + } + void setOperatorLoc(SourceLocation L) { + UnaryExprOrTypeTraitExprBits.OpLoc = L; + } SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return UnaryExprOrTypeTraitExprBits.OpLoc; + } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } static bool classof(const Stmt *T) { @@ -3407,11 +3416,6 @@ /// CompoundLiteralExpr - [C99 6.5.2.5] /// class CompoundLiteralExpr : public Expr { - /// LParenLoc - If non-null, this is the location of the left paren in a - /// compound literal like "(int){4}". This can be null if this is a - /// synthesized compound expression. - SourceLocation LParenLoc; - /// The type as written. This can be an incomplete array type, in /// which case the actual expression type will be different. /// The int part of the pair stores whether this expr is file scope. @@ -3421,7 +3425,8 @@ CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope) : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary), - LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) { + TInfoAndScope(tinfo, fileScope), Init(init) { + CompoundLiteralExprBits.LParenLoc = lparenloc; setDependence(computeDependence(this)); } @@ -3436,8 +3441,10 @@ bool isFileScope() const { return TInfoAndScope.getInt(); } void setFileScope(bool FS) { TInfoAndScope.setInt(FS); } - SourceLocation getLParenLoc() const { return LParenLoc; } - void setLParenLoc(SourceLocation L) { LParenLoc = L; } + SourceLocation getLParenLoc() const { + return CompoundLiteralExprBits.LParenLoc; + } + void setLParenLoc(SourceLocation L) { CompoundLiteralExprBits.LParenLoc = L; } TypeSourceInfo *getTypeSourceInfo() const { return TInfoAndScope.getPointer(); @@ -3450,9 +3457,9 @@ // FIXME: Init should never be null. if (!Init) return SourceLocation(); - if (LParenLoc.isInvalid()) + if (CompoundLiteralExprBits.LParenLoc.isInvalid()) return Init->getBeginLoc(); - return LParenLoc; + return CompoundLiteralExprBits.LParenLoc; } SourceLocation getEndLoc() const LLVM_READONLY { // FIXME: Init should never be null. @@ -4107,14 +4114,16 @@ /// AbstractConditionalOperator - An abstract base class for /// ConditionalOperator and BinaryConditionalOperator. class AbstractConditionalOperator : public Expr { - SourceLocation QuestionLoc, ColonLoc; + SourceLocation ColonLoc; friend class ASTStmtReader; protected: AbstractConditionalOperator(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation qloc, SourceLocation cloc) - : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {} + : Expr(SC, T, VK, OK), ColonLoc(cloc) { + ExprWithSLocBits.Loc = qloc; + } AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { } @@ -4133,7 +4142,7 @@ // the same as getRHS. Expr *getFalseExpr() const; - SourceLocation getQuestionLoc() const { return QuestionLoc; } + SourceLocation getQuestionLoc() const { return ExprWithSLocBits.Loc; } SourceLocation getColonLoc() const { return ColonLoc; } static bool classof(const Stmt *T) { @@ -4304,13 +4313,14 @@ /// AddrLabelExpr - The GNU address of label extension, representing &&label. class AddrLabelExpr : public Expr { - SourceLocation AmpAmpLoc, LabelLoc; + SourceLocation LabelLoc; LabelDecl *Label; public: AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, QualType t) - : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc), - LabelLoc(LLoc), Label(L) { + : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), LabelLoc(LLoc), + Label(L) { + ExprWithSLocBits.Loc = AALoc; setDependence(ExprDependence::None); } @@ -4318,12 +4328,14 @@ explicit AddrLabelExpr(EmptyShell Empty) : Expr(AddrLabelExprClass, Empty) { } - SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } - void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } + SourceLocation getAmpAmpLoc() const { return ExprWithSLocBits.Loc; } + void setAmpAmpLoc(SourceLocation L) { ExprWithSLocBits.Loc = L; } SourceLocation getLabelLoc() const { return LabelLoc; } void setLabelLoc(SourceLocation L) { LabelLoc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; } LabelDecl *getLabel() const { return Label; } @@ -4404,7 +4416,6 @@ // indices. The number of values in this list is always // 2+the number of indices in the vector type. Stmt **SubExprs; - unsigned NumExprs; public: ShuffleVectorExpr(const ASTContext &C, ArrayRef args, QualType Type, @@ -4430,34 +4441,39 @@ /// getNumSubExprs - Return the size of the SubExprs array. This includes the /// constant expression, the actual arguments passed in, and the function /// pointers. - unsigned getNumSubExprs() const { return NumExprs; } + unsigned getNumSubExprs() const { return ShuffleVectorExprBits.NumExprs; } /// Retrieve the array of expressions. Expr **getSubExprs() { return reinterpret_cast(SubExprs); } /// getExpr - Return the Expr at the specified index. Expr *getExpr(unsigned Index) { - assert((Index < NumExprs) && "Arg access out of range!"); + assert((Index < ShuffleVectorExprBits.NumExprs) && + "Arg access out of range!"); return cast(SubExprs[Index]); } const Expr *getExpr(unsigned Index) const { - assert((Index < NumExprs) && "Arg access out of range!"); + assert((Index < ShuffleVectorExprBits.NumExprs) && + "Arg access out of range!"); return cast(SubExprs[Index]); } void setExprs(const ASTContext &C, ArrayRef Exprs); llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const { - assert((N < NumExprs - 2) && "Shuffle idx out of range!"); + assert((N < ShuffleVectorExprBits.NumExprs - 2) && + "Shuffle idx out of range!"); return getExpr(N+2)->EvaluateKnownConstInt(Ctx); } // Iterators child_range children() { - return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); + return child_range(&SubExprs[0], + &SubExprs[0] + ShuffleVectorExprBits.NumExprs); } const_child_range children() const { - return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs); + return const_child_range(&SubExprs[0], + &SubExprs[0] + ShuffleVectorExprBits.NumExprs); } }; @@ -4526,14 +4542,15 @@ class ChooseExpr : public Expr { enum { COND, LHS, RHS, END_EXPR }; Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. - SourceLocation BuiltinLoc, RParenLoc; - bool CondIsTrue; + SourceLocation RParenLoc; + public: ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation RP, bool condIsTrue) - : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP), - CondIsTrue(condIsTrue) { + : Expr(ChooseExprClass, t, VK, OK), RParenLoc(RP) { + ChooseExprBits.CondIsTrue = condIsTrue; + ChooseExprBits.BuiltinLoc = BLoc; SubExprs[COND] = cond; SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; @@ -4549,9 +4566,9 @@ bool isConditionTrue() const { assert(!isConditionDependent() && "Dependent condition isn't true or false"); - return CondIsTrue; + return ChooseExprBits.CondIsTrue; } - void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; } + void setIsConditionTrue(bool isTrue) { ChooseExprBits.CondIsTrue = isTrue; } bool isConditionDependent() const { return getCond()->isTypeDependent() || getCond()->isValueDependent(); @@ -4570,13 +4587,15 @@ Expr *getRHS() const { return cast(SubExprs[RHS]); } void setRHS(Expr *E) { SubExprs[RHS] = E; } - SourceLocation getBuiltinLoc() const { return BuiltinLoc; } - void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } + SourceLocation getBuiltinLoc() const { return ChooseExprBits.BuiltinLoc; } + void setBuiltinLoc(SourceLocation L) { ChooseExprBits.BuiltinLoc = L; } SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ChooseExprBits.BuiltinLoc; + } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } static bool classof(const Stmt *T) { @@ -4600,11 +4619,11 @@ /// that may not match the size of a pointer). class GNUNullExpr : public Expr { /// TokenLoc - The location of the __null keyword. - SourceLocation TokenLoc; public: GNUNullExpr(QualType Ty, SourceLocation Loc) - : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary), TokenLoc(Loc) { + : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary) { + ExprWithSLocBits.Loc = Loc; setDependence(ExprDependence::None); } @@ -4612,11 +4631,15 @@ explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } /// getTokenLocation - The location of the __null token. - SourceLocation getTokenLocation() const { return TokenLoc; } - void setTokenLocation(SourceLocation L) { TokenLoc = L; } + SourceLocation getTokenLocation() const { return ExprWithSLocBits.Loc; } + void setTokenLocation(SourceLocation L) { ExprWithSLocBits.Loc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; } - SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } static bool classof(const Stmt *T) { return T->getStmtClass() == GNUNullExprClass; @@ -4682,7 +4705,7 @@ /// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), /// __builtin_FUNCTION(), or __builtin_FILE(). class SourceLocExpr final : public Expr { - SourceLocation BuiltinLoc, RParenLoc; + SourceLocation RParenLoc; DeclContext *ParentContext; public: @@ -4724,8 +4747,8 @@ const DeclContext *getParentContext() const { return ParentContext; } DeclContext *getParentContext() { return ParentContext; } - SourceLocation getLocation() const { return BuiltinLoc; } - SourceLocation getBeginLoc() const { return BuiltinLoc; } + SourceLocation getLocation() const { return SourceLocExprBits.BuiltinLoc; } + SourceLocation getBeginLoc() const { return SourceLocExprBits.BuiltinLoc; } SourceLocation getEndLoc() const { return RParenLoc; } child_range children() { @@ -4793,7 +4816,7 @@ // FIXME: Eliminate this vector in favor of ASTContext allocation typedef ASTVector InitExprsTy; InitExprsTy InitExprs; - SourceLocation LBraceLoc, RBraceLoc; + SourceLocation RBraceLoc; /// The alternative form of the initializer list (if it exists). /// The int part of the pair stores whether this initializer list is @@ -4922,7 +4945,7 @@ // FIXME: This is wrong; InitListExprs created by semantic analysis have // valid source locations too! bool isExplicit() const { - return LBraceLoc.isValid() && RBraceLoc.isValid(); + return InitListExprBits.LBraceLoc.isValid() && RBraceLoc.isValid(); } // Is this an initializer for an array of characters, initialized by a string @@ -4938,8 +4961,8 @@ /// idiomatic? bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const; - SourceLocation getLBraceLoc() const { return LBraceLoc; } - void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } + SourceLocation getLBraceLoc() const { return InitListExprBits.LBraceLoc; } + void setLBraceLoc(SourceLocation Loc) { InitListExprBits.LBraceLoc = Loc; } SourceLocation getRBraceLoc() const { return RBraceLoc; } void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } @@ -5039,18 +5062,6 @@ /// expression. SourceLocation EqualOrColonLoc; - /// Whether this designated initializer used the GNU deprecated - /// syntax rather than the C99 '=' syntax. - unsigned GNUSyntax : 1; - - /// The number of designators in this initializer expression. - unsigned NumDesignators : 15; - - /// The number of subexpressions of this initializer expression, - /// which contains both the initializer and any additional - /// expressions used by array and array-range designators. - unsigned NumSubExprs : 16; - /// The designators in this designated initialization /// expression. Designator *Designators; @@ -5061,8 +5072,10 @@ ArrayRef IndexExprs, Expr *Init); explicit DesignatedInitExpr(unsigned NumSubExprs) - : Expr(DesignatedInitExprClass, EmptyShell()), - NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { } + : Expr(DesignatedInitExprClass, EmptyShell()), Designators(nullptr) { + DesignatedInitExprBits.NumDesignators = 0; + DesignatedInitExprBits.NumSubExprs = NumSubExprs; + } public: /// A field designator, e.g., ".x". @@ -5230,15 +5243,15 @@ unsigned NumIndexExprs); /// Returns the number of designators in this initializer. - unsigned size() const { return NumDesignators; } + unsigned size() const { return DesignatedInitExprBits.NumDesignators; } // Iterator access to the designators. llvm::MutableArrayRef designators() { - return {Designators, NumDesignators}; + return {Designators, DesignatedInitExprBits.NumDesignators}; } llvm::ArrayRef designators() const { - return {Designators, NumDesignators}; + return {Designators, DesignatedInitExprBits.NumDesignators}; } Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; } @@ -5264,8 +5277,8 @@ /// Determines whether this designated initializer used the /// deprecated GNU syntax for designated initializers. - bool usesGNUSyntax() const { return GNUSyntax; } - void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } + bool usesGNUSyntax() const { return DesignatedInitExprBits.GNUSyntax; } + void setGNUSyntax(bool GNU) { DesignatedInitExprBits.GNUSyntax = GNU; } /// Retrieve the initializer value. Expr *getInit() const { @@ -5280,15 +5293,17 @@ /// designated initializer expression, including the actual /// initialized value and any expressions that occur within array /// and array-range designators. - unsigned getNumSubExprs() const { return NumSubExprs; } + unsigned getNumSubExprs() const { return DesignatedInitExprBits.NumSubExprs; } Expr *getSubExpr(unsigned Idx) const { - assert(Idx < NumSubExprs && "Subscript out of range"); + assert(Idx < DesignatedInitExprBits.NumSubExprs && + "Subscript out of range"); return cast(getTrailingObjects()[Idx]); } void setSubExpr(unsigned Idx, Expr *E) { - assert(Idx < NumSubExprs && "Subscript out of range"); + assert(Idx < DesignatedInitExprBits.NumSubExprs && + "Subscript out of range"); getTrailingObjects()[Idx] = E; } @@ -5309,11 +5324,11 @@ // Iterators child_range children() { Stmt **begin = getTrailingObjects(); - return child_range(begin, begin + NumSubExprs); + return child_range(begin, begin + DesignatedInitExprBits.NumSubExprs); } const_child_range children() const { Stmt * const *begin = getTrailingObjects(); - return const_child_range(begin, begin + NumSubExprs); + return const_child_range(begin, begin + DesignatedInitExprBits.NumSubExprs); } friend TrailingObjects; @@ -5911,13 +5926,14 @@ class ExtVectorElementExpr : public Expr { Stmt *Base; IdentifierInfo *Accessor; - SourceLocation AccessorLoc; + public: ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, IdentifierInfo &accessor, SourceLocation loc) : Expr(ExtVectorElementExprClass, ty, VK, (VK == VK_PRValue ? OK_Ordinary : OK_VectorComponent)), - Base(base), Accessor(&accessor), AccessorLoc(loc) { + Base(base), Accessor(&accessor) { + ExprWithSLocBits.Loc = loc; setDependence(computeDependence(this)); } @@ -5932,8 +5948,8 @@ IdentifierInfo &getAccessor() const { return *Accessor; } void setAccessor(IdentifierInfo *II) { Accessor = II; } - SourceLocation getAccessorLoc() const { return AccessorLoc; } - void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } + SourceLocation getAccessorLoc() const { return ExprWithSLocBits.Loc; } + void setAccessorLoc(SourceLocation L) { ExprWithSLocBits.Loc = L; } /// getNumElements - Get the number of components being selected. unsigned getNumElements() const; @@ -5949,7 +5965,9 @@ SourceLocation getBeginLoc() const LLVM_READONLY { return getBase()->getBeginLoc(); } - SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; } + SourceLocation getEndLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } /// isArrow - Return true if the base expression is a pointer to vector, /// return false if the base expression is a vector. @@ -6248,9 +6266,7 @@ /// not fixed, therefore is not defined in enum. enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR }; Stmt *SubExprs[END_EXPR + 1]; - unsigned NumSubExprs; SourceLocation BuiltinLoc, RParenLoc; - AtomicOp Op; friend class ASTStmtReader; public: @@ -6272,32 +6288,33 @@ } Expr *getScope() const { assert(getScopeModel() && "No scope"); - return cast(SubExprs[NumSubExprs - 1]); + return cast(SubExprs[AtomicExprBits.NumSubExprs - 1]); } Expr *getVal1() const { - if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init) + if (AtomicExprBits.Op == AO__c11_atomic_init || + AtomicExprBits.Op == AO__opencl_atomic_init) return cast(SubExprs[ORDER]); - assert(NumSubExprs > VAL1); + assert(AtomicExprBits.NumSubExprs > VAL1); return cast(SubExprs[VAL1]); } Expr *getOrderFail() const { - assert(NumSubExprs > ORDER_FAIL); + assert(AtomicExprBits.NumSubExprs > ORDER_FAIL); return cast(SubExprs[ORDER_FAIL]); } Expr *getVal2() const { - if (Op == AO__atomic_exchange) + if (AtomicExprBits.Op == AO__atomic_exchange) return cast(SubExprs[ORDER_FAIL]); - assert(NumSubExprs > VAL2); + assert(AtomicExprBits.NumSubExprs > VAL2); return cast(SubExprs[VAL2]); } Expr *getWeak() const { - assert(NumSubExprs > WEAK); + assert(AtomicExprBits.NumSubExprs > WEAK); return cast(SubExprs[WEAK]); } QualType getValueType() const; - AtomicOp getOp() const { return Op; } - unsigned getNumSubExprs() const { return NumSubExprs; } + AtomicOp getOp() const { return static_cast(AtomicExprBits.Op); } + unsigned getNumSubExprs() const { return AtomicExprBits.NumSubExprs; } Expr **getSubExprs() { return reinterpret_cast(SubExprs); } const Expr * const *getSubExprs() const { @@ -6336,10 +6353,10 @@ // Iterators child_range children() { - return child_range(SubExprs, SubExprs+NumSubExprs); + return child_range(SubExprs, SubExprs + AtomicExprBits.NumSubExprs); } const_child_range children() const { - return const_child_range(SubExprs, SubExprs + NumSubExprs); + return const_child_range(SubExprs, SubExprs + AtomicExprBits.NumSubExprs); } /// Get atomic scope model for the atomic op code. @@ -6366,12 +6383,10 @@ /// TypoExpr - Internal placeholder for expressions where typo correction /// still needs to be performed and/or an error diagnostic emitted. class TypoExpr : public Expr { - // The location for the typo name. - SourceLocation TypoLoc; - public: TypoExpr(QualType T, SourceLocation TypoLoc) - : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary), TypoLoc(TypoLoc) { + : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary) { + ExprWithSLocBits.Loc = TypoLoc; assert(T->isDependentType() && "TypoExpr given a non-dependent type"); setDependence(ExprDependence::TypeValueInstantiation | ExprDependence::Error); @@ -6384,13 +6399,16 @@ return const_child_range(const_child_iterator(), const_child_iterator()); } - SourceLocation getBeginLoc() const LLVM_READONLY { return TypoLoc; } - SourceLocation getEndLoc() const LLVM_READONLY { return TypoLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } static bool classof(const Stmt *T) { return T->getStmtClass() == TypoExprClass; } - }; /// Frontend produces RecoveryExprs on semantic errors that prevent creating @@ -6429,7 +6447,7 @@ ArrayRef subExpressions() { auto *B = getTrailingObjects(); - return llvm::makeArrayRef(B, B + NumExprs); + return llvm::makeArrayRef(B, B + RecoveryExprBits.NumExprs); } ArrayRef subExpressions() const { @@ -6438,10 +6456,10 @@ child_range children() { Stmt **B = reinterpret_cast(getTrailingObjects()); - return child_range(B, B + NumExprs); + return child_range(B, B + RecoveryExprBits.NumExprs); } - SourceLocation getBeginLoc() const { return BeginLoc; } + SourceLocation getBeginLoc() const { return RecoveryExprBits.BeginLoc; } SourceLocation getEndLoc() const { return EndLoc; } static bool classof(const Stmt *T) { @@ -6452,12 +6470,15 @@ RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef SubExprs); RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs) - : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {} + : Expr(RecoveryExprClass, Empty) { + RecoveryExprBits.NumExprs = NumSubExprs; + } - size_t numTrailingObjects(OverloadToken) const { return NumExprs; } + size_t numTrailingObjects(OverloadToken) const { + return RecoveryExprBits.NumExprs; + } - SourceLocation BeginLoc, EndLoc; - unsigned NumExprs; + SourceLocation EndLoc; friend TrailingObjects; friend class ASTStmtReader; friend class ASTStmtWriter; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -923,8 +923,6 @@ class MSPropertyRefExpr : public Expr { Expr *BaseExpr; MSPropertyDecl *TheDecl; - SourceLocation MemberLoc; - bool IsArrow; NestedNameSpecifierLoc QualifierLoc; public: @@ -934,8 +932,9 @@ QualType ty, ExprValueKind VK, NestedNameSpecifierLoc qualifierLoc, SourceLocation nameLoc) : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary), BaseExpr(baseExpr), - TheDecl(decl), MemberLoc(nameLoc), IsArrow(isArrow), - QualifierLoc(qualifierLoc) { + TheDecl(decl), QualifierLoc(qualifierLoc) { + MSPropertyRefExprBits.IsArrow = isArrow; + MSPropertyRefExprBits.MemberLoc = nameLoc; setDependence(computeDependence(this)); } @@ -955,7 +954,7 @@ else if (QualifierLoc) return QualifierLoc.getBeginLoc(); else - return MemberLoc; + return MSPropertyRefExprBits.MemberLoc; } SourceLocation getEndLoc() const { return getMemberLoc(); } @@ -975,8 +974,10 @@ Expr *getBaseExpr() const { return BaseExpr; } MSPropertyDecl *getPropertyDecl() const { return TheDecl; } - bool isArrow() const { return IsArrow; } - SourceLocation getMemberLoc() const { return MemberLoc; } + bool isArrow() const { return MSPropertyRefExprBits.IsArrow; } + SourceLocation getMemberLoc() const { + return MSPropertyRefExprBits.MemberLoc; + } NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } }; @@ -997,7 +998,6 @@ enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 }; Stmt *SubExprs[NUM_SUBEXPRS]; - SourceLocation RBracketLoc; void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; } void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; } @@ -1005,8 +1005,8 @@ public: MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK, ExprObjectKind OK, SourceLocation RBracketLoc) - : Expr(MSPropertySubscriptExprClass, Ty, VK, OK), - RBracketLoc(RBracketLoc) { + : Expr(MSPropertySubscriptExprClass, Ty, VK, OK) { + ExprWithSLocBits.Loc = RBracketLoc; SubExprs[BASE_EXPR] = Base; SubExprs[IDX_EXPR] = Idx; setDependence(computeDependence(this)); @@ -1026,10 +1026,12 @@ return getBase()->getBeginLoc(); } - SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; } + SourceLocation getEndLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } - SourceLocation getRBracketLoc() const { return RBracketLoc; } - void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } + SourceLocation getRBracketLoc() const { return ExprWithSLocBits.Loc; } + void setRBracketLoc(SourceLocation L) { ExprWithSLocBits.Loc = L; } SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); @@ -1652,16 +1654,6 @@ private: CXXConstructorDecl *Constructor = nullptr; - /// The location of the using declaration. - SourceLocation Loc; - - /// Whether this is the construction of a virtual base. - unsigned ConstructsVirtualBase : 1; - - /// Whether the constructor is inherited from a virtual base class of the - /// class that we construct. - unsigned InheritedFromVirtualBase : 1; - public: friend class ASTStmtReader; @@ -1670,38 +1662,53 @@ CXXConstructorDecl *Ctor, bool ConstructsVirtualBase, bool InheritedFromVirtualBase) : Expr(CXXInheritedCtorInitExprClass, T, VK_PRValue, OK_Ordinary), - Constructor(Ctor), Loc(Loc), - ConstructsVirtualBase(ConstructsVirtualBase), - InheritedFromVirtualBase(InheritedFromVirtualBase) { + Constructor(Ctor) { + CXXInheritedCtorInitExprBits.Loc = Loc; + CXXInheritedCtorInitExprBits.ConstructsVirtualBase = ConstructsVirtualBase; + CXXInheritedCtorInitExprBits.InheritedFromVirtualBase = + InheritedFromVirtualBase; assert(!T->isDependentType()); setDependence(ExprDependence::None); } /// Construct an empty C++ inheriting construction expression. explicit CXXInheritedCtorInitExpr(EmptyShell Empty) - : Expr(CXXInheritedCtorInitExprClass, Empty), - ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {} + : Expr(CXXInheritedCtorInitExprClass, Empty) { + CXXInheritedCtorInitExprBits.ConstructsVirtualBase = false; + CXXInheritedCtorInitExprBits.InheritedFromVirtualBase = false; + } /// Get the constructor that this expression will call. CXXConstructorDecl *getConstructor() const { return Constructor; } /// Determine whether this constructor is actually constructing /// a base class (rather than a complete object). - bool constructsVBase() const { return ConstructsVirtualBase; } + bool constructsVBase() const { + return CXXInheritedCtorInitExprBits.ConstructsVirtualBase; + } CXXConstructExpr::ConstructionKind getConstructionKind() const { - return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase - : CXXConstructExpr::CK_NonVirtualBase; + return CXXInheritedCtorInitExprBits.ConstructsVirtualBase + ? CXXConstructExpr::CK_VirtualBase + : CXXConstructExpr::CK_NonVirtualBase; } /// Determine whether the inherited constructor is inherited from a /// virtual base of the object we construct. If so, we are not responsible /// for calling the inherited constructor (the complete object constructor /// does that), and so we don't need to pass any arguments. - bool inheritedFromVBase() const { return InheritedFromVirtualBase; } + bool inheritedFromVBase() const { + return CXXInheritedCtorInitExprBits.InheritedFromVirtualBase; + } - SourceLocation getLocation() const LLVM_READONLY { return Loc; } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getLocation() const LLVM_READONLY { + return CXXInheritedCtorInitExprBits.Loc; + } + SourceLocation getBeginLoc() const LLVM_READONLY { + return CXXInheritedCtorInitExprBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return CXXInheritedCtorInitExprBits.Loc; + } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXInheritedCtorInitExprClass; @@ -2520,13 +2527,6 @@ /// The base expression (that is being destroyed). Stmt *Base = nullptr; - /// Whether the operator was an arrow ('->'); otherwise, it was a - /// period ('.'). - bool IsArrow : 1; - - /// The location of the '.' or '->' operator. - SourceLocation OperatorLoc; - /// The nested-name-specifier that follows the operator, if present. NestedNameSpecifierLoc QualifierLoc; @@ -2555,7 +2555,9 @@ PseudoDestructorTypeStorage DestroyedType); explicit CXXPseudoDestructorExpr(EmptyShell Shell) - : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {} + : Expr(CXXPseudoDestructorExprClass, Shell) { + CXXPseudoDestructorExprBits.IsArrow = false; + } Expr *getBase() const { return cast(Base); } @@ -2577,10 +2579,12 @@ /// Determine whether this pseudo-destructor expression was written /// using an '->' (otherwise, it used a '.'). - bool isArrow() const { return IsArrow; } + bool isArrow() const { return CXXPseudoDestructorExprBits.IsArrow; } /// Retrieve the location of the '.' or '->' operator. - SourceLocation getOperatorLoc() const { return OperatorLoc; } + SourceLocation getOperatorLoc() const { + return CXXPseudoDestructorExprBits.OperatorLoc; + } /// Retrieve the scope type in a qualified pseudo-destructor /// expression. @@ -2751,8 +2755,6 @@ /// __array_extent(int, 1) == 20 /// \endcode class ArrayTypeTraitExpr : public Expr { - /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. - unsigned ATT : 2; /// The value of the type trait. Unspecified if dependent. uint64_t Value = 0; @@ -2760,9 +2762,6 @@ /// The array dimension being queried, or -1 if not used. Expr *Dimension; - /// The location of the type trait keyword. - SourceLocation Loc; - /// The location of the closing paren. SourceLocation RParen; @@ -2775,21 +2774,30 @@ ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, TypeSourceInfo *queried, uint64_t value, Expr *dimension, SourceLocation rparen, QualType ty) - : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), ATT(att), - Value(value), Dimension(dimension), Loc(loc), RParen(rparen), + : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), + Value(value), Dimension(dimension), RParen(rparen), QueriedType(queried) { assert(att <= ATT_Last && "invalid enum value!"); - assert(static_cast(att) == ATT && "ATT overflow!"); + assert(static_cast(att) == ArrayTypeTraitExprBits.ATT && + "ATT overflow!"); + ArrayTypeTraitExprBits.ATT = att; + ArrayTypeTraitExprBits.Loc = loc; setDependence(computeDependence(this)); } explicit ArrayTypeTraitExpr(EmptyShell Empty) - : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {} + : Expr(ArrayTypeTraitExprClass, Empty) { + ArrayTypeTraitExprBits.ATT = 0; + } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ArrayTypeTraitExprBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } - ArrayTypeTrait getTrait() const { return static_cast(ATT); } + ArrayTypeTrait getTrait() const { + return static_cast(ArrayTypeTraitExprBits.ATT); + } QualType getQueriedType() const { return QueriedType->getType(); } @@ -2822,13 +2830,7 @@ /// \endcode class ExpressionTraitExpr : public Expr { /// The trait. A ExpressionTrait enum in MSVC compatible unsigned. - unsigned ET : 31; - - /// The value of the type trait. Unspecified if dependent. - unsigned Value : 1; - - /// The location of the type trait keyword. - SourceLocation Loc; + unsigned ET; /// The location of the closing paren. SourceLocation RParen; @@ -2842,24 +2844,29 @@ ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried, bool value, SourceLocation rparen, QualType resultType) : Expr(ExpressionTraitExprClass, resultType, VK_PRValue, OK_Ordinary), - ET(et), Value(value), Loc(loc), RParen(rparen), - QueriedExpression(queried) { + ET(et), RParen(rparen), QueriedExpression(queried) { assert(et <= ET_Last && "invalid enum value!"); assert(static_cast(et) == ET && "ET overflow!"); + ExpressionTraitExprBits.Value = value; + ExpressionTraitExprBits.Loc = loc; setDependence(computeDependence(this)); } explicit ExpressionTraitExpr(EmptyShell Empty) - : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {} + : Expr(ExpressionTraitExprClass, Empty), ET(0) { + ExpressionTraitExprBits.Value = 0; + } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExpressionTraitExprBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } ExpressionTrait getTrait() const { return static_cast(ET); } Expr *getQueriedExpression() const { return QueriedExpression; } - bool getValue() const { return Value; } + bool getValue() const { return ExpressionTraitExprBits.Value; } static bool classof(const Stmt *T) { return T->getStmtClass() == ExpressionTraitExprClass; @@ -3998,14 +4005,15 @@ friend class ASTStmtReader; Stmt *Operand; - SourceRange Range; + SourceLocation RParenLoc; public: CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, SourceLocation Keyword, SourceLocation RParen) : Expr(CXXNoexceptExprClass, Ty, VK_PRValue, OK_Ordinary), - Operand(Operand), Range(Keyword, RParen) { + Operand(Operand), RParenLoc(RParen) { CXXNoexceptExprBits.Value = Val == CT_Cannot; + CXXNoexceptExprBits.KeywordLoc = Keyword; setDependence(computeDependence(this, Val)); } @@ -4013,9 +4021,11 @@ Expr *getOperand() const { return static_cast(Operand); } - SourceLocation getBeginLoc() const { return Range.getBegin(); } - SourceLocation getEndLoc() const { return Range.getEnd(); } - SourceRange getSourceRange() const { return Range; } + SourceLocation getBeginLoc() const { return CXXNoexceptExprBits.KeywordLoc; } + SourceLocation getEndLoc() const { return RParenLoc; } + SourceRange getSourceRange() const { + return {CXXNoexceptExprBits.KeywordLoc, RParenLoc}; + } bool getValue() const { return CXXNoexceptExprBits.Value; } @@ -4577,14 +4587,12 @@ enum SubExpr { Callee, LHS, RHS, Count }; - SourceLocation LParenLoc; SourceLocation EllipsisLoc; SourceLocation RParenLoc; // When 0, the number of expansions is not known. Otherwise, this is one more // than the number of expansions. unsigned NumExpansions; Stmt *SubExprs[SubExpr::Count]; - BinaryOperatorKind Opcode; public: CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee, @@ -4592,8 +4600,10 @@ SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, Optional NumExpansions) : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary), - LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), - NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) { + EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), + NumExpansions(NumExpansions ? *NumExpansions + 1 : 0) { + CXXFoldExprBits.LParenLoc = LParenLoc; + CXXFoldExprBits.Opcode = Opcode; SubExprs[SubExpr::Callee] = Callee; SubExprs[SubExpr::LHS] = LHS; SubExprs[SubExpr::RHS] = RHS; @@ -4622,10 +4632,12 @@ /// Get the operand that doesn't contain a pack, for a binary fold. Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); } - SourceLocation getLParenLoc() const { return LParenLoc; } + SourceLocation getLParenLoc() const { return CXXFoldExprBits.LParenLoc; } SourceLocation getRParenLoc() const { return RParenLoc; } SourceLocation getEllipsisLoc() const { return EllipsisLoc; } - BinaryOperatorKind getOperator() const { return Opcode; } + BinaryOperatorKind getOperator() const { + return BinaryOperatorKind(CXXFoldExprBits.Opcode); + } Optional getNumExpansions() const { if (NumExpansions) @@ -4634,8 +4646,8 @@ } SourceLocation getBeginLoc() const LLVM_READONLY { - if (LParenLoc.isValid()) - return LParenLoc; + if (CXXFoldExprBits.LParenLoc.isValid()) + return CXXFoldExprBits.LParenLoc; if (isLeftFold()) return getEllipsisLoc(); return getLHS()->getBeginLoc(); @@ -4679,8 +4691,6 @@ class CoroutineSuspendExpr : public Expr { friend class ASTStmtReader; - SourceLocation KeywordLoc; - enum SubExpr { Common, Ready, Suspend, Resume, Count }; Stmt *SubExprs[SubExpr::Count]; @@ -4692,7 +4702,8 @@ OpaqueValueExpr *OpaqueValue) : Expr(SC, Resume->getType(), Resume->getValueKind(), Resume->getObjectKind()), - KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { + OpaqueValue(OpaqueValue) { + CoroutineSuspendExprBits.KeywordLoc = KeywordLoc; SubExprs[SubExpr::Common] = Common; SubExprs[SubExpr::Ready] = Ready; SubExprs[SubExpr::Suspend] = Suspend; @@ -4702,9 +4713,10 @@ CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty, Expr *Common) - : Expr(SC, Ty, VK_PRValue, OK_Ordinary), KeywordLoc(KeywordLoc) { + : Expr(SC, Ty, VK_PRValue, OK_Ordinary) { assert(Common->isTypeDependent() && Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression"); + CoroutineSuspendExprBits.KeywordLoc = KeywordLoc; SubExprs[SubExpr::Common] = Common; SubExprs[SubExpr::Ready] = nullptr; SubExprs[SubExpr::Suspend] = nullptr; @@ -4719,7 +4731,9 @@ SubExprs[SubExpr::Resume] = nullptr; } - SourceLocation getKeywordLoc() const { return KeywordLoc; } + SourceLocation getKeywordLoc() const { + return CoroutineSuspendExprBits.KeywordLoc; + } Expr *getCommonExpr() const { return static_cast(SubExprs[SubExpr::Common]); @@ -4740,7 +4754,9 @@ return static_cast(SubExprs[SubExpr::Resume]); } - SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return CoroutineSuspendExprBits.KeywordLoc; + } SourceLocation getEndLoc() const LLVM_READONLY { return getCommonExpr()->getEndLoc(); @@ -4800,18 +4816,17 @@ class DependentCoawaitExpr : public Expr { friend class ASTStmtReader; - SourceLocation KeywordLoc; Stmt *SubExprs[2]; public: DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op, UnresolvedLookupExpr *OpCoawait) - : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary), - KeywordLoc(KeywordLoc) { + : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary) { // NOTE: A co_await expression is dependent on the coroutines promise // type and may be dependent even when the `Op` expression is not. assert(Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression"); + ExprWithSLocBits.Loc = KeywordLoc; SubExprs[0] = Op; SubExprs[1] = OpCoawait; setDependence(computeDependence(this)); @@ -4826,9 +4841,11 @@ return cast(SubExprs[1]); } - SourceLocation getKeywordLoc() const { return KeywordLoc; } + SourceLocation getKeywordLoc() const { return ExprWithSLocBits.Loc; } - SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return getOperand()->getEndLoc(); diff --git a/clang/include/clang/AST/ExprObjC.h b/clang/include/clang/AST/ExprObjC.h --- a/clang/include/clang/AST/ExprObjC.h +++ b/clang/include/clang/AST/ExprObjC.h @@ -51,12 +51,11 @@ /// i.e. @"foo". class ObjCStringLiteral : public Expr { Stmt *String; - SourceLocation AtLoc; public: ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) - : Expr(ObjCStringLiteralClass, T, VK_PRValue, OK_Ordinary), String(SL), - AtLoc(L) { + : Expr(ObjCStringLiteralClass, T, VK_PRValue, OK_Ordinary), String(SL) { + ExprWithSLocBits.Loc = L; setDependence(ExprDependence::None); } explicit ObjCStringLiteral(EmptyShell Empty) @@ -66,10 +65,12 @@ const StringLiteral *getString() const { return cast(String); } void setString(StringLiteral *S) { String = S; } - SourceLocation getAtLoc() const { return AtLoc; } - void setAtLoc(SourceLocation L) { AtLoc = L; } + SourceLocation getAtLoc() const { return ExprWithSLocBits.Loc; } + void setAtLoc(SourceLocation L) { ExprWithSLocBits.Loc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return String->getEndLoc(); } // Iterators @@ -86,26 +87,28 @@ /// ObjCBoolLiteralExpr - Objective-C Boolean Literal. class ObjCBoolLiteralExpr : public Expr { - bool Value; - SourceLocation Loc; - public: ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) - : Expr(ObjCBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary), Value(val), - Loc(l) { + : Expr(ObjCBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { + ObjCBoolLiteralExprBits.Value = val; + ObjCBoolLiteralExprBits.Loc = l; setDependence(ExprDependence::None); } explicit ObjCBoolLiteralExpr(EmptyShell Empty) : Expr(ObjCBoolLiteralExprClass, Empty) {} - bool getValue() const { return Value; } - void setValue(bool V) { Value = V; } + bool getValue() const { return ObjCBoolLiteralExprBits.Value; } + void setValue(bool V) { ObjCBoolLiteralExprBits.Value = V; } - SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ObjCBoolLiteralExprBits.Loc; + } + SourceLocation getEndLoc() const LLVM_READONLY { + return ObjCBoolLiteralExprBits.Loc; + } - SourceLocation getLocation() const { return Loc; } - void setLocation(SourceLocation L) { Loc = L; } + SourceLocation getLocation() const { return ObjCBoolLiteralExprBits.Loc; } + void setLocation(SourceLocation L) { ObjCBoolLiteralExprBits.Loc = L; } // Iterators child_range children() { @@ -190,7 +193,6 @@ class ObjCArrayLiteral final : public Expr, private llvm::TrailingObjects { - unsigned NumElements; SourceRange Range; ObjCMethodDecl *ArrayWithObjectsMethod; @@ -199,7 +201,9 @@ SourceRange SR); explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements) - : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {} + : Expr(ObjCArrayLiteralClass, Empty) { + ObjCArrayLiteralBits.NumElements = NumElements; + } public: friend class ASTStmtReader; @@ -226,15 +230,17 @@ } /// getNumElements - Return number of elements of objective-c array literal. - unsigned getNumElements() const { return NumElements; } + unsigned getNumElements() const { return ObjCArrayLiteralBits.NumElements; } /// getElement - Return the Element at the specified index. Expr *getElement(unsigned Index) { - assert((Index < NumElements) && "Arg access out of range!"); + assert((Index < ObjCArrayLiteralBits.NumElements) && + "Arg access out of range!"); return getElements()[Index]; } const Expr *getElement(unsigned Index) const { - assert((Index < NumElements) && "Arg access out of range!"); + assert((Index < ObjCArrayLiteralBits.NumElements) && + "Arg access out of range!"); return getElements()[Index]; } @@ -245,7 +251,8 @@ // Iterators child_range children() { return child_range(reinterpret_cast(getElements()), - reinterpret_cast(getElements()) + NumElements); + reinterpret_cast(getElements()) + + ObjCArrayLiteralBits.NumElements); } const_child_range children() const { @@ -308,17 +315,6 @@ private llvm::TrailingObjects { - /// The number of elements in this dictionary literal. - unsigned NumElements : 31; - - /// Determine whether this dictionary literal has any pack expansions. - /// - /// If the dictionary literal has pack expansions, then there will - /// be an array of pack expansion data following the array of - /// key/value pairs, which provide the locations of the ellipses (if - /// any) and number of elements in the expansion (if known). If - /// there are no pack expansions, we optimize away this storage. - unsigned HasPackExpansions : 1; SourceRange Range; ObjCMethodDecl *DictWithObjectsMethod; @@ -333,11 +329,13 @@ explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements, bool HasPackExpansions) - : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements), - HasPackExpansions(HasPackExpansions) {} + : Expr(ObjCDictionaryLiteralClass, Empty) { + ObjCDictionaryLiteralBits.NumElements = NumElements; + ObjCDictionaryLiteralBits.HasPackExpansions = HasPackExpansions; + } size_t numTrailingObjects(OverloadToken) const { - return NumElements; + return ObjCDictionaryLiteralBits.NumElements; } public: @@ -357,13 +355,16 @@ /// getNumElements - Return number of elements of objective-c dictionary /// literal. - unsigned getNumElements() const { return NumElements; } + unsigned getNumElements() const { + return ObjCDictionaryLiteralBits.NumElements; + } ObjCDictionaryElement getKeyValueElement(unsigned Index) const { - assert((Index < NumElements) && "Arg access out of range!"); + assert((Index < ObjCDictionaryLiteralBits.NumElements) && + "Arg access out of range!"); const KeyValuePair &KV = getTrailingObjects()[Index]; ObjCDictionaryElement Result = { KV.Key, KV.Value, SourceLocation(), None }; - if (HasPackExpansions) { + if (ObjCDictionaryLiteralBits.HasPackExpansions) { const ExpansionData &Expansion = getTrailingObjects()[Index]; Result.EllipsisLoc = Expansion.EllipsisLoc; @@ -390,7 +391,7 @@ return child_range( reinterpret_cast(getTrailingObjects()), reinterpret_cast(getTrailingObjects()) + - NumElements * 2); + ObjCDictionaryLiteralBits.NumElements * 2); } const_child_range children() const { @@ -503,7 +504,7 @@ /// The return type is "Protocol*". class ObjCProtocolExpr : public Expr { ObjCProtocolDecl *TheProtocol; - SourceLocation AtLoc, ProtoLoc, RParenLoc; + SourceLocation ProtoLoc, RParenLoc; public: friend class ASTStmtReader; @@ -512,7 +513,8 @@ ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, SourceLocation at, SourceLocation protoLoc, SourceLocation rp) : Expr(ObjCProtocolExprClass, T, VK_PRValue, OK_Ordinary), - TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) { + TheProtocol(protocol), ProtoLoc(protoLoc), RParenLoc(rp) { + ExprWithSLocBits.Loc = at; setDependence(ExprDependence::None); } explicit ObjCProtocolExpr(EmptyShell Empty) @@ -522,12 +524,14 @@ void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; } SourceLocation getProtocolIdLoc() const { return ProtoLoc; } - SourceLocation getAtLoc() const { return AtLoc; } + SourceLocation getAtLoc() const { return ExprWithSLocBits.Loc; } SourceLocation getRParenLoc() const { return RParenLoc; } - void setAtLoc(SourceLocation L) { AtLoc = L; } + void setAtLoc(SourceLocation L) { ExprWithSLocBits.Loc = L; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } // Iterators @@ -548,25 +552,20 @@ class ObjCIvarRefExpr : public Expr { ObjCIvarDecl *D; Stmt *Base; - SourceLocation Loc; /// OpLoc - This is the location of '.' or '->' SourceLocation OpLoc; - // True if this is "X->F", false if this is "X.F". - bool IsArrow : 1; - - // True if ivar reference has no base (self assumed). - bool IsFreeIvar : 1; - public: ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, SourceLocation oploc, Expr *base, bool arrow = false, bool freeIvar = false) : Expr(ObjCIvarRefExprClass, t, VK_LValue, d->isBitField() ? OK_BitField : OK_Ordinary), - D(d), Base(base), Loc(l), OpLoc(oploc), IsArrow(arrow), - IsFreeIvar(freeIvar) { + D(d), Base(base), OpLoc(oploc) { + ObjCIvarRefExprBits.Loc = l; + ObjCIvarRefExprBits.IsArrow = arrow; + ObjCIvarRefExprBits.IsFreeIvar = freeIvar; setDependence(computeDependence(this)); } @@ -581,18 +580,20 @@ Expr *getBase() { return cast(Base); } void setBase(Expr * base) { Base = base; } - bool isArrow() const { return IsArrow; } - bool isFreeIvar() const { return IsFreeIvar; } - void setIsArrow(bool A) { IsArrow = A; } - void setIsFreeIvar(bool A) { IsFreeIvar = A; } + bool isArrow() const { return ObjCIvarRefExprBits.IsArrow; } + bool isFreeIvar() const { return ObjCIvarRefExprBits.IsFreeIvar; } + void setIsArrow(bool A) { ObjCIvarRefExprBits.IsArrow = A; } + void setIsFreeIvar(bool A) { ObjCIvarRefExprBits.IsFreeIvar = A; } - SourceLocation getLocation() const { return Loc; } - void setLocation(SourceLocation L) { Loc = L; } + SourceLocation getLocation() const { return ObjCIvarRefExprBits.Loc; } + void setLocation(SourceLocation L) { ObjCIvarRefExprBits.Loc = L; } SourceLocation getBeginLoc() const LLVM_READONLY { - return isFreeIvar() ? Loc : getBase()->getBeginLoc(); + return isFreeIvar() ? ObjCIvarRefExprBits.Loc : getBase()->getBeginLoc(); + } + SourceLocation getEndLoc() const LLVM_READONLY { + return ObjCIvarRefExprBits.Loc; } - SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } SourceLocation getOpLoc() const { return OpLoc; } void setOpLoc(SourceLocation L) { OpLoc = L; } @@ -839,9 +840,6 @@ /// ObjCSubscriptRefExpr - used for array and dictionary subscripting. /// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; class ObjCSubscriptRefExpr : public Expr { - // Location of ']' in an indexing expression. - SourceLocation RBracket; - // array/dictionary base expression. // for arrays, this is a numeric expression. For dictionaries, this is // an objective-c object pointer expression. @@ -858,8 +856,9 @@ ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, ExprValueKind VK, ExprObjectKind OK, ObjCMethodDecl *getMethod, ObjCMethodDecl *setMethod, SourceLocation RB) - : Expr(ObjCSubscriptRefExprClass, T, VK, OK), RBracket(RB), + : Expr(ObjCSubscriptRefExprClass, T, VK, OK), GetAtIndexMethodDecl(getMethod), SetAtIndexMethodDecl(setMethod) { + ExprWithSLocBits.Loc = RB; SubExprs[BASE] = base; SubExprs[KEY] = key; setDependence(computeDependence(this)); @@ -868,14 +867,16 @@ explicit ObjCSubscriptRefExpr(EmptyShell Empty) : Expr(ObjCSubscriptRefExprClass, Empty) {} - SourceLocation getRBracket() const { return RBracket; } - void setRBracket(SourceLocation RB) { RBracket = RB; } + SourceLocation getRBracket() const { return ExprWithSLocBits.Loc; } + void setRBracket(SourceLocation RB) { ExprWithSLocBits.Loc = RB; } SourceLocation getBeginLoc() const LLVM_READONLY { return SubExprs[BASE]->getBeginLoc(); } - SourceLocation getEndLoc() const LLVM_READONLY { return RBracket; } + SourceLocation getEndLoc() const LLVM_READONLY { + return ExprWithSLocBits.Loc; + } Expr *getBaseExpr() const { return cast(SubExprs[BASE]); } void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; } @@ -1483,20 +1484,16 @@ /// Base - the expression for the base object pointer. Stmt *Base; - /// IsaMemberLoc - This is the location of the 'isa'. - SourceLocation IsaMemberLoc; - /// OpLoc - This is the location of '.' or '->' SourceLocation OpLoc; - /// IsArrow - True if this is "X->F", false if this is "X.F". - bool IsArrow; - public: ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc, QualType ty) : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary), Base(base), - IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) { + OpLoc(oploc) { + ObjCIsaExprBits.IsArrow = isarrow; + ObjCIsaExprBits.IsaMemberLoc = l; setDependence(computeDependence(this)); } @@ -1506,13 +1503,15 @@ void setBase(Expr *E) { Base = E; } Expr *getBase() const { return cast(Base); } - bool isArrow() const { return IsArrow; } - void setArrow(bool A) { IsArrow = A; } + bool isArrow() const { return ObjCIsaExprBits.IsArrow; } + void setArrow(bool A) { ObjCIsaExprBits.IsArrow = A; } /// getMemberLoc - Return the location of the "member", in X->F, it is the /// location of 'F'. - SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } - void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } + SourceLocation getIsaMemberLoc() const { + return ObjCIsaExprBits.IsaMemberLoc; + } + void setIsaMemberLoc(SourceLocation L) { ObjCIsaExprBits.IsaMemberLoc = L; } SourceLocation getOpLoc() const { return OpLoc; } void setOpLoc(SourceLocation L) { OpLoc = L; } @@ -1525,9 +1524,13 @@ return getBase()->getEndLoc(); } - SourceLocation getEndLoc() const LLVM_READONLY { return IsaMemberLoc; } + SourceLocation getEndLoc() const LLVM_READONLY { + return ObjCIsaExprBits.IsaMemberLoc; + } - SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; } + SourceLocation getExprLoc() const LLVM_READONLY { + return ObjCIsaExprBits.IsaMemberLoc; + } // Iterators child_range children() { return child_range(&Base, &Base+1); } @@ -1630,9 +1633,7 @@ friend class CastExpr; friend TrailingObjects; - SourceLocation LParenLoc; SourceLocation BridgeKeywordLoc; - unsigned Kind : 2; public: ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, @@ -1640,17 +1641,22 @@ TypeSourceInfo *TSInfo, Expr *Operand) : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(), VK_PRValue, CK, Operand, 0, false, TSInfo), - LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) {} + BridgeKeywordLoc(BridgeKeywordLoc) { + ObjCBridgedCastExprBits.LParenLoc = LParenLoc; + ObjCBridgedCastExprBits.Kind = Kind; + } /// Construct an empty Objective-C bridged cast. explicit ObjCBridgedCastExpr(EmptyShell Shell) : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0, false) {} - SourceLocation getLParenLoc() const { return LParenLoc; } + SourceLocation getLParenLoc() const { + return ObjCBridgedCastExprBits.LParenLoc; + } /// Determine which kind of bridge is being performed via this cast. ObjCBridgeCastKind getBridgeKind() const { - return static_cast(Kind); + return static_cast(ObjCBridgedCastExprBits.Kind); } /// Retrieve the kind of bridge being performed as a string. @@ -1659,7 +1665,9 @@ /// The location of the bridge keyword. SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; } - SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; } + SourceLocation getBeginLoc() const LLVM_READONLY { + return ObjCBridgedCastExprBits.LParenLoc; + } SourceLocation getEndLoc() const LLVM_READONLY { return getSubExpr()->getEndLoc(); diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -316,6 +316,25 @@ }; enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth }; + class ExprWithSLocBitfields { + friend class ASTStmtReader; + friend class SYCLUniqueStableNameExpr; + friend class ParenExpr; + friend class AddrLabelExpr; + friend class AbstractConditionalOperator; + friend class GNUNullExpr; + friend class ExtVectorElementExpr; + friend class TypoExpr; + friend class DependentCoawaitExpr; + friend class MSPropertySubscriptExpr; + friend class ObjCStringLiteral; + friend class ObjCProtocolExpr; + friend class ObjCSubscriptRefExpr; + + unsigned : NumExprBits; + SourceLocation Loc; + }; + class ConstantExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -389,6 +408,18 @@ unsigned Semantics : 3; // Provides semantics for APFloat construction unsigned IsExact : 1; + + SourceLocation Loc; + }; + + class FixedPointLiteralBitfields { + friend class FixedPointLiteral; + + unsigned : NumExprBits; + + unsigned Scale : 8; + + SourceLocation Loc; }; class StringLiteralBitfields { @@ -419,6 +450,8 @@ unsigned : NumExprBits; unsigned Kind : 3; + + unsigned Value; }; class UnaryOperatorBitfields { @@ -437,6 +470,14 @@ SourceLocation Loc; }; + class OffsetOfExprBitfields { + friend class OffsetOfExpr; + + unsigned : NumExprBits; + unsigned NumComps : 16; + unsigned NumExprs : 16; + }; + class UnaryExprOrTypeTraitExprBitfields { friend class UnaryExprOrTypeTraitExpr; @@ -444,6 +485,8 @@ unsigned Kind : 3; unsigned IsType : 1; // true if operand is a type, false if an expression. + + SourceLocation OpLoc; }; class ArrayOrMatrixSubscriptExprBitfields { @@ -513,6 +556,17 @@ SourceLocation OperatorLoc; }; + class CompoundLiteralExprBitfields { + friend class CompoundLiteralExpr; + + unsigned : NumExprBits; + + /// LParenLoc - If non-null, this is the location of the left paren in a + /// compound literal like "(int){4}". This can be null if this is a + /// synthesized compound expression. + SourceLocation LParenLoc; + }; + class CastExprBitfields { friend class CastExpr; friend class ImplicitCastExpr; @@ -545,6 +599,14 @@ SourceLocation OpLoc; }; + class ShuffleVectorExprBitfields { + friend class ShuffleVectorExpr; + + unsigned : NumExprBits; + + unsigned NumExprs; + }; + class InitListExprBitfields { friend class InitListExpr; @@ -553,6 +615,8 @@ /// Whether this initializer list originally had a GNU array-range /// designator in it. This is a temporary marker used by CodeGen. unsigned HadArrayRangeDesignator : 1; + + SourceLocation LBraceLoc; }; class ParenListExprBitfields { @@ -596,6 +660,49 @@ /// The kind of source location builtin represented by the SourceLocExpr. /// Ex. __builtin_LINE, __builtin_FUNCTION, ect. unsigned Kind : 2; + + SourceLocation BuiltinLoc; + }; + + class DesignatedInitExprBitfields { + friend class ASTStmtReader; + friend class DesignatedInitExpr; + + unsigned : NumExprBits; + + /// Whether this designated initializer used the GNU deprecated + /// syntax rather than the C99 '=' syntax. + unsigned GNUSyntax : 1; + + /// The number of designators in this initializer expression. + unsigned NumDesignators : 15; + + /// The number of subexpressions of this initializer expression, + /// which contains both the initializer and any additional + /// expressions used by array and array-range designators. + unsigned NumSubExprs : 16; + }; + + class AtomicExprBitfields { + friend class ASTStmtReader; + friend class AtomicExpr; + + unsigned : NumExprBits; + + unsigned Op : 6; + + unsigned NumSubExprs; + }; + + class RecoveryExprBitfields { + friend class ASTStmtReader; + friend class RecoveryExpr; + + unsigned : NumExprBits; + + unsigned NumExprs : 32 - NumExprBits; + + SourceLocation BeginLoc; }; class StmtExprBitfields { @@ -610,6 +717,15 @@ unsigned TemplateDepth; }; + class ChooseExprBitfields { + friend class ASTStmtReader; + friend class ChooseExpr; + + unsigned : NumExprBits; + unsigned CondIsTrue : 1; + SourceLocation BuiltinLoc; + }; + //===--- C++ Expression bitfields classes ---===// class CXXOperatorCallExprBitfields { @@ -653,6 +769,16 @@ SourceLocation Loc; }; + class MSPropertyRefExprBitfields { + friend class ASTStmtReader; + friend class MSPropertyRefExpr; + + unsigned : NumExprBits; + + unsigned IsArrow : 1; + SourceLocation MemberLoc; + }; + class CXXThisExprBitfields { friend class CXXThisExpr; @@ -765,6 +891,20 @@ SourceLocation Loc; }; + class CXXPseudoDestructorExprBitfields { + friend class ASTStmtReader; + friend class CXXPseudoDestructorExpr; + + unsigned : NumExprBits; + + /// Whether the operator was an arrow ('->'); otherwise, it was a + /// period ('.'). + unsigned IsArrow : 1; + + /// The location of the '.' or '->' operator. + SourceLocation OperatorLoc; + }; + class TypeTraitExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -785,6 +925,30 @@ unsigned NumArgs; }; + class ArrayTypeTraitExprBitfields { + friend class ASTStmtReader; + friend class ArrayTypeTraitExpr; + + unsigned : NumExprBits; + + /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. + unsigned ATT : 2; + /// The location of the type trait keyword. + SourceLocation Loc; + }; + + class ExpressionTraitExprBitfields { + friend class ASTStmtReader; + friend class ExpressionTraitExpr; + + unsigned : NumExprBits; + /// The value of the type trait. Unspecified if dependent. + unsigned Value : 1; + + /// The location of the type trait keyword. + SourceLocation Loc; + }; + class DependentScopeDeclRefExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -813,6 +977,22 @@ SourceLocation Loc; }; + class CXXInheritedCtorInitExprBitfields { + friend class ASTStmtReader; + friend class CXXInheritedCtorInitExpr; + unsigned : NumExprBits; + + /// Whether this is the construction of a virtual base. + unsigned ConstructsVirtualBase : 1; + + /// Whether the constructor is inherited from a virtual base class of the + /// class that we construct. + unsigned InheritedFromVirtualBase : 1; + + /// The location of the using declaration. + SourceLocation Loc; + }; + class ExprWithCleanupsBitfields { friend class ASTStmtReader; // deserialization friend class ExprWithCleanups; @@ -919,6 +1099,8 @@ unsigned : NumExprBits; unsigned Value : 1; + + SourceLocation KeywordLoc; }; class SubstNonTypeTemplateParmExprBitfields { @@ -953,6 +1135,15 @@ unsigned NumCaptures : 16; }; + class CXXFoldExprBitfields { + friend class ASTStmtReader; + friend class CXXFoldExpr; + + unsigned : NumExprBits; + unsigned Opcode : 6; + SourceLocation LParenLoc; + }; + class RequiresExprBitfields { friend class ASTStmtReader; friend class ASTStmtWriter; @@ -966,14 +1157,31 @@ //===--- C++ Coroutines TS bitfields classes ---===// + class CoroutineSuspendExprBitfields { + friend class CoroutineSuspendExpr; + friend class ASTStmtReader; + + unsigned : NumExprBits; + + unsigned : 32 - NumExprBits; + + SourceLocation KeywordLoc; + }; + + enum { NumCoroutineSuspendExprBits = NumExprBits }; + class CoawaitExprBitfields { friend class CoawaitExpr; - unsigned : NumExprBits; + unsigned : NumCoroutineSuspendExprBits; unsigned IsImplicit : 1; }; + static_assert(sizeof(CoawaitExprBitfields) <= 4, + "CoawaitExprBitfields must be <= than 4 bytes to" + "avoid trashing CoroutineSuspendExprBitfields::KeywordLoc!"); + //===--- Obj-C Expression bitfields classes ---===// class ObjCIndirectCopyRestoreExprBitfields { @@ -984,6 +1192,79 @@ unsigned ShouldCopy : 1; }; + class ObjCBoolLiteralExprBitfields { + friend class ObjCBoolLiteralExpr; + + unsigned : NumExprBits; + + unsigned Value : 1; + SourceLocation Loc; + }; + + class ObjCArrayLiteralBitfields { + friend class ObjCArrayLiteral; + + unsigned : NumExprBits; + + unsigned NumElements; + }; + + class ObjCDictionaryLiteralBitfields { + friend class ASTStmtReader; + friend class ASTStmtWriter; + friend class ObjCDictionaryLiteral; + + unsigned : NumExprBits; + + /// Determine whether this dictionary literal has any pack expansions. + /// + /// If the dictionary literal has pack expansions, then there will + /// be an array of pack expansion data following the array of + /// key/value pairs, which provide the locations of the ellipses (if + /// any) and number of elements in the expansion (if known). If + /// there are no pack expansions, we optimize away this storage. + unsigned HasPackExpansions : 1; + + /// The number of elements in this dictionary literal. + unsigned NumElements; + }; + + class ObjCIvarRefExprBitfields { + friend class ObjCIvarRefExpr; + + unsigned : NumExprBits; + + // True if this is "X->F", false if this is "X.F". + unsigned IsArrow : 1; + + // True if ivar reference has no base (self assumed). + unsigned IsFreeIvar : 1; + + SourceLocation Loc; + }; + + class ObjCIsaExprBitfields { + friend class ObjCIsaExpr; + + unsigned : NumExprBits; + + /// IsArrow - True if this is "X->F", false if this is "X.F". + unsigned IsArrow : 1; + + /// IsaMemberLoc - This is the location of the 'isa'. + SourceLocation IsaMemberLoc; + }; + + class ObjCBridgedCastExprBitfields { + friend class ASTStmtReader; + friend class ObjCBridgedCastExpr; + + unsigned : NumExprBits; + + unsigned Kind : 2; + SourceLocation LParenLoc; + }; + //===--- Clang Extensions bitfields classes ---===// class OpaqueValueExprBitfields { @@ -1020,33 +1301,43 @@ // Expressions ExprBitfields ExprBits; + ExprWithSLocBitfields ExprWithSLocBits; ConstantExprBitfields ConstantExprBits; PredefinedExprBitfields PredefinedExprBits; DeclRefExprBitfields DeclRefExprBits; FloatingLiteralBitfields FloatingLiteralBits; + FixedPointLiteralBitfields FixedPointLiteralBits; StringLiteralBitfields StringLiteralBits; CharacterLiteralBitfields CharacterLiteralBits; UnaryOperatorBitfields UnaryOperatorBits; + OffsetOfExprBitfields OffsetOfExprBits; UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits; CallExprBitfields CallExprBits; MemberExprBitfields MemberExprBits; + CompoundLiteralExprBitfields CompoundLiteralExprBits; CastExprBitfields CastExprBits; BinaryOperatorBitfields BinaryOperatorBits; + ShuffleVectorExprBitfields ShuffleVectorExprBits; InitListExprBitfields InitListExprBits; ParenListExprBitfields ParenListExprBits; GenericSelectionExprBitfields GenericSelectionExprBits; PseudoObjectExprBitfields PseudoObjectExprBits; SourceLocExprBitfields SourceLocExprBits; + DesignatedInitExprBitfields DesignatedInitExprBits; + AtomicExprBitfields AtomicExprBits; + RecoveryExprBitfields RecoveryExprBits; // GNU Extensions. StmtExprBitfields StmtExprBits; + ChooseExprBitfields ChooseExprBits; // C++ Expressions CXXOperatorCallExprBitfields CXXOperatorCallExprBits; CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits; CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits; CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits; + MSPropertyRefExprBitfields MSPropertyRefExprBits; CXXThisExprBitfields CXXThisExprBits; CXXThrowExprBitfields CXXThrowExprBits; CXXDefaultArgExprBitfields CXXDefaultArgExprBits; @@ -1054,9 +1345,13 @@ CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits; CXXNewExprBitfields CXXNewExprBits; CXXDeleteExprBitfields CXXDeleteExprBits; + CXXPseudoDestructorExprBitfields CXXPseudoDestructorExprBits; TypeTraitExprBitfields TypeTraitExprBits; + ArrayTypeTraitExprBitfields ArrayTypeTraitExprBits; + ExpressionTraitExprBitfields ExpressionTraitExprBits; DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits; CXXConstructExprBitfields CXXConstructExprBits; + CXXInheritedCtorInitExprBitfields CXXInheritedCtorInitExprBits; ExprWithCleanupsBitfields ExprWithCleanupsBits; CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits; CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits; @@ -1066,13 +1361,21 @@ CXXNoexceptExprBitfields CXXNoexceptExprBits; SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits; LambdaExprBitfields LambdaExprBits; + CXXFoldExprBitfields CXXFoldExprBits; RequiresExprBitfields RequiresExprBits; // C++ Coroutines TS expressions + CoroutineSuspendExprBitfields CoroutineSuspendExprBits; CoawaitExprBitfields CoawaitBits; // Obj-C Expressions ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; + ObjCBoolLiteralExprBitfields ObjCBoolLiteralExprBits; + ObjCArrayLiteralBitfields ObjCArrayLiteralBits; + ObjCDictionaryLiteralBitfields ObjCDictionaryLiteralBits; + ObjCIvarRefExprBitfields ObjCIvarRefExprBits; + ObjCIsaExprBitfields ObjCIsaExprBits; + ObjCBridgedCastExprBitfields ObjCBridgedCastExprBits; // Clang Extensions OpaqueValueExprBitfields OpaqueValueExprBits; diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -529,7 +529,8 @@ QualType ResultTy, TypeSourceInfo *TSI) : Expr(SYCLUniqueStableNameExprClass, ResultTy, VK_PRValue, OK_Ordinary), - OpLoc(OpLoc), LParen(LParen), RParen(RParen) { + LParen(LParen), RParen(RParen) { + ExprWithSLocBits.Loc = OpLoc; setTypeSourceInfo(TSI); setDependence(computeDependence(this)); } @@ -909,11 +910,12 @@ FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale) - : Expr(FixedPointLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l), - Scale(Scale) { + : Expr(FixedPointLiteralClass, type, VK_PRValue, OK_Ordinary) { assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral"); assert(V.getBitWidth() == C.getTypeInfo(type).Width && "Fixed point type is not the correct size for constant."); + FixedPointLiteralBits.Loc = l; + FixedPointLiteralBits.Scale = Scale; setValue(C, V); setDependence(ExprDependence::None); } @@ -936,8 +938,9 @@ // unsigned long _Accum: 4294967295.99999999976716935634613037109375 // which is 43 characters. SmallString<64> S; - FixedPointValueToString( - S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale); + FixedPointValueToString(S, + llvm::APSInt::getUnsigned(getValue().getZExtValue()), + FixedPointLiteralBits.Scale); return std::string(S.str()); } @@ -1013,9 +1016,10 @@ FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L) - : Expr(FloatingLiteralClass, Type, VK_PRValue, OK_Ordinary), Loc(L) { + : Expr(FloatingLiteralClass, Type, VK_PRValue, OK_Ordinary) { setSemantics(V.getSemantics()); FloatingLiteralBits.IsExact = isexact; + FloatingLiteralBits.Loc = L; setValue(C, V); setDependence(ExprDependence::None); } @@ -1609,8 +1613,9 @@ ArrayRef comps, ArrayRef exprs, SourceLocation RParenLoc) : Expr(OffsetOfExprClass, type, VK_PRValue, OK_Ordinary), - OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), - NumComps(comps.size()), NumExprs(exprs.size()) { + OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi) { + OffsetOfExprBits.NumComps = comps.size(); + OffsetOfExprBits.NumExprs = exprs.size(); for (unsigned i = 0; i != comps.size(); ++i) setComponent(i, comps[i]); for (unsigned i = 0; i != exprs.size(); ++i) @@ -1631,9 +1636,10 @@ UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType, SourceLocation op, SourceLocation rp) : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue, OK_Ordinary), - OpLoc(op), RParenLoc(rp) { + RParenLoc(rp) { assert(ExprKind <= UETT_Last && "invalid enum value!"); UnaryExprOrTypeTraitExprBits.Kind = ExprKind; + UnaryExprOrTypeTraitExprBits.OpLoc = op; assert(static_cast(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind && "UnaryExprOrTypeTraitExprBits.Kind overflow!"); UnaryExprOrTypeTraitExprBits.IsType = false; @@ -2195,8 +2201,9 @@ DeclContext *ParentContext) : Expr(SourceLocExprClass, getDecayedSourceLocExprType(Ctx, Kind), VK_PRValue, OK_Ordinary), - BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) { + RParenLoc(RParenLoc), ParentContext(ParentContext) { SourceLocExprBits.Kind = Kind; + SourceLocExprBits.BuiltinLoc = BLoc; setDependence(ExprDependence::None); } @@ -2266,8 +2273,9 @@ InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef initExprs, SourceLocation rbraceloc) : Expr(InitListExprClass, QualType(), VK_PRValue, OK_Ordinary), - InitExprs(C, initExprs.size()), LBraceLoc(lbraceloc), - RBraceLoc(rbraceloc), AltForm(nullptr, true) { + InitExprs(C, initExprs.size()), RBraceLoc(rbraceloc), + AltForm(nullptr, true) { + InitListExprBits.LBraceLoc = lbraceloc; sawArrayRangeDesignator(false); InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); @@ -2356,7 +2364,7 @@ SourceLocation InitListExpr::getBeginLoc() const { if (InitListExpr *SyntacticForm = getSyntacticForm()) return SyntacticForm->getBeginLoc(); - SourceLocation Beg = LBraceLoc; + SourceLocation Beg = InitListExprBits.LBraceLoc; if (Beg.isInvalid()) { // Find the first non-null initializer. for (InitExprsTy::const_iterator I = InitExprs.begin(), @@ -4173,7 +4181,8 @@ QualType Type, SourceLocation BLoc, SourceLocation RP) : Expr(ShuffleVectorExprClass, Type, VK_PRValue, OK_Ordinary), - BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) { + BuiltinLoc(BLoc), RParenLoc(RP) { + ShuffleVectorExprBits.NumExprs = args.size(); SubExprs = new (C) Stmt*[args.size()]; for (unsigned i = 0; i != args.size(); i++) SubExprs[i] = args[i]; @@ -4184,8 +4193,8 @@ void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef Exprs) { if (SubExprs) C.Deallocate(SubExprs); - this->NumExprs = Exprs.size(); - SubExprs = new (C) Stmt*[NumExprs]; + ShuffleVectorExprBits.NumExprs = Exprs.size(); + SubExprs = new (C) Stmt *[ShuffleVectorExprBits.NumExprs]; memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size()); } @@ -4295,9 +4304,11 @@ ArrayRef IndexExprs, Expr *Init) : Expr(DesignatedInitExprClass, Ty, Init->getValueKind(), Init->getObjectKind()), - EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), - NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) { - this->Designators = new (C) Designator[NumDesignators]; + EqualOrColonLoc(EqualOrColonLoc) { + DesignatedInitExprBits.GNUSyntax = GNUSyntax; + DesignatedInitExprBits.NumDesignators = Designators.size(); + DesignatedInitExprBits.NumSubExprs = IndexExprs.size() + 1; + this->Designators = new (C) Designator[DesignatedInitExprBits.NumDesignators]; // Record the initializer itself. child_iterator Child = child_begin(); @@ -4306,7 +4317,7 @@ // Copy the designators and their subexpressions, computing // value-dependence along the way. unsigned IndexIdx = 0; - for (unsigned I = 0; I != NumDesignators; ++I) { + for (unsigned I = 0; I != DesignatedInitExprBits.NumDesignators; ++I) { this->Designators[I] = Designators[I]; if (this->Designators[I].isArrayDesignator()) { // Copy the index expressions into permanent storage. @@ -4346,7 +4357,7 @@ const Designator *Desigs, unsigned NumDesigs) { Designators = new (C) Designator[NumDesigs]; - NumDesignators = NumDesigs; + DesignatedInitExprBits.NumDesignators = NumDesigs; for (unsigned I = 0; I != NumDesigs; ++I) Designators[I] = Desigs[I]; } @@ -4364,7 +4375,8 @@ auto *DIE = const_cast(this); Designator &First = *DIE->getDesignator(0); if (First.isFieldDesignator()) - StartLoc = GNUSyntax ? First.Field.FieldLoc : First.Field.DotLoc; + StartLoc = DesignatedInitExprBits.GNUSyntax ? First.Field.FieldLoc + : First.Field.DotLoc; else StartLoc = First.ArrayOrRange.LBracketLoc; return StartLoc; @@ -4399,7 +4411,7 @@ unsigned NumNewDesignators = Last - First; if (NumNewDesignators == 0) { std::copy_backward(Designators + Idx + 1, - Designators + NumDesignators, + Designators + DesignatedInitExprBits.NumDesignators, Designators + Idx); --NumNewDesignators; return; @@ -4409,14 +4421,16 @@ return; } - Designator *NewDesignators - = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; + Designator *NewDesignators = new (C) + Designator[DesignatedInitExprBits.NumDesignators - 1 + NumNewDesignators]; std::copy(Designators, Designators + Idx, NewDesignators); std::copy(First, Last, NewDesignators + Idx); - std::copy(Designators + Idx + 1, Designators + NumDesignators, + std::copy(Designators + Idx + 1, + Designators + DesignatedInitExprBits.NumDesignators, NewDesignators + Idx + NumNewDesignators); Designators = NewDesignators; - NumDesignators = NumDesignators - 1 + NumNewDesignators; + DesignatedInitExprBits.NumDesignators = + DesignatedInitExprBits.NumDesignators - 1 + NumNewDesignators; } DesignatedInitUpdateExpr::DesignatedInitUpdateExpr(const ASTContext &C, @@ -4681,8 +4695,10 @@ AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef args, QualType t, AtomicOp op, SourceLocation RP) - : Expr(AtomicExprClass, t, VK_PRValue, OK_Ordinary), - NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) { + : Expr(AtomicExprClass, t, VK_PRValue, OK_Ordinary), BuiltinLoc(BLoc), + RParenLoc(RP) { + AtomicExprBits.NumSubExprs = args.size(); + AtomicExprBits.Op = op; assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); for (unsigned i = 0; i != args.size(); i++) SubExprs[i] = args[i]; @@ -4805,7 +4821,9 @@ : Expr(RecoveryExprClass, T.getNonReferenceType(), T->isDependentType() ? VK_LValue : getValueKindForType(T), OK_Ordinary), - BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) { + EndLoc(EndLoc) { + RecoveryExprBits.NumExprs = SubExprs.size(); + RecoveryExprBits.BeginLoc = BeginLoc; assert(!T.isNull()); assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; })); diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -324,10 +324,11 @@ SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType) : Expr(CXXPseudoDestructorExprClass, Context.BoundMemberTy, VK_PRValue, OK_Ordinary), - Base(static_cast(Base)), IsArrow(isArrow), - OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), + Base(static_cast(Base)), QualifierLoc(QualifierLoc), ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), DestroyedType(DestroyedType) { + CXXPseudoDestructorExprBits.IsArrow = isArrow; + CXXPseudoDestructorExprBits.OperatorLoc = OperatorLoc; setDependence(computeDependence(this)); } diff --git a/clang/lib/AST/ExprObjC.cpp b/clang/lib/AST/ExprObjC.cpp --- a/clang/lib/AST/ExprObjC.cpp +++ b/clang/lib/AST/ExprObjC.cpp @@ -27,8 +27,9 @@ ObjCArrayLiteral::ObjCArrayLiteral(ArrayRef Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR) - : Expr(ObjCArrayLiteralClass, T, VK_PRValue, OK_Ordinary), - NumElements(Elements.size()), Range(SR), ArrayWithObjectsMethod(Method) { + : Expr(ObjCArrayLiteralClass, T, VK_PRValue, OK_Ordinary), Range(SR), + ArrayWithObjectsMethod(Method) { + ObjCArrayLiteralBits.NumElements = Elements.size(); Expr **SaveElements = getElements(); for (unsigned I = 0, N = Elements.size(); I != N; ++I) SaveElements[I] = Elements[I]; @@ -54,13 +55,14 @@ bool HasPackExpansions, QualType T, ObjCMethodDecl *method, SourceRange SR) - : Expr(ObjCDictionaryLiteralClass, T, VK_PRValue, OK_Ordinary), - NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), + : Expr(ObjCDictionaryLiteralClass, T, VK_PRValue, OK_Ordinary), Range(SR), DictWithObjectsMethod(method) { + ObjCDictionaryLiteralBits.HasPackExpansions = HasPackExpansions; + ObjCDictionaryLiteralBits.NumElements = VK.size(); KeyValuePair *KeyValues = getTrailingObjects(); ExpansionData *Expansions = HasPackExpansions ? getTrailingObjects() : nullptr; - for (unsigned I = 0; I < NumElements; I++) { + for (unsigned I = 0; I < ObjCDictionaryLiteralBits.NumElements; I++) { KeyValues[I].Key = VK[I].Key; KeyValues[I].Value = VK[I].Value; if (Expansions) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -468,26 +468,26 @@ S->IsImplicit = Record.readInt() != 0; } -void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) { +void ASTStmtReader::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E) { VisitExpr(E); - E->KeywordLoc = readSourceLocation(); - for (auto &SubExpr: E->SubExprs) + E->CoroutineSuspendExprBits.KeywordLoc = readSourceLocation(); + for (auto &SubExpr : E->SubExprs) SubExpr = Record.readSubStmt(); E->OpaqueValue = cast_or_null(Record.readSubStmt()); +} + +void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) { + VisitCoroutineSuspendExpr(E); E->setIsImplicit(Record.readInt() != 0); } void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *E) { - VisitExpr(E); - E->KeywordLoc = readSourceLocation(); - for (auto &SubExpr: E->SubExprs) - SubExpr = Record.readSubStmt(); - E->OpaqueValue = cast_or_null(Record.readSubStmt()); + VisitCoroutineSuspendExpr(E); } void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) { VisitExpr(E); - E->KeywordLoc = readSourceLocation(); + E->ExprWithSLocBits.Loc = readSourceLocation(); for (auto &SubExpr: E->SubExprs) SubExpr = Record.readSubStmt(); } @@ -1085,9 +1085,9 @@ void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { VisitExplicitCastExpr(E); - E->LParenLoc = readSourceLocation(); + E->ObjCBridgedCastExprBits.LParenLoc = readSourceLocation(); E->BridgeKeywordLoc = readSourceLocation(); - E->Kind = Record.readInt(); + E->ObjCBridgedCastExprBits.Kind = Record.readInt(); } void ASTStmtReader::VisitCastExpr(CastExpr *E) { @@ -1133,7 +1133,7 @@ E->SubExprs[ConditionalOperator::COND] = Record.readSubExpr(); E->SubExprs[ConditionalOperator::LHS] = Record.readSubExpr(); E->SubExprs[ConditionalOperator::RHS] = Record.readSubExpr(); - E->QuestionLoc = readSourceLocation(); + E->ExprWithSLocBits.Loc = readSourceLocation(); E->ColonLoc = readSourceLocation(); } @@ -1145,7 +1145,7 @@ E->SubExprs[BinaryConditionalOperator::COND] = Record.readSubExpr(); E->SubExprs[BinaryConditionalOperator::LHS] = Record.readSubExpr(); E->SubExprs[BinaryConditionalOperator::RHS] = Record.readSubExpr(); - E->QuestionLoc = readSourceLocation(); + E->ExprWithSLocBits.Loc = readSourceLocation(); E->ColonLoc = readSourceLocation(); } @@ -1298,7 +1298,7 @@ void ASTStmtReader::VisitSourceLocExpr(SourceLocExpr *E) { VisitExpr(E); E->ParentContext = readDeclAs(); - E->BuiltinLoc = readSourceLocation(); + E->SourceLocExprBits.BuiltinLoc = readSourceLocation(); E->RParenLoc = readSourceLocation(); E->SourceLocExprBits.Kind = static_cast(Record.readInt()); @@ -1398,9 +1398,10 @@ void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) { VisitExpr(E); - E->Op = AtomicExpr::AtomicOp(Record.readInt()); - E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op); - for (unsigned I = 0; I != E->NumSubExprs; ++I) + E->AtomicExprBits.Op = Record.readInt(); + E->AtomicExprBits.NumSubExprs = + AtomicExpr::getNumSubExprs(AtomicExpr::AtomicOp(E->AtomicExprBits.Op)); + for (unsigned I = 0; I != E->AtomicExprBits.NumSubExprs; ++I) E->SubExprs[I] = Record.readSubExpr(); E->BuiltinLoc = readSourceLocation(); E->RParenLoc = readSourceLocation(); @@ -1439,7 +1440,8 @@ unsigned NumElements = Record.readInt(); assert(NumElements == E->getNumElements() && "Wrong number of elements"); bool HasPackExpansions = Record.readInt(); - assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch"); + assert(HasPackExpansions == E->ObjCDictionaryLiteralBits.HasPackExpansions && + "Pack expansion mismatch"); auto *KeyValues = E->getTrailingObjects(); auto *Expansions = @@ -1720,9 +1722,9 @@ void ASTStmtReader::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) { VisitExpr(E); E->Constructor = readDeclAs(); - E->Loc = readSourceLocation(); - E->ConstructsVirtualBase = Record.readInt(); - E->InheritedFromVirtualBase = Record.readInt(); + E->CXXInheritedCtorInitExprBits.Loc = readSourceLocation(); + E->CXXInheritedCtorInitExprBits.ConstructsVirtualBase = Record.readInt(); + E->CXXInheritedCtorInitExprBits.InheritedFromVirtualBase = Record.readInt(); } void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { @@ -1915,8 +1917,8 @@ VisitExpr(E); E->Base = Record.readSubExpr(); - E->IsArrow = Record.readInt(); - E->OperatorLoc = readSourceLocation(); + E->CXXPseudoDestructorExprBits.IsArrow = Record.readInt(); + E->CXXPseudoDestructorExprBits.OperatorLoc = readSourceLocation(); E->QualifierLoc = Record.readNestedNameSpecifierLoc(); E->ScopeType = readTypeSourceInfo(); E->ColonColonLoc = readSourceLocation(); @@ -2078,10 +2080,10 @@ void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { VisitExpr(E); - E->ATT = (ArrayTypeTrait)Record.readInt(); + E->ArrayTypeTraitExprBits.ATT = (ArrayTypeTrait)Record.readInt(); E->Value = (unsigned int)Record.readInt(); SourceRange Range = readSourceRange(); - E->Loc = Range.getBegin(); + E->ArrayTypeTraitExprBits.Loc = Range.getBegin(); E->RParen = Range.getEnd(); E->QueriedType = readTypeSourceInfo(); E->Dimension = Record.readSubExpr(); @@ -2090,17 +2092,19 @@ void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { VisitExpr(E); E->ET = (ExpressionTrait)Record.readInt(); - E->Value = (bool)Record.readInt(); + E->ExpressionTraitExprBits.Value = (bool)Record.readInt(); SourceRange Range = readSourceRange(); E->QueriedExpression = Record.readSubExpr(); - E->Loc = Range.getBegin(); + E->ExpressionTraitExprBits.Loc = Range.getBegin(); E->RParen = Range.getEnd(); } void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { VisitExpr(E); E->CXXNoexceptExprBits.Value = Record.readInt(); - E->Range = readSourceRange(); + SourceRange R = readSourceRange(); + E->CXXNoexceptExprBits.KeywordLoc = R.getBegin(); + E->RParenLoc = R.getEnd(); E->Operand = Record.readSubExpr(); } @@ -2172,14 +2176,14 @@ void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) { VisitExpr(E); - E->LParenLoc = readSourceLocation(); + E->CXXFoldExprBits.LParenLoc = readSourceLocation(); E->EllipsisLoc = readSourceLocation(); E->RParenLoc = readSourceLocation(); E->NumExpansions = Record.readInt(); E->SubExprs[0] = Record.readSubExpr(); E->SubExprs[1] = Record.readSubExpr(); E->SubExprs[2] = Record.readSubExpr(); - E->Opcode = (BinaryOperatorKind)Record.readInt(); + E->CXXFoldExprBits.Opcode = Record.readInt(); } void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) { @@ -2196,7 +2200,7 @@ void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) { VisitExpr(E); unsigned NumArgs = Record.readInt(); - E->BeginLoc = readSourceLocation(); + E->RecoveryExprBits.BeginLoc = readSourceLocation(); E->EndLoc = readSourceLocation(); assert((NumArgs + 0LL == std::distance(E->children().begin(), E->children().end())) && @@ -2211,10 +2215,10 @@ //===----------------------------------------------------------------------===// void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) { VisitExpr(E); - E->IsArrow = (Record.readInt() != 0); + E->MSPropertyRefExprBits.IsArrow = (Record.readInt() != 0); E->BaseExpr = Record.readSubExpr(); E->QualifierLoc = Record.readNestedNameSpecifierLoc(); - E->MemberLoc = readSourceLocation(); + E->MSPropertyRefExprBits.MemberLoc = readSourceLocation(); E->TheDecl = readDeclAs(); } diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1306,12 +1306,12 @@ void ASTStmtWriter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { VisitExpr(E); Record.push_back(E->getNumElements()); - Record.push_back(E->HasPackExpansions); + Record.push_back(E->ObjCDictionaryLiteralBits.HasPackExpansions); for (unsigned i = 0; i < E->getNumElements(); i++) { ObjCDictionaryElement Element = E->getKeyValueElement(i); Record.AddStmt(Element.Key); Record.AddStmt(Element.Value); - if (E->HasPackExpansions) { + if (E->ObjCDictionaryLiteralBits.HasPackExpansions) { Record.AddSourceLocation(Element.EllipsisLoc); unsigned NumExpansions = 0; if (Element.NumExpansions) @@ -2067,14 +2067,14 @@ void ASTStmtWriter::VisitCXXFoldExpr(CXXFoldExpr *E) { VisitExpr(E); - Record.AddSourceLocation(E->LParenLoc); + Record.AddSourceLocation(E->getLParenLoc()); Record.AddSourceLocation(E->EllipsisLoc); Record.AddSourceLocation(E->RParenLoc); Record.push_back(E->NumExpansions); Record.AddStmt(E->SubExprs[0]); Record.AddStmt(E->SubExprs[1]); Record.AddStmt(E->SubExprs[2]); - Record.push_back(E->Opcode); + Record.push_back(E->getOperator()); Code = serialization::EXPR_CXX_FOLD; }