This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add basic support for attributes (selection, hover)
ClosedPublic

Authored by sammccall on Oct 20 2020, 3:02 AM.

Details

Summary

These aren't terribly common, but we currently mishandle them badly.
Not only do we not recogize the attributes themselves, but we often end up
selecting some node other than the parent (because source ranges aren't accurate
in the presence of attributes).

Diff Detail

Event Timeline

sammccall created this revision.Oct 20 2020, 3:02 AM
sammccall requested review of this revision.Oct 20 2020, 3:02 AM
sammccall updated this revision to Diff 299957.Oct 22 2020, 7:00 AM

Only deoptimize selection for *explicit* attributes

hokein added inline comments.Oct 23 2020, 12:02 AM
clang-tools-extra/clangd/AST.cpp
490

this looks like not safe, getNextTypeLoc() may return a null TypeLoc.

clang-tools-extra/clangd/unittests/ASTTests.cpp
390

sorry, I'm not familiar with attributes, what is an implicit attr? It is unclear to me why there is an attr for class X, the source code doesn't have any attribute label for X (the same question for f and a)

Add comment+assert to clarify

sammccall added inline comments.Oct 23 2020, 12:33 AM
clang-tools-extra/clangd/AST.cpp
490

I don't think it can - an AttributedType always modifies a real type.
I've added an assert.

clang-tools-extra/clangd/unittests/ASTTests.cpp
390

Right, implicit attributes are when there's nothing written in the source ,but something else modifies the semantics in a way that clang authors decided to model as an attribute (e.g. because semantics match that of an explicit attribute).

I'm not familiar with many examples either, but a couple:

  • when targeting windows, top-level classes appear to have an implicit "type visibility" attribute that I guess models the difference between default unix/windows symbol visibility.
  • Aaron Ballman gave an example of [[interrupt(...)]] which also adds an implicit [[used]] attribute.

The windows example was why I assert there are no explicit attributes, instead of that there are none at all. I've added a comment.

hokein accepted this revision.Oct 23 2020, 1:04 AM
hokein added inline comments.
clang-tools-extra/clangd/unittests/ASTTests.cpp
390

ah, thanks for the explanation.

This revision is now accepted and ready to land.Oct 23 2020, 1:04 AM
This revision was landed with ongoing or failed builds.Aug 6 2021, 1:49 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 1:49 PM