Author: faisalv
Date: Sat Nov 11 10:02:29 2017
New Revision: 317984

URL: http://llvm.org/viewvc/llvm-project?rev=317984&view=rev
Log:
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

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=317984&r1=317983&r2=317984&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Nov 11 10:02:29 2017
@@ -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<FunctionDecl> redeclarable_base;
   FunctionDecl *getNextRedeclarationImpl() override {

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=317984&r1=317983&r2=317984&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat Nov 11 10:02:29 2017
@@ -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:

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=317984&r1=317983&r2=317984&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sat Nov 11 10:02:29 2017
@@ -1863,8 +1863,7 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CX
 
 void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
   VisitFunctionDecl(D);
-  if (Record.readInt())
-    D->setIsCopyDeductionCandidate();
+  D->IsCopyDeductionCandidate = Record.readInt();
 }
 
 void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=317984&r1=317983&r2=317984&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sat Nov 11 10:02:29 2017
@@ -612,7 +612,7 @@ void ASTDeclWriter::VisitFunctionDecl(Fu
 
 void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
   VisitFunctionDecl(D);
-  Record.push_back(D->isCopyDeductionCandidate());
+  Record.push_back(D->IsCopyDeductionCandidate);
   Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
 }
 


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to