diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h --- a/clang/include/clang/AST/Decl.h +++ b/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; diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h --- a/clang/include/clang/AST/DeclBase.h +++ b/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. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2792,6 +2792,7 @@ FunctionDeclBits.IsMultiVersion = false; FunctionDeclBits.IsCopyDeductionCandidate = false; FunctionDeclBits.HasODRHash = false; + FunctionDeclBits.IsDefinitionKind = false; } void FunctionDecl::getNameForDiagnostic( diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/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(NewFD) && DC == CurContext && D.isFunctionDefinition()) { // C++ [class.mfct]p2: