Author: ingoneuse
Date: 2026-07-06T03:03:07-04:00
New Revision: ae3d310fa38febc0fd52421ed1e12c621757204c

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

LOG: [clangd] Null-check AutoTypeLoc in 
CollectExtraHighlightings::VisitDeclaratorDecl (#207323)

A Decl's getType() can have a getContainedAutoType() without
its TypeSourceInfo's type having one, because the two types
can differ in type sugar such as DecltypeType which
getContainedAutoType[Loc]() deliberately does not look through.

Fixes https://github.com/llvm/llvm-project/issues/207139

Added: 
    

Modified: 
    clang-tools-extra/clangd/SemanticHighlighting.cpp
    clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 
    


################################################################################
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 f8b7c242be9ff..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;
@@ -1230,11 +1234,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);


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

Reply via email to