Unverified Commit 75b04c7a authored by Kadir Cetinkaya's avatar Kadir Cetinkaya
Browse files

[clangd] Fix hover crashing on null types

Summary: Fixes https://github.com/clangd/clangd/issues/225

Reviewers: sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71403
parent d7357c52
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -242,12 +242,13 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
  // 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!
+18 −0
Original line number Diff line number Diff line
@@ -506,6 +506,24 @@ void foo())cpp";
         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);