]> granicus.if.org Git - clang/commitdiff
Adjust r316292 - remove the anonymous union for sharing a bitfield in FunctionDecl.
authorFaisal Vali <faisalv@yahoo.com>
Sat, 11 Nov 2017 18:02:29 +0000 (18:02 +0000)
committerFaisal Vali <faisalv@yahoo.com>
Sat, 11 Nov 2017 18:02:29 +0000 (18:02 +0000)
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

include/clang/AST/Decl.h
include/clang/AST/DeclCXX.h
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index ef0f502a35c02ca0721eb0fbca5231372b5210df..4b869ae3253031968c2b7fcccc2240a72f9c8c8d 100644 (file)
@@ -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 {
index d9b8ac274dd2e70e97b2700b30a5ed1301f0e670..8df47cbfe1ddb185c789bd9084270a6da42682d6 100644 (file)
@@ -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:
index ae9efa9948be3dfb7f030f5e6440941c7bf2e91d..126738b6173817cbb190554d85be7c8d6ef3cfb8 100644 (file)
@@ -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) {
index e940806094758ca12314e7da56b8a239752fceb2..fcf78e850b2a0d8dd05ab5ee149ca1ab65d5a919 100644 (file)
@@ -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;
 }