gchatelet created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Tentatively fixing the bug described in 
https://reviews.llvm.org/D68028#inline-614831.
This is not a good solution though since `isThisDeclarationADefinition` still 
doesn't work as expected.

Having `isThisDeclarationADefinition` use `isDefinitionKind` is breaking a lot 
of tests.
I believe there is broken code out there relying on the current behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68701

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDecl.cpp

Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8565,6 +8565,26 @@
                                               isVirtualOkay);
   if (!NewFD) return nullptr;
 
+  // If a function is defined as defaulted or deleted, mark it as such now.
+  // FIXME: Does this ever happen? ActOnStartOfFunctionDef forces the function
+  // definition kind to FDK_Definition.
+  switch (D.getFunctionDefinitionKind()) {
+    case FDK_Declaration:
+      break;
+
+    case FDK_Definition:
+      NewFD->setDefinitionKind();
+      break;
+
+    case FDK_Defaulted:
+      NewFD->setDefaulted();
+      break;
+
+    case FDK_Deleted:
+      NewFD->setDeletedAsWritten();
+      break;
+  }
+
   if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer())
     NewFD->setTopLevelDeclInObjCContainer();
 
@@ -8817,23 +8837,6 @@
       NewFD->setAccess(AS_public);
     }
 
-    // If a function is defined as defaulted or deleted, mark it as such now.
-    // FIXME: Does this ever happen? ActOnStartOfFunctionDef forces the function
-    // definition kind to FDK_Definition.
-    switch (D.getFunctionDefinitionKind()) {
-      case FDK_Declaration:
-      case FDK_Definition:
-        break;
-
-      case FDK_Defaulted:
-        NewFD->setDefaulted();
-        break;
-
-      case FDK_Deleted:
-        NewFD->setDeletedAsWritten();
-        break;
-    }
-
     if (isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
         D.isFunctionDefinition()) {
       // C++ [class.mfct]p2:
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -2792,6 +2792,7 @@
   FunctionDeclBits.IsMultiVersion = false;
   FunctionDeclBits.IsCopyDeductionCandidate = false;
   FunctionDeclBits.HasODRHash = false;
+  FunctionDeclBits.IsDefinitionKind = false;
 }
 
 void FunctionDecl::getNameForDiagnostic(
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1534,10 +1534,14 @@
 
     /// Store the ODRHash after first calculation.
     uint64_t HasODRHash : 1;
+
+    /// Indicates that this function has the FDK_Definition
+    /// FunctionDefinitionKind.
+    uint64_t IsDefinitionKind : 1;
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 25 };
+  enum { NumFunctionDeclBits = 26 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1549,12 +1553,12 @@
     /// For the bits in FunctionDeclBitfields.
     uint64_t : NumFunctionDeclBits;
 
-    /// 24 bits to fit in the remaining available space.
+    /// 25 bits to fit in the remaining available space.
     /// Note that this makes CXXConstructorDeclBitfields take
     /// exactly 64 bits and thus the width of NumCtorInitializers
     /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
     /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
-    uint64_t NumCtorInitializers : 23;
+    uint64_t NumCtorInitializers : 22;
     uint64_t IsInheritingConstructor : 1;
 
     /// Whether this constructor has a trail-allocated explicit specifier.
Index: clang/include/clang/AST/Decl.h
===================================================================
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -2284,6 +2284,12 @@
   bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
   void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
 
+  /// True if this function is of type of Kind FDK_Definition.
+  bool isDefinitionKind() const { return FunctionDeclBits.IsDefinitionKind; }
+  void setDefinitionKind(bool V = true) {
+    FunctionDeclBits.IsDefinitionKind = V;
+  }
+
   /// True if this function is considered a multiversioned function.
   bool isMultiVersion() const {
     return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to