This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Show padding following a field on field hover.
ClosedPublic

Authored by sammccall on Mar 10 2021, 4:21 PM.

Details

Summary

This displays as: Size: 4 bytes (+4 padding)

Also stop showing (byte) offset/size for bitfields. They're not
meaningful and using them to calculate padding is dangerous!

Diff Detail

Event Timeline

sammccall created this revision.Mar 10 2021, 4:21 PM
sammccall requested review of this revision.Mar 10 2021, 4:21 PM
njames93 added inline comments.
clang-tools-extra/clangd/unittests/HoverTests.cpp
105

Does it make any sense to include the padding for union fields?

sammccall added inline comments.Mar 10 2021, 4:48 PM
clang-tools-extra/clangd/unittests/HoverTests.cpp
105

I think so - it tells you how much room you have to grow/are wasting in particular branches of the union. True, it's easy enough to infer by looking at the union size and the field size. But on the other hand, the *purpose* of a union is to get a compact memory layout, so memory layout information is more likely to be useful.

Maybe we should omit Offset though...

sammccall updated this revision to Diff 329805.Mar 10 2021, 4:52 PM

Stop reporting offset for fields in a union, too

kbobyrev accepted this revision.Mar 30 2021, 4:23 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mar 30 2021, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2021, 4:23 AM
This revision was automatically updated to reflect the committed changes.