Author: Aaron Puchert Date: 2021-11-12T21:11:11+01:00 New Revision: 3010883fc296619def051e0a2f97d40fb15960d7
URL: https://github.com/llvm/llvm-project/commit/3010883fc296619def051e0a2f97d40fb15960d7 DIFF: https://github.com/llvm/llvm-project/commit/3010883fc296619def051e0a2f97d40fb15960d7.diff LOG: Comment AST: Recognize function-like objects via return type (NFC) Instead of pretending that function pointer type aliases or variables are functions, and thereby losing the information that they are type aliases or variables, respectively, we use the existence of a return type in the DeclInfo to signify a "function-like" object. That seems pretty natural, since it's also the return type (or parameter list) from the DeclInfo that we compare the documentation with. Addresses a concern voiced in D111264#3115104. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D113691 Added: Modified: clang/include/clang/AST/Comment.h clang/include/clang/AST/CommentSema.h clang/lib/AST/Comment.cpp clang/lib/AST/CommentSema.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index fff0a985028a..4184e103206d 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -1019,9 +1019,6 @@ struct DeclInfo { /// \li member function template, /// \li member function template specialization, /// \li ObjC method, - /// \li variable of function pointer, member function pointer or block type, - /// \li a typedef for a function pointer, member function pointer, - /// ObjC block. FunctionKind, /// Something that we consider a "class": @@ -1089,6 +1086,8 @@ struct DeclInfo { TemplateDeclKind getTemplateKind() const LLVM_READONLY { return static_cast<TemplateDeclKind>(TemplateKind); } + + bool involvesFunctionType() const { return !ReturnType.isNull(); } }; /// A full comment attached to a declaration, contains block content. diff --git a/clang/include/clang/AST/CommentSema.h b/clang/include/clang/AST/CommentSema.h index 4a5174e08bff..b4e564e81185 100644 --- a/clang/include/clang/AST/CommentSema.h +++ b/clang/include/clang/AST/CommentSema.h @@ -201,6 +201,10 @@ class Sema { /// Emit diagnostics about unknown parametrs. void resolveParamCommandIndexes(const FullComment *FC); + /// \returns \c true if the declaration that this comment is attached to + /// is a pointer to function/method/block type or has such a type. + bool involvesFunctionType(); + bool isFunctionDecl(); bool isAnyFunctionDecl(); diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index aac0591b057e..fae3640d5ff7 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -250,6 +250,7 @@ void DeclInfo::fill() { IsClassMethod = !IsInstanceMethod; } IsVariadic = FD->isVariadic(); + assert(involvesFunctionType()); break; } case Decl::ObjCMethod: { @@ -261,6 +262,7 @@ void DeclInfo::fill() { IsInstanceMethod = MD->isInstanceMethod(); IsClassMethod = !IsInstanceMethod; IsVariadic = MD->isVariadic(); + assert(involvesFunctionType()); break; } case Decl::FunctionTemplate: { @@ -272,6 +274,7 @@ void DeclInfo::fill() { ReturnType = FD->getReturnType(); TemplateParameters = FTD->getTemplateParameters(); IsVariadic = FD->isVariadic(); + assert(involvesFunctionType()); break; } case Decl::ClassTemplate: { @@ -352,11 +355,11 @@ void DeclInfo::fill() { TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc(); FunctionTypeLoc FTL; if (getFunctionTypeLoc(TL, FTL)) { - Kind = FunctionKind; ParamVars = FTL.getParams(); ReturnType = FTL.getReturnLoc().getType(); if (const auto *FPT = dyn_cast<FunctionProtoType>(FTL.getTypePtr())) IsVariadic = FPT->isVariadic(); + assert(involvesFunctionType()); } } diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 8251802482a0..087f103e4931 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -86,7 +86,7 @@ ParamCommandComment *Sema::actOnParamCommandStart( new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID, CommandMarker); - if (!isFunctionDecl()) + if (!involvesFunctionType()) Diag(Command->getLocation(), diag::warn_doc_param_not_attached_to_a_function_decl) << CommandMarker @@ -588,7 +588,7 @@ void Sema::checkReturnsCommand(const BlockCommandComment *Command) { // to document the value that the property getter returns. if (isObjCPropertyDecl()) return; - if (isFunctionDecl()) { + if (involvesFunctionType()) { assert(!ThisDeclInfo->ReturnType.isNull() && "should have a valid return type"); if (ThisDeclInfo->ReturnType->isVoidType()) { @@ -728,7 +728,7 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) { } void Sema::resolveParamCommandIndexes(const FullComment *FC) { - if (!isFunctionDecl()) { + if (!involvesFunctionType()) { // We already warned that \\param commands are not attached to a function // decl. return; @@ -816,6 +816,14 @@ void Sema::resolveParamCommandIndexes(const FullComment *FC) { } } +bool Sema::involvesFunctionType() { + if (!ThisDeclInfo) + return false; + if (!ThisDeclInfo->IsFilled) + inspectThisDecl(); + return ThisDeclInfo->involvesFunctionType(); +} + bool Sema::isFunctionDecl() { if (!ThisDeclInfo) return false; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits