[clang-tools-extra] [Clangd] Fix dereference of null value (PR #159566)

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 18 05:51:44 PDT 2025


https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/159566

None

>From 5b78181faf98d419ad96b95c089e6046e604a104 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Thu, 18 Sep 2025 05:50:57 -0700
Subject: [PATCH] [Clangd] Fix dereference of null value

---
 clang-tools-extra/clangd/AST.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 2f46ecc92576c..55055cd3f8f11 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -145,8 +145,11 @@ std::string getQualification(ASTContext &Context,
   for (const auto *CurD : llvm::reverse(Parents)) {
     if (auto *TD = llvm::dyn_cast<TagDecl>(CurD)) {
       QualType T;
-      if (const auto *RD = dyn_cast<CXXRecordDecl>(TD);
-          ClassTemplateDecl *CTD = RD->getDescribedClassTemplate()) {
+      const auto *RD = dyn_cast<CXXRecordDecl>(TD);
+      ClassTemplateDecl *CTD = nullptr;
+      if (RD)
+        CTD = RD->getDescribedClassTemplate();
+      if (RD && CTD) {
         ArrayRef<TemplateArgument> Args;
         if (const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
           Args = SD->getTemplateArgs().asArray();



More information about the cfe-commits mailing list