[PATCH] D89194: [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs
Zinovy Nis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 11:37:16 PDT 2020
zinovy.nis created this revision.
Herald added subscribers: cfe-commits, lebedev.ri, xazax.hun.
Herald added a reviewer: lebedev.ri.
Herald added a project: clang.
zinovy.nis requested review of this revision.
Assert fires on weak refs like
static void dont_crash_on_weak() __attribute__((__weakref__("__dont_crash_on_weak")));
Bug: https://bugs.llvm.org/show_bug.cgi?id=47779
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89194
Files:
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
clang/include/clang/ASTMatchers/ASTMatchers.h
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4647,6 +4647,19 @@
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:
Index: clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp
@@ -1013,3 +1013,5 @@
templatedFunction<void*>();
}
+
+static void dont_crash_on_weak() __attribute__((__weakref__("__dont_crash_on_weak")));
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 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(allOf(isDefinition(),
+ unless(anyOf(isDefaulted(), isDeleted(), isImplicit(),
+ isInstantiated(), isWeak()))))
.bind("func"),
this);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89194.297427.patch
Type: text/x-patch
Size: 2052 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201010/fb46c182/attachment.bin>
More information about the cfe-commits
mailing list