This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix a case where we fail to detect a header-declared symbol in rename.
ClosedPublic

Authored by hokein on Jun 27 2019, 4:59 AM.

Details

Summary

Failing case:

#include "foo.h"
void fo^o() {}

getRenameDecl() returns the decl of the symbol under the cursor (which is
in the current main file), instead, we use the canonical decl to determine
whether a symbol is declared in #included header.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein created this revision.Jun 27 2019, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2019, 4:59 AM
sammccall added inline comments.Jun 27 2019, 5:16 AM
clang-tools-extra/clangd/refactor/Rename.cpp
157 ↗(On Diff #206833)

This cast isn't safe. I can't remember the exact case, but if you really need a NamedDecl you need to decide what to do if the canonical one isn't.

hokein updated this revision to Diff 206844.Jun 27 2019, 6:08 AM
hokein marked 2 inline comments as done.

Address comment.

hokein added inline comments.Jun 27 2019, 6:08 AM
clang-tools-extra/clangd/refactor/Rename.cpp
157 ↗(On Diff #206833)

Thanks, it is a little surprising this is not safe (I don't have a corner case in mind either).

The shouldCollectSymbol requires a NamedDecl, I think when the CanonicalDecl is not a NamedDecl, we think this symbol is not indexable.

sammccall accepted this revision.Jun 27 2019, 6:13 AM
sammccall added inline comments.
clang-tools-extra/clangd/refactor/Rename.cpp
157 ↗(On Diff #206833)

Sounds good.

See the comment in SymbolCollector about ObjCPropertyDecl.

This revision is now accepted and ready to land.Jun 27 2019, 6:13 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2019, 6:27 AM