llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangd

Author: ingoneuse

<details>
<summary>Changes</summary>

fixes #<!-- -->207139 

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

---
Full diff: https://github.com/llvm/llvm-project/pull/207323.diff


2 Files Affected:

- (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+4-2) 
- (modified) clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
(+8-3) 


``````````diff
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);

``````````

</details>


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

Reply via email to