https://github.com/TPPPP72 updated 
https://github.com/llvm/llvm-project/pull/183274

>From 28ae315f2606a393f6b0e87c4e9eef164eb9be84 Mon Sep 17 00:00:00 2001
From: TPPPP72 <[email protected]>
Date: Mon, 9 Mar 2026 20:46:37 +0800
Subject: [PATCH] [Clang] Fix crash when parsing documentation comments with
 invalid declarations

---
 clang/docs/ReleaseNotes.rst      |  2 ++
 clang/lib/AST/RawCommentList.cpp |  3 +++
 clang/test/Sema/gh182737.c       | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+)
 create mode 100644 clang/test/Sema/gh182737.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d07bfc210e05..cc109b7b2ddd4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -318,6 +318,7 @@ Bug Fixes in This Version
 - Fixed an assertion failure caused by error recovery while extending a nested 
name specifier with results from ordinary lookup. (#GH181470)
 - Fixed a crash when parsing ``#pragma clang attribute`` arguments for 
attributes that forbid arguments. (#GH182122)
 - Fixed a bug with multiple-include optimization (MIOpt) state not being 
preserved in some cases during lexing, which could suppress header-guard 
mismatch diagnostics and interfere with include-guard optimization. (#GH180155)
+- Fixed a crash when parsing Doxygen ``@param`` commands attached to invalid 
declarations or non-function entities. (#GH182737)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -351,6 +352,7 @@ Bug Fixes to C++ Support
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed a bug where explicit nullability property attributes were not stored 
in AST nodes in Objective-C. (#GH179703)
+- Fixed a crash when parsing Doxygen ``@param`` commands attached to invalid 
declarations or non-function entities. (#GH182737)
 
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index 3f9edc75311d4..6379a2a1fe6bd 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -202,6 +202,9 @@ const char *RawComment::extractBriefText(const ASTContext 
&Context) const {
 comments::FullComment *RawComment::parse(const ASTContext &Context,
                                          const Preprocessor *PP,
                                          const Decl *D) const {
+  if (D->isInvalidDecl())
+    return nullptr;
+
   // Lazily initialize RawText using the accessor before using it.
   (void)getRawText(Context.getSourceManager());
 
diff --git a/clang/test/Sema/gh182737.c b/clang/test/Sema/gh182737.c
new file mode 100644
index 0000000000000..b076f57001704
--- /dev/null
+++ b/clang/test/Sema/gh182737.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -ast-dump -verify %s
+
+// expected-warning@+3 2 {{empty paragraph passed to '@param' command}}
+// expected-warning@+2 2 {{'@param' command used in a comment that is not 
attached to a function declaration}}
+/**
+ * @param a
+ */
+typedef int my_int;
+
+/**
+ * @brief A callback
+ *
+ * @param[in] a param1
+ * @return
+ *      - true: ok
+ *      - false: failure
+ */
+typedef int (*func_t)(int a);

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

Reply via email to