https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/200178

None

>From e03ba2f0a7aaf3e0d94064e7e03879937f82c167 Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Thu, 28 May 2026 21:33:59 +0800
Subject: [PATCH] [clang-tidy] Fix crash in readability-non-const-parameter
 with redecls

---
 .../clang-tidy/readability/NonConstParameterCheck.cpp     | 7 ++++++-
 clang-tools-extra/docs/ReleaseNotes.rst                   | 3 +++
 .../checkers/readability/non-const-parameter.cpp          | 8 ++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index cc12479bcd86e..f3414aaa552f1 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -104,7 +104,12 @@ void NonConstParameterCheck::check(const 
MatchFinder::MatchResult &Result) {
   } else if (const auto *VD = Result.Nodes.getNodeAs<VarDecl>("Mark")) {
     const QualType T = VD->getType();
     if (T->isDependentType()) {
-      const Expr *Init = VD->getInit()->IgnoreParenCasts();
+      // Initializer matched by hasInitializer() may be attached to a different
+      // redeclaration.
+      const Expr *Init = VD->getInit();
+      if (!Init)
+        return;
+      Init = Init->IgnoreParenCasts();
       if (const auto *U = dyn_cast<UnaryOperator>(Init);
           U && U->getOpcode() == UO_Deref) {
         markCanNotBeConst(U->getSubExpr(), true);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0b3bb091307e7..9c846377d797a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -715,6 +715,9 @@ Changes in existing checks
   - Fixed a false positive in array subscript expressions where the types are
     not yet resolved.
 
+  - Fixed a crash when analyzing a redeclaration whose initializer is attached
+    to another declaration.
+
 - Improved :doc:`readability-redundant-casting
   <clang-tidy/checks/readability/redundant-casting>` check by adding the
   `IgnoreImplicitCasts` option (default `false`) to flag casts as redundant
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
index d3749285df071..1a56db3a10263 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -433,3 +433,11 @@ void dependentInitInGenericLambdaMultiArg() {
     DependentCtor2<T> s(p, p);
   };
 }
+
+template <class T>
+struct StaticMemberWithDependentType {
+  static const T X = 0;
+};
+
+template <class T>
+const T StaticMemberWithDependentType<T>::X;

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

Reply via email to