Author: Zeyi Xu
Date: 2026-09-14T22:01:02+08:00
New Revision: 59f5719cac1c1781988255aca7d598a8a48651f9

URL: 
https://github.com/llvm/llvm-project/commit/59f5719cac1c1781988255aca7d598a8a48651f9
DIFF: 
https://github.com/llvm/llvm-project/commit/59f5719cac1c1781988255aca7d598a8a48651f9.diff

LOG: [clang-tidy] Fix function-cognitive-complexity crash on aliases (#222965)

Only match function definitions that have a body, since declarations
with the alias attribute satisfy `isDefinition()` without providing one.

Fixes #222958

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

Modified: 
    
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
    clang-tools-extra/docs/ReleaseNotes.md

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index d7f1b73438177..a1ca8c198105c 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -484,7 +484,7 @@ void FunctionCognitiveComplexityCheck::storeOptions(
 
 void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-      functionDecl(isDefinition(),
+      functionDecl(isDefinition(), hasBody(stmt()),
                    unless(anyOf(isDefaulted(), isDeleted(), isWeak())))
           .bind("func"),
       this);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.md 
b/clang-tools-extra/docs/ReleaseNotes.md
index 98105ac222df9..f523c7b4dc4a9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -235,6 +235,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   `INT09-C-EX1` exception, allowing enumerators initialized by referencing
   another enumerator in the same enum (e.g., `last = first`).
 
+- Improved {doc}`readability-function-cognitive-complexity
+  <clang-tidy/checks/readability/function-cognitive-complexity>` check by 
fixing
+  a crash when checking a function declared with the `alias` attribute.
+
 - Improved {doc}`readability-identifier-naming
   <clang-tidy/checks/readability/identifier-naming>` check:
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/function-cognitive-complexity-alias.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/function-cognitive-complexity-alias.cpp
new file mode 100644
index 0000000000000..4626fb5be4779
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/function-cognitive-complexity-alias.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s readability-function-cognitive-complexity %t -- \
+// RUN:   -- -target x86_64-unknown-linux-gnu
+
+extern "C" int function_alias_target() { return 42; }
+extern "C" int function_alias()
+    __attribute__((alias("function_alias_target")));


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

Reply via email to