[PATCH] D82701: [clangd][Hover] Dont crash on null types

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 29 00:29:43 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG117b9230a74c: [clangd][Hover] Dont crash on null types (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82701/new/

https://reviews.llvm.org/D82701

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -708,6 +708,17 @@
          HI.Definition = "X x";
          HI.Type = "struct X";
        }},
+      {// Don't crash on null types.
+       R"cpp(auto [^[[x]]] = 1; /*error-ok*/)cpp",
+       [](HoverInfo &HI) {
+         HI.Name = "x";
+         HI.Kind = index::SymbolKind::Variable;
+         HI.NamespaceScope = "";
+         HI.Definition = "";
+         HI.Type = "NULL TYPE";
+         // Bindings are in theory public members of an anonymous struct.
+         HI.AccessSpecifier = "public";
+       }},
   };
   for (const auto &Case : Cases) {
     SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -124,8 +124,8 @@
   // TypePrinter doesn't resolve decltypes, so resolve them here.
   // FIXME: This doesn't handle composite types that contain a decltype in them.
   // We should rather have a printing policy for that.
-  while (const auto *DT = QT->getAs<DecltypeType>())
-    QT = DT->getUnderlyingType();
+  while (!QT.isNull() && QT->isDecltypeType())
+    QT = QT->getAs<DecltypeType>()->getUnderlyingType();
   return QT.getAsString(Policy);
 }
 
@@ -297,15 +297,7 @@
   for (const ParmVarDecl *PVD : FD->parameters()) {
     HI.Parameters->emplace_back();
     auto &P = HI.Parameters->back();
-    if (!PVD->getType().isNull()) {
-      P.Type = printType(PVD->getType(), Policy);
-    } else {
-      std::string Param;
-      llvm::raw_string_ostream OS(Param);
-      PVD->dump(OS);
-      OS.flush();
-      elog("Got param with null type: {0}", Param);
-    }
+    P.Type = printType(PVD->getType(), Policy);
     if (!PVD->getName().empty())
       P.Name = PVD->getNameAsString();
     if (const Expr *DefArg = getDefaultArg(PVD)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82701.274001.patch
Type: text/x-patch
Size: 2062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200629/11cb65d2/attachment-0001.bin>


More information about the cfe-commits mailing list