From 7dd928f7e77e495f99a75faa0b7e2015f74b781a Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Mon, 2 Sep 2019 18:24:33 +0000 Subject: [PATCH] [Wdocumentation] fixes an assertion failure with typedefed function and block pointer Summary: The assertion happens when compiling with -Wdocumentation with variable declaration to a typedefed function pointer. I not too familiar with the ObjC syntax but first two tests assert without this patch. Fixes https://bugs.llvm.org/show_bug.cgi?id=42844 Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66706 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370677 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/CommentSema.cpp | 8 ++++++++ test/Sema/warn-documentation.cpp | 31 +++++++++++++++++++++++++++++++ test/Sema/warn-documentation.m | 8 ++++++++ 3 files changed, 47 insertions(+) diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index 067b3ae422..69d61dc551 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -588,6 +588,8 @@ void Sema::checkReturnsCommand(const BlockCommandComment *Command) { if (isObjCPropertyDecl()) return; if (isFunctionDecl() || isFunctionOrBlockPointerVarLikeDecl()) { + assert(!ThisDeclInfo->ReturnType.isNull() && + "should have a valid return type"); if (ThisDeclInfo->ReturnType->isVoidType()) { unsigned DiagKind; switch (ThisDeclInfo->CommentDecl->getKind()) { @@ -873,6 +875,12 @@ bool Sema::isFunctionOrBlockPointerVarLikeDecl() { // can be ignored. if (QT->getAs()) return false; + if (const auto *P = QT->getAs()) + if (P->getPointeeType()->getAs()) + return false; + if (const auto *P = QT->getAs()) + if (P->getPointeeType()->getAs()) + return false; return QT->isFunctionPointerType() || QT->isBlockPointerType(); } diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp index 306c413c87..66f02efdc4 100644 --- a/test/Sema/warn-documentation.cpp +++ b/test/Sema/warn-documentation.cpp @@ -1360,3 +1360,34 @@ using VariadicFnType2 = void (*)(int a, ...); */ class EmptyNoteNoCrash { }; + +namespace PR42844 { // Assertion failures when using typedefed function pointers +typedef void (*AA)(); +typedef AA A(); +A *a; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +typedef void B(); +B *b; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +void CC(); +typedef void C(); +C &c = CC; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +using DD = void(*)(); +using D = DD(); +D *d; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +using E = void(); +E *e; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +void FF(); +using F = void(); +F &f = FF; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +} // namespace PR42844 diff --git a/test/Sema/warn-documentation.m b/test/Sema/warn-documentation.m index 0b75bcf80d..c713d5b07f 100644 --- a/test/Sema/warn-documentation.m +++ b/test/Sema/warn-documentation.m @@ -310,3 +310,11 @@ void (^_Nullable blockPointerVariableThatLeadsNowhere)(); * now should work too. */ typedef void (^VariadicBlockType)(int a, ...); + +// PR42844 - Assertion failures when using typedefed block pointers +typedef void(^VoidBlockType)(); +typedef VoidBlockType VoidBlockTypeCall(); +VoidBlockTypeCall *d; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} +VoidBlockTypeCall ^e; ///< \return none +// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} -- 2.40.0