Author: Aaron Puchert Date: 2021-11-12T21:10:56+01:00 New Revision: 4e7df1ef7b679953c1501177539166876c4cbda4
URL: https://github.com/llvm/llvm-project/commit/4e7df1ef7b679953c1501177539166876c4cbda4 DIFF: https://github.com/llvm/llvm-project/commit/4e7df1ef7b679953c1501177539166876c4cbda4.diff LOG: Comment AST: Find out if function is variadic in DeclInfo::fill Then we don't have to look into the declaration again. Also it's only natural to collect this information alongside parameters and return type, as it's also just a parameter in some sense. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D113690 Added: Modified: clang/include/clang/AST/Comment.h clang/lib/AST/Comment.cpp clang/lib/AST/CommentSema.cpp clang/test/Sema/warn-documentation.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 50ed7eec82080..fff0a985028a8 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -1077,6 +1077,9 @@ struct DeclInfo { /// Can be true only if \c IsFunctionDecl is true. unsigned IsClassMethod : 1; + /// Is \c CommentDecl something we consider a "function" that's variadic. + unsigned IsVariadic : 1; + void fill(); DeclKind getKind() const LLVM_READONLY { diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index 5e6a7de5b5638..aac0591b057ec 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -210,6 +210,7 @@ void DeclInfo::fill() { IsObjCMethod = false; IsInstanceMethod = false; IsClassMethod = false; + IsVariadic = false; ParamVars = None; TemplateParameters = nullptr; @@ -248,6 +249,7 @@ void DeclInfo::fill() { IsInstanceMethod = MD->isInstance(); IsClassMethod = !IsInstanceMethod; } + IsVariadic = FD->isVariadic(); break; } case Decl::ObjCMethod: { @@ -258,6 +260,7 @@ void DeclInfo::fill() { IsObjCMethod = true; IsInstanceMethod = MD->isInstanceMethod(); IsClassMethod = !IsInstanceMethod; + IsVariadic = MD->isVariadic(); break; } case Decl::FunctionTemplate: { @@ -268,6 +271,7 @@ void DeclInfo::fill() { ParamVars = FD->parameters(); ReturnType = FD->getReturnType(); TemplateParameters = FTD->getTemplateParameters(); + IsVariadic = FD->isVariadic(); break; } case Decl::ClassTemplate: { @@ -351,6 +355,8 @@ void DeclInfo::fill() { Kind = FunctionKind; ParamVars = FTL.getParams(); ReturnType = FTL.getReturnLoc().getType(); + if (const auto *FPT = dyn_cast<FunctionProtoType>(FTL.getTypePtr())) + IsVariadic = FPT->isVariadic(); } } diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 3977e6c20a88a..8251802482a0c 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -830,26 +830,11 @@ bool Sema::isAnyFunctionDecl() { } bool Sema::isFunctionOrMethodVariadic() { - if (!isFunctionDecl() || !ThisDeclInfo->CurrentDecl) + if (!ThisDeclInfo) return false; - if (const FunctionDecl *FD = - dyn_cast<FunctionDecl>(ThisDeclInfo->CurrentDecl)) - return FD->isVariadic(); - if (const FunctionTemplateDecl *FTD = - dyn_cast<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl)) - return FTD->getTemplatedDecl()->isVariadic(); - if (const ObjCMethodDecl *MD = - dyn_cast<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl)) - return MD->isVariadic(); - if (const TypedefNameDecl *TD = - dyn_cast<TypedefNameDecl>(ThisDeclInfo->CurrentDecl)) { - QualType Type = TD->getUnderlyingType(); - if (Type->isFunctionPointerType() || Type->isBlockPointerType()) - Type = Type->getPointeeType(); - if (const auto *FT = Type->getAs<FunctionProtoType>()) - return FT->isVariadic(); - } - return false; + if (!ThisDeclInfo->IsFilled) + inspectThisDecl(); + return ThisDeclInfo->IsVariadic; } bool Sema::isObjCMethodDecl() { diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index 3a25c31f76f59..7243e791bba60 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -1448,6 +1448,17 @@ typedef void (*VariadicFnType)(int a, ...); */ using VariadicFnType2 = void (*)(int a, ...); +/*! + * Function pointer type variable. + * + * @param a + * works + * + * @param ... + * now should work too. + */ +void (*variadicFnVar)(int a, ...); + // expected-warning@+2 {{empty paragraph passed to '@note' command}} /** @note _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits