[PATCH] D66706: [Wdocumentation] fixes an assertion failure with typedefed function and block pointer

Dmitri Gribenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 2 11:24:56 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL370677: [Wdocumentation] fixes an assertion failure with typedefed function and blockā€¦ (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66706?vs=218377&id=218384#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66706/new/

https://reviews.llvm.org/D66706

Files:
  cfe/trunk/lib/AST/CommentSema.cpp
  cfe/trunk/test/Sema/warn-documentation.cpp
  cfe/trunk/test/Sema/warn-documentation.m


Index: cfe/trunk/lib/AST/CommentSema.cpp
===================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp
+++ cfe/trunk/lib/AST/CommentSema.cpp
@@ -588,6 +588,8 @@
   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 @@
   // can be ignored.
   if (QT->getAs<TypedefType>())
     return false;
+  if (const auto *P = QT->getAs<PointerType>())
+    if (P->getPointeeType()->getAs<TypedefType>())
+      return false;
+  if (const auto *P = QT->getAs<BlockPointerType>())
+    if (P->getPointeeType()->getAs<TypedefType>())
+      return false;
   return QT->isFunctionPointerType() || QT->isBlockPointerType();
 }
 
Index: cfe/trunk/test/Sema/warn-documentation.m
===================================================================
--- cfe/trunk/test/Sema/warn-documentation.m
+++ cfe/trunk/test/Sema/warn-documentation.m
@@ -310,3 +310,11 @@
  * 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 at -1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+VoidBlockTypeCall ^e; ///< \return none
+// expected-warning at -1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
Index: cfe/trunk/test/Sema/warn-documentation.cpp
===================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp
+++ cfe/trunk/test/Sema/warn-documentation.cpp
@@ -1360,3 +1360,34 @@
  */
 class EmptyNoteNoCrash {
 };
+
+namespace PR42844 { // Assertion failures when using typedefed function pointers
+typedef void (*AA)();
+typedef AA A();
+A *a; ///< \return none
+// expected-warning at -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 at -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 at -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 at -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 at -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 at -1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+
+} // namespace PR42844


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66706.218384.patch
Type: text/x-patch
Size: 3194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190902/0bb66743/attachment.bin>


More information about the cfe-commits mailing list