From: Faisal Vali Date: Sat, 11 Nov 2017 18:02:29 +0000 (+0000) Subject: Adjust r316292 - remove the anonymous union for sharing a bitfield in FunctionDecl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dad78d5b7ea2a0bda1ad3e68e99f460af7da1ee3;p=clang Adjust r316292 - remove the anonymous union for sharing a bitfield in FunctionDecl. The anonymous union did NOT save us storage, but instead behaved as if we added an additional integer data member to FunctionDecl. For additional context, the anonymous union renders the bit fields as non-adjacent and prevents them from sharing the same 'memory location' (i.e. bit-storage) by requiring the anonymous union object to be appropriately aligned. This was confirmed through discussion with Richard Smith in Albuquerque (ISO C++ Meeting) https://reviews.llvm.org/rL316292 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317984 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index ef0f502a35..4b869ae325 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1678,17 +1678,17 @@ private: /// skipped. unsigned HasSkippedBody : 1; + /// Indicates if the function declaration will have a body, once we're done + /// parsing it. + unsigned WillHaveBody : 1; + protected: - // Since a Deduction Guide [C++17] will never have a body, we can share the - // storage, and use a different name. - union { - /// Indicates if the function declaration will have a body, once we're done - /// parsing it. - unsigned WillHaveBody : 1; - /// Indicates that the Deduction Guide is the implicitly generated 'copy - /// deduction candidate' (is used during overload resolution). - unsigned IsCopyDeductionCandidate : 1; - }; + /// [C++17] Only used by CXXDeductionGuideDecl. Declared here to avoid + /// increasing the size of CXXDeductionGuideDecl by the size of an unsigned + /// int as opposed to adding a single bit to FunctionDecl. + /// Indicates that the Deduction Guide is the implicitly generated 'copy + /// deduction candidate' (is used during overload resolution). + unsigned IsCopyDeductionCandidate : 1; private: /// \brief End part of this FunctionDecl's source range. /// @@ -1767,15 +1767,14 @@ protected: DeclContext(DK), redeclarable_base(C), ParamInfo(nullptr), Body(), SClass(S), IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), IsExplicitSpecified(false), - IsVirtualAsWritten(false), IsPure(false), - HasInheritedPrototype(false), HasWrittenPrototype(true), - IsDeleted(false), IsTrivial(false), IsDefaulted(false), - IsExplicitlyDefaulted(false), HasImplicitReturnZero(false), - IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified), - InstantiationIsPending(false), + IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false), + HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false), + IsDefaulted(false), IsExplicitlyDefaulted(false), + HasImplicitReturnZero(false), IsLateTemplateParsed(false), + IsConstexpr(isConstexprSpecified), InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false), - EndRangeLoc(NameInfo.getEndLoc()), TemplateOrSpecialization(), - DNLoc(NameInfo.getInfo()) {} + IsCopyDeductionCandidate(false), EndRangeLoc(NameInfo.getEndLoc()), + TemplateOrSpecialization(), DNLoc(NameInfo.getInfo()) {} typedef Redeclarable redeclarable_base; FunctionDecl *getNextRedeclarationImpl() override { diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index d9b8ac274d..8df47cbfe1 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1881,10 +1881,6 @@ private: if (EndLocation.isValid()) setRangeEnd(EndLocation); IsExplicitSpecified = IsExplicit; - - // IsCopyDeductionCandidate is a union variant member, so ensure it is the - // active member by storing to it. - IsCopyDeductionCandidate = false; } public: diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index ae9efa9948..126738b617 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1863,8 +1863,7 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { VisitFunctionDecl(D); - if (Record.readInt()) - D->setIsCopyDeductionCandidate(); + D->IsCopyDeductionCandidate = Record.readInt(); } void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index e940806094..fcf78e850b 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -612,7 +612,7 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { VisitFunctionDecl(D); - Record.push_back(D->isCopyDeductionCandidate()); + Record.push_back(D->IsCopyDeductionCandidate); Code = serialization::DECL_CXX_DEDUCTION_GUIDE; }