diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp @@ -501,9 +501,9 @@ void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( - functionDecl( - allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(), - isImplicit(), isInstantiated())))) + functionDecl(isDefinition(), + unless(anyOf(isDefaulted(), isDeleted(), isImplicit(), + isInstantiated(), isWeak()))) .bind("func"), this); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp @@ -1013,3 +1013,5 @@ templatedFunction(); } + +static void pr47779_dont_crash_on_weak() __attribute__((__weakref__("__pr47779_dont_crash_on_weak"))); diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -3569,6 +3569,17 @@ +Matcher<FunctionDecl>isWeak +
Matches weak function declarations.
+
+Given:
+  void foo() __attribute__((__weakref__("__foo")));
+  void bar();
+functionDecl(isWeak())
+  matches the weak declaration "foo", but not "bar".
+
+ + Matcher<FunctionDecl>parameterCountIsunsigned N
Matches FunctionDecls and FunctionProtoTypes that have a
 specific parameter count.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,17 @@
   return Node.isDefaulted();
 }
 
+/// Matches weak function declarations.
+///
+/// Given:
+/// \code
+///   void foo() __attribute__((__weakref__("__foo")));
+///   void bar();
+/// \endcode
+/// functionDecl(isWeak())
+///   matches the weak declaration "foo", but not "bar".
+AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
+
 /// Matches functions that have a dynamic exception specification.
 ///
 /// Given:
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -433,6 +433,7 @@
   REGISTER_MATCHER(isVirtual);
   REGISTER_MATCHER(isVirtualAsWritten);
   REGISTER_MATCHER(isVolatileQualified);
+  REGISTER_MATCHER(isWeak);
   REGISTER_MATCHER(isWritten);
   REGISTER_MATCHER(lValueReferenceType);
   REGISTER_MATCHER(labelDecl);