[clang] [clang] Fix crash when @param is attached to invalid nodes (PR #183274)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 21:01:59 PDT 2026
https://github.com/TPPPP72 updated https://github.com/llvm/llvm-project/pull/183274
>From 383f4f032581b09edcf4527e10e260ac81bfe68e Mon Sep 17 00:00:00 2001
From: TPPPP72 <906483498 at qq.com>
Date: Mon, 9 Mar 2026 23:44:28 +0800
Subject: [PATCH] [Clang] Fix crash when parsing documentation comments with
invalid declarations
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/AST/RawCommentList.cpp | 3 +++
clang/test/Sema/gh182737.c | 18 ++++++++++++++++++
3 files changed, 22 insertions(+)
create mode 100644 clang/test/Sema/gh182737.c
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d07bfc210e05..7482bb079d3a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -351,6 +351,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 at +3 2 {{empty paragraph passed to '@param' command}}
+// expected-warning at +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);
More information about the cfe-commits
mailing list