Author: Akira Hatanaka
Date: 2026-09-04T08:50:04-07:00
New Revision: 1346f98d0e116d989d7e8659154b54c9d47b3b7a

URL: 
https://github.com/llvm/llvm-project/commit/1346f98d0e116d989d7e8659154b54c9d47b3b7a
DIFF: 
https://github.com/llvm/llvm-project/commit/1346f98d0e116d989d7e8659154b54c9d47b3b7a.diff

LOG: [Comment] Fix @method/@methodgroup/@callback false positives (#220787)

76af74004e8b (#181769) refactored the DiagSelect computation in
checkFunctionDeclVerbatimLine to use named enum constants instead of
magic numbers. The checks for whether the comment was attached to an
Objective-C method, a method group, or a pointer to a function
declaration were removed for the @method, @methodgroup, and @callback
cases, which caused warn_doc_function_method_decl_mismatch to be emitted
even when the comments were attached to matching declarations.

Restore the dropped checks.

rdar://184264978

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index bc7884f1ffd52..fba37d5a60c4f 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -111,13 +111,16 @@ void Sema::checkFunctionDeclVerbatimLine(const 
BlockCommandComment *Comment) {
         DiagSelect = diag::CallableKind::FunctionGroup;
       break;
     case CommandTraits::KCI_method:
-      DiagSelect = diag::CallableKind::Method;
+      if (!isObjCMethodDecl())
+        DiagSelect = diag::CallableKind::Method;
       break;
     case CommandTraits::KCI_methodgroup:
-      DiagSelect = diag::CallableKind::MethodGroup;
+      if (!isObjCMethodDecl())
+        DiagSelect = diag::CallableKind::MethodGroup;
       break;
     case CommandTraits::KCI_callback:
-      DiagSelect = diag::CallableKind::Callback;
+      if (!isFunctionPointerVarDecl())
+        DiagSelect = diag::CallableKind::Callback;
       break;
   }
   if (DiagSelect)

diff  --git a/clang/test/Sema/warn-documentation.cpp 
b/clang/test/Sema/warn-documentation.cpp
index e64f68a8797ee..ae891957e07f4 100644
--- a/clang/test/Sema/warn-documentation.cpp
+++ b/clang/test/Sema/warn-documentation.cpp
@@ -834,6 +834,12 @@ unsigned test_function(Base64Flags inFlags);
 typedef unsigned int BaseFlags;
 unsigned (*test_callback)(BaseFlags inFlags);
 
+// @callback should not warn when the comment is directly attached to a
+// pointer to function declaration.
+/*! @callback test_callback_attached
+*/
+unsigned (*test_callback_attached)(BaseFlags inFlags);
+
 // expected-warning@+1 {{'\endverbatim' command does not terminate a verbatim 
text block}}
 /// \endverbatim
 int test_verbatim_1();

diff  --git a/clang/test/Sema/warn-documentation.m 
b/clang/test/Sema/warn-documentation.m
index 30c8bb754c2cd..4b8758bab5c70 100644
--- a/clang/test/Sema/warn-documentation.m
+++ b/clang/test/Sema/warn-documentation.m
@@ -135,6 +135,18 @@ @interface rdar12379114
 - (id)initWithTimeout:(NSTimeInterval)timeout;
 @end
 
+// @method and @methodgroup should not warn when the comment is directly
+// attached to an Objective-C method declaration.
+@interface TestMethodAndMethodgroupAttached
+/*!
+ @methodgroup Creating a request
+*/
+/*!
+ @method doSomething
+*/
+- (id)doSomething;
+@end
+
 // expected-warning@+2 {{'@protocol' command should not be used in a comment 
attached to a non-protocol declaration}}
 /*!
 @protocol PROTO


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to