This revision was automatically updated to reflect the committed changes.
kadircet marked an inline comment as done.
Closed by commit rG75b04c7af9e7: [clangd] Fix hover crashing on null types 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71403

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
@@ -506,6 +506,24 @@
          HI.NamespaceScope = "";
          HI.Value = "&\"1234\"[0]";
        }},
+      {R"cpp(// Should not crash
+        template <typename T>
+        struct Tmpl {
+          Tmpl(int name);
+        };
+
+        template <typename A>
+        void boom(int name) {
+          new Tmpl<A>([[na^me]]);
+        })cpp",
+       [](HoverInfo &HI) {
+         HI.Name = "name";
+         HI.Definition = "int name";
+         HI.Kind = index::SymbolKind::Parameter;
+         HI.Type = "int";
+         HI.NamespaceScope = "";
+         HI.LocalScope = "boom::";
+       }},
   };
   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
@@ -242,12 +242,13 @@
   // FIXME: handle variadics.
 }
 
-llvm::Optional<std::string> printExprValue(const Expr *E, const ASTContext 
&Ctx) {
+llvm::Optional<std::string> printExprValue(const Expr *E,
+                                           const ASTContext &Ctx) {
   Expr::EvalResult Constant;
   // Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
   // to the enclosing call.
   QualType T = E->getType();
-  if (T->isFunctionType() || T->isFunctionPointerType() ||
+  if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
       T->isFunctionReferenceType())
     return llvm::None;
   // Attempt to evaluate. If expr is dependent, evaluation crashes!


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -506,6 +506,24 @@
          HI.NamespaceScope = "";
          HI.Value = "&\"1234\"[0]";
        }},
+      {R"cpp(// Should not crash
+        template <typename T>
+        struct Tmpl {
+          Tmpl(int name);
+        };
+
+        template <typename A>
+        void boom(int name) {
+          new Tmpl<A>([[na^me]]);
+        })cpp",
+       [](HoverInfo &HI) {
+         HI.Name = "name";
+         HI.Definition = "int name";
+         HI.Kind = index::SymbolKind::Parameter;
+         HI.Type = "int";
+         HI.NamespaceScope = "";
+         HI.LocalScope = "boom::";
+       }},
   };
   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
@@ -242,12 +242,13 @@
   // FIXME: handle variadics.
 }
 
-llvm::Optional<std::string> printExprValue(const Expr *E, const ASTContext &Ctx) {
+llvm::Optional<std::string> printExprValue(const Expr *E,
+                                           const ASTContext &Ctx) {
   Expr::EvalResult Constant;
   // Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
   // to the enclosing call.
   QualType T = E->getType();
-  if (T->isFunctionType() || T->isFunctionPointerType() ||
+  if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
       T->isFunctionReferenceType())
     return llvm::None;
   // Attempt to evaluate. If expr is dependent, evaluation crashes!
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to