Mordante updated this revision to Diff 218264.
Mordante marked an inline comment as done.
Mordante added a comment.

As discussed on IRC no longer allow `\return` on a `typedef`'ed type. This is 
consistent with `\param`.

- Reverts all prior changes in `lib/AST/Comment.cpp`
- Adds extra tests in `Sema::isFunctionOrBlockPointerVarLikeDecl`
- Updates unit tests


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

https://reviews.llvm.org/D66706

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


Index: clang/test/Sema/warn-documentation.m
===================================================================
--- clang/test/Sema/warn-documentation.m
+++ clang/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@-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}}
Index: clang/test/Sema/warn-documentation.cpp
===================================================================
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -1360,3 +1360,24 @@
  */
 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}}
+
+using CC = void(*)();
+using C = CC();
+C *c; ///< \return none
+// expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
+
+using D = void();
+D *d; ///< \return none
+// expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
+
+} // namespace PR42844
Index: clang/lib/AST/CommentSema.cpp
===================================================================
--- clang/lib/AST/CommentSema.cpp
+++ clang/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: clang/test/Sema/warn-documentation.m
===================================================================
--- clang/test/Sema/warn-documentation.m
+++ clang/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@-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}}
Index: clang/test/Sema/warn-documentation.cpp
===================================================================
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -1360,3 +1360,24 @@
  */
 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}}
+
+using CC = void(*)();
+using C = CC();
+C *c; ///< \return none
+// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+
+using D = void();
+D *d; ///< \return none
+// expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+
+} // namespace PR42844
Index: clang/lib/AST/CommentSema.cpp
===================================================================
--- clang/lib/AST/CommentSema.cpp
+++ clang/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();
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to