Skip to content

Commit 32d565b

Browse files
committed
[clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs
Fix for https://bugs.llvm.org/show_bug.cgi?id=47779 Differential Revision: https://reviews.llvm.org/D89194
1 parent d7186fe commit 32d565b

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ void FunctionCognitiveComplexityCheck::storeOptions(
501501

502502
void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
503503
Finder->addMatcher(
504-
functionDecl(
505-
allOf(isDefinition(), unless(anyOf(isDefaulted(), isDeleted(),
506-
isImplicit(), isInstantiated()))))
504+
functionDecl(isDefinition(),
505+
unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
506+
isInstantiated(), isWeak())))
507507
.bind("func"),
508508
this);
509509
}

clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,3 +1013,5 @@ void functionThatCallsTemplatedFunctions() {
10131013

10141014
templatedFunction<void*>();
10151015
}
1016+
1017+
static void pr47779_dont_crash_on_weak() __attribute__((__weakref__("__pr47779_dont_crash_on_weak")));

clang/docs/LibASTMatchersReference.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,6 +3569,17 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
35693569
</pre></td></tr>
35703570

35713571

3572+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('isWeak0')"><a name="isWeak0Anchor">isWeak</a></td><td></td></tr>
3573+
<tr><td colspan="4" class="doc" id="isWeak0"><pre>Matches weak function declarations.
3574+
3575+
Given:
3576+
void foo() __attribute__((__weakref__("__foo")));
3577+
void bar();
3578+
functionDecl(isWeak())
3579+
matches the weak declaration "foo", but not "bar".
3580+
</pre></td></tr>
3581+
3582+
35723583
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>&gt;</td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr>
35733584
<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls and FunctionProtoTypes that have a
35743585
specific parameter count.

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,6 +4647,17 @@ AST_MATCHER(FunctionDecl, isDefaulted) {
46474647
return Node.isDefaulted();
46484648
}
46494649

4650+
/// Matches weak function declarations.
4651+
///
4652+
/// Given:
4653+
/// \code
4654+
/// void foo() __attribute__((__weakref__("__foo")));
4655+
/// void bar();
4656+
/// \endcode
4657+
/// functionDecl(isWeak())
4658+
/// matches the weak declaration "foo", but not "bar".
4659+
AST_MATCHER(FunctionDecl, isWeak) { return Node.isWeak(); }
4660+
46504661
/// Matches functions that have a dynamic exception specification.
46514662
///
46524663
/// Given:

clang/lib/ASTMatchers/Dynamic/Registry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ RegistryMaps::RegistryMaps() {
433433
REGISTER_MATCHER(isVirtual);
434434
REGISTER_MATCHER(isVirtualAsWritten);
435435
REGISTER_MATCHER(isVolatileQualified);
436+
REGISTER_MATCHER(isWeak);
436437
REGISTER_MATCHER(isWritten);
437438
REGISTER_MATCHER(lValueReferenceType);
438439
REGISTER_MATCHER(labelDecl);

0 commit comments

Comments
 (0)