https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/200714

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

>From a611950fe253c73a33d1492c012caecf772e4520 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <[email protected]>
Date: Mon, 1 Jun 2026 01:12:01 -0400
Subject: [PATCH] [clang][HeuristicResolver] Handle non-dependent
 TemplateSpecializationType gracefully

---
 .../unittests/SemanticHighlightingTests.cpp   | 19 +++++++++++++++++++
 clang/lib/Sema/HeuristicResolver.cpp          | 14 +++++++++-----
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 782221306bf85..59f2fe1b51e24 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1156,6 +1156,25 @@ sizeof...($TemplateParameter[[Elements]]);
                      ~ScopeModifierMask, {"-isystemSystemSDK/"});
 }
 
+TEST(SemanticHighlighting, NoCrash) {
+  // Testcases where we are just testing that computation of the
+  // semantic tokens does not trigger a crash.
+  const char *TestCases[] = {
+      R"cpp(
+      template < template <> class a > using b = a<>;
+      template <class c>
+      using e = b<c::template d>
+    )cpp"};
+  for (const auto &TestCase : TestCases) {
+    TestTU TU;
+    TU.Code = TestCase;
+    TU.ExtraArgs.push_back("-std=c++20");
+    TU.ExtraArgs.push_back("-xobjective-c++");
+    auto AST = TU.build();
+    getSemanticHighlightings(AST, /*IncludeInactiveRegionTokens=*/true);
+  }
+}
+
 TEST(SemanticHighlighting, ScopeModifiers) {
   const char *TestCases[] = {
       R"cpp(
diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index 056e13308b7d3..8a799a1b46436 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 
 namespace clang {
@@ -408,11 +409,14 @@ HeuristicResolverImpl::resolveDependentNameType(const 
DependentNameType *DNT) {
 std::vector<const NamedDecl *>
 HeuristicResolverImpl::resolveTemplateSpecializationType(
     const TemplateSpecializationType *TST) {
-  const DependentTemplateStorage &DTN =
-      *TST->getTemplateName().getAsDependentTemplateName();
-  return resolveDependentMember(
-      resolveNestedNameSpecifierToType(DTN.getQualifier()),
-      DTN.getName().getIdentifier(), TemplateFilter);
+  if (TST->getTemplateName().getKind() == TemplateName::DependentTemplate) {
+    const DependentTemplateStorage &DTN =
+        *TST->getTemplateName().getAsDependentTemplateName();
+    return resolveDependentMember(
+        resolveNestedNameSpecifierToType(DTN.getQualifier()),
+        DTN.getName().getIdentifier(), TemplateFilter);
+  }
+  return {};
 }
 
 std::vector<const NamedDecl *>

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

Reply via email to