https://github.com/ingoneuse created 
https://github.com/llvm/llvm-project/pull/207323

fixes #207139 

- additional null check in `VisitDeclaratorDecl` for this edge case
- regression test

>From 04cabaf5f10f4a8a4e3dc8798bf72b7a09d0bf98 Mon Sep 17 00:00:00 2001
From: Ingo Neuse <[email protected]>
Date: Fri, 3 Jul 2026 05:04:55 +0000
Subject: [PATCH 1/2] [clangd] formatting SemanticHighlightingTests.cpp

---
 .../clangd/unittests/SemanticHighlightingTests.cpp         | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index f8b7c242be9ff..2d90446647cee 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1230,11 +1230,12 @@ TEST(SemanticHighlighting, ScopeModifiers) {
 std::vector<HighlightingToken> tokens(llvm::StringRef MarkedText) {
   Annotations A(MarkedText);
   std::vector<HighlightingToken> Results;
-  for (const Range& R : A.ranges())
+  for (const Range &R : A.ranges())
     Results.push_back({HighlightingKind::Variable, 0, R});
-  for (unsigned I = 0; I < static_cast<unsigned>(HighlightingKind::LastKind); 
++I) {
+  for (unsigned I = 0; I < static_cast<unsigned>(HighlightingKind::LastKind);
+       ++I) {
     HighlightingKind Kind = static_cast<HighlightingKind>(I);
-    for (const Range& R : A.ranges(llvm::to_string(Kind)))
+    for (const Range &R : A.ranges(llvm::to_string(Kind)))
       Results.push_back({Kind, 0, R});
   }
   llvm::sort(Results);

>From b22bfb07ca09869b31db6651dc44f5afcbe61c6b Mon Sep 17 00:00:00 2001
From: Ingo Neuse <[email protected]>
Date: Fri, 3 Jul 2026 05:05:11 +0000
Subject: [PATCH 2/2] [clangd] fix crashes in SemanticHighlighting on NTTP
 typed decltype(constexpr-auto-variable)

---
 clang-tools-extra/clangd/SemanticHighlighting.cpp           | 6 ++++--
 .../clangd/unittests/SemanticHighlightingTests.cpp          | 4 ++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index d1ed3ea9bc88a..5d9336fa6e53d 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -833,8 +833,10 @@ class CollectExtraHighlightings
     auto *TSI = D->getTypeSourceInfo();
     if (!TSI)
       return true;
-    SourceLocation StartLoc =
-        TSI->getTypeLoc().getContainedAutoTypeLoc().getNameLoc();
+    auto ATL = TSI->getTypeLoc().getContainedAutoTypeLoc();
+    if (!ATL)
+      return true;
+    SourceLocation StartLoc = ATL.getNameLoc();
     // The AutoType may not have a corresponding token, e.g. in the case of
     // init-captures. In this case, StartLoc overlaps with the location
     // of the decl itself, and producing a token for the type here would result
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 2d90446647cee..a7ebd146c297b 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1164,6 +1164,10 @@ TEST(SemanticHighlighting, NoCrash) {
       template < template <> class a > using b = a<>;  // error-ok
       template <class c>
       using e = b<c::template d>
+    )cpp",
+      R"cpp(
+      constexpr auto v = 0;
+      template <decltype(v) t> class c {};
     )cpp"};
   for (const auto &TestCase : TestCases) {
     TestTU TU;

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

Reply via email to