[PATCH] D153015: [clangd] Skip function parameter decls when evaluating variables on hover.

Viktoriia Bakalova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 16 01:31:25 PDT 2023


VitaNuo added inline comments.


================
Comment at: clang-tools-extra/clangd/Hover.cpp:663
+  const auto *Var = dyn_cast<VarDecl>(D);
+  if (Var && !llvm::isa<ParmVarDecl>(Var)) {
     if (const Expr *Init = Var->getInit())
----------------
VitaNuo wrote:
> hokein wrote:
> > We're ignoring all `ParmVarDecl` cases, 
> > 
> > The crash here is for broken code. For the crash case, the AST node looks like 
> > 
> > ```
> > `-ParmVarDecl 0x563b7cc853c0 <col:10, col:20> col:14 invalid param 'Foo':'Foo' cinit
> >     `-OpaqueValueExpr 0x563b7cc854a0 <col:20> 'Foo':'Foo'
> > ```
> > 
> > One alternative is to exclude invalid `VarDecl`, then the Hover feature still keep working on valid `ParmVarDecl`.
> > 
> > ```
> > if (const auto* Var = dyn_cast<VarDecl>(D); Var && !Var->isInvalidDecl()) {
> >    ...
> > }
> > ```
> Why would you do that?
Sorry this was an unintended comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153015



More information about the cfe-commits mailing list