Index: include/clang/AST/Decl.h =================================================================== --- include/clang/AST/Decl.h +++ include/clang/AST/Decl.h @@ -3800,6 +3800,8 @@ /// unnamed FunctionDecl. For example: /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } class BlockDecl : public Decl, public DeclContext { + // This class stores some data in DeclContext::BlockDeclBits + // to save some space. Use the provided accessors to access it. public: /// A class which contains all the information about a particular /// captured value. @@ -3840,16 +3842,6 @@ }; private: - // FIXME: This can be packed into the bitfields in Decl. - bool IsVariadic : 1; - bool CapturesCXXThis : 1; - bool BlockMissingReturnType : 1; - bool IsConversionFromLambda : 1; - - /// A bit that indicates this block is passed directly to a function as a - /// non-escaping parameter. - bool DoesNotEscape : 1; - /// A new[]'d array of pointers to ParmVarDecls for the formal /// parameters of this function. This is null if a prototype or if there are /// no formals. @@ -3866,10 +3858,7 @@ Decl *ManglingContextDecl = nullptr; protected: - BlockDecl(DeclContext *DC, SourceLocation CaretLoc) - : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false), - CapturesCXXThis(false), BlockMissingReturnType(true), - IsConversionFromLambda(false), DoesNotEscape(false) {} + BlockDecl(DeclContext *DC, SourceLocation CaretLoc); public: static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); @@ -3877,8 +3866,8 @@ SourceLocation getCaretLocation() const { return getLocation(); } - bool isVariadic() const { return IsVariadic; } - void setIsVariadic(bool value) { IsVariadic = value; } + bool isVariadic() const { return BlockDeclBits.IsVariadic; } + void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; } CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; } Stmt *getBody() const override { return (Stmt*) Body; } @@ -3921,7 +3910,9 @@ /// True if this block (or its nested blocks) captures /// anything of local storage from its enclosing scopes. - bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; } + bool hasCaptures() const { + return NumCaptures || capturesCXXThis(); + } /// Returns the number of captured variables. /// Does not include an entry for 'this'. @@ -3934,15 +3925,25 @@ capture_const_iterator capture_begin() const { return captures().begin(); } capture_const_iterator capture_end() const { return captures().end(); } - bool capturesCXXThis() const { return CapturesCXXThis; } - bool blockMissingReturnType() const { return BlockMissingReturnType; } - void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; } + bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; } + void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; } - bool isConversionFromLambda() const { return IsConversionFromLambda; } - void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; } + bool blockMissingReturnType() const { + return BlockDeclBits.BlockMissingReturnType; + } + void setBlockMissingReturnType(bool val = true) { + BlockDeclBits.BlockMissingReturnType = val; + } + + bool isConversionFromLambda() const { + return BlockDeclBits.IsConversionFromLambda; + } + void setIsConversionFromLambda(bool val = true) { + BlockDeclBits.IsConversionFromLambda = val; + } - bool doesNotEscape() const { return DoesNotEscape; } - void setDoesNotEscape() { DoesNotEscape = true; } + bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; } + void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; } bool capturesVariable(const VarDecl *var) const; Index: include/clang/AST/DeclCXX.h =================================================================== --- include/clang/AST/DeclCXX.h +++ include/clang/AST/DeclCXX.h @@ -2817,7 +2817,8 @@ /// \endcode class LinkageSpecDecl : public Decl, public DeclContext { virtual void anchor(); - + // This class stores some data in DeclContext::LinkageSpecDeclBits to save + // some space. Use the provided accessors to access it. public: /// Represents the language in a linkage specification. /// @@ -2831,16 +2832,6 @@ }; private: - /// The language for this linkage specification. - unsigned Language : 3; - - /// True if this linkage spec has braces. - /// - /// This is needed so that hasBraces() returns the correct result while the - /// linkage spec body is being parsed. Once RBraceLoc has been set this is - /// not used, so it doesn't need to be serialized. - unsigned HasBraces : 1; - /// The source location for the extern keyword. SourceLocation ExternLoc; @@ -2848,10 +2839,10 @@ SourceLocation RBraceLoc; LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, - SourceLocation LangLoc, LanguageIDs lang, bool HasBraces) - : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), - Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc), - RBraceLoc(SourceLocation()) {} + SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); + + bool hasBracesImpl() const { return LinkageSpecDeclBits.HasBraces; } + void setBracesImpl(bool B = true) { LinkageSpecDeclBits.HasBraces = B; } public: static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, @@ -2861,16 +2852,18 @@ static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); /// Return the language specified by this linkage specification. - LanguageIDs getLanguage() const { return LanguageIDs(Language); } + LanguageIDs getLanguage() const { + return static_cast(LinkageSpecDeclBits.Language); + } /// Set the language specified by this linkage specification. - void setLanguage(LanguageIDs L) { Language = L; } + void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } /// Determines whether this linkage specification had braces in /// its syntactic form. bool hasBraces() const { - assert(!RBraceLoc.isValid() || HasBraces); - return HasBraces; + assert(!RBraceLoc.isValid() || hasBracesImpl()); + return hasBracesImpl(); } SourceLocation getExternLoc() const { return ExternLoc; } @@ -2878,7 +2871,7 @@ void setExternLoc(SourceLocation L) { ExternLoc = L; } void setRBraceLoc(SourceLocation L) { RBraceLoc = L; - HasBraces = RBraceLoc.isValid(); + setBracesImpl(RBraceLoc.isValid()); } SourceLocation getLocEnd() const LLVM_READONLY { Index: include/clang/AST/DeclOpenMP.h =================================================================== --- include/clang/AST/DeclOpenMP.h +++ include/clang/AST/DeclOpenMP.h @@ -100,6 +100,8 @@ /// /// Here 'omp_out += omp_in' is a combiner and 'omp_priv = 0' is an initializer. class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext { + // This class stores some data in DeclContext::OMPDeclareReductionDeclBits + // to save some space. Use the provided accessors to access it. public: enum InitKind { CallInit, // Initialized by function call. @@ -113,8 +115,6 @@ Expr *Combiner; /// Initializer for declare reduction construct. Expr *Initializer; - /// Kind of initializer - function call or omp_priv initializtion. - InitKind InitializerKind = CallInit; /// Reference to the previous declare reduction construct in the same /// scope with the same name. Required for proper templates instantiation if @@ -125,10 +125,7 @@ OMPDeclareReductionDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType Ty, - OMPDeclareReductionDecl *PrevDeclInScope) - : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr), - Initializer(nullptr), InitializerKind(CallInit), - PrevDeclInScope(PrevDeclInScope) {} + OMPDeclareReductionDecl *PrevDeclInScope); void setPrevDeclInScope(OMPDeclareReductionDecl *Prev) { PrevDeclInScope = Prev; @@ -154,11 +151,13 @@ Expr *getInitializer() { return Initializer; } const Expr *getInitializer() const { return Initializer; } /// Get initializer kind. - InitKind getInitializerKind() const { return InitializerKind; } + InitKind getInitializerKind() const { + return static_cast(OMPDeclareReductionDeclBits.InitializerKind); + } /// Set initializer expression for the declare reduction construct. void setInitializer(Expr *E, InitKind IK) { Initializer = E; - InitializerKind = IK; + OMPDeclareReductionDeclBits.InitializerKind = IK; } /// Get reference to previous declare reduction construct in the same Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -4204,6 +4204,15 @@ // BlockDecl Implementation //===----------------------------------------------------------------------===// +BlockDecl::BlockDecl(DeclContext *DC, SourceLocation CaretLoc) + : Decl(Block, DC, CaretLoc), DeclContext(Block) { + setIsVariadic(false); + setCapturesCXXThis(false); + setBlockMissingReturnType(true); + setIsConversionFromLambda(false); + setDoesNotEscape(false); +} + void BlockDecl::setParams(ArrayRef NewParamInfo) { assert(!ParamInfo && "Already has param info!"); @@ -4217,7 +4226,7 @@ void BlockDecl::setCaptures(ASTContext &Context, ArrayRef Captures, bool CapturesCXXThis) { - this->CapturesCXXThis = CapturesCXXThis; + this->setCapturesCXXThis(CapturesCXXThis); this->NumCaptures = Captures.size(); if (Captures.empty()) { Index: lib/AST/DeclCXX.cpp =================================================================== --- lib/AST/DeclCXX.cpp +++ lib/AST/DeclCXX.cpp @@ -2467,6 +2467,14 @@ getConversionType()->isBlockPointerType(); } +LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, + SourceLocation LangLoc, LanguageIDs lang, bool HasBraces) + : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), + ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) { + setLanguage(lang); + setBracesImpl(HasBraces); +} + void LinkageSpecDecl::anchor() {} LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, Index: lib/AST/DeclOpenMP.cpp =================================================================== --- lib/AST/DeclOpenMP.cpp +++ lib/AST/DeclOpenMP.cpp @@ -57,6 +57,14 @@ // OMPDeclareReductionDecl Implementation. //===----------------------------------------------------------------------===// +OMPDeclareReductionDecl::OMPDeclareReductionDecl(Kind DK, DeclContext *DC, + SourceLocation L, DeclarationName Name, QualType Ty, + OMPDeclareReductionDecl *PrevDeclInScope) + : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), + Combiner(nullptr), PrevDeclInScope(PrevDeclInScope) { + setInitializer(nullptr, CallInit); +} + void OMPDeclareReductionDecl::anchor() {} OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(