This is an archive of the discontinued LLVM Phabricator instance.

[DataFormatter] Fix variant npos with `_LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION` enabled.
ClosedPublic

Authored by rupprecht on Nov 28 2022, 8:45 PM.

Details

Summary

This data formatter should print "No Value" if a variant is unset. It does so by checking if __index has a value of -1, however it does so by interpreting it as a signed int.

By default, __index has type unsigned int. When _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION is enabled, the type of __index is either unsigned char, unsigned short, or unsigned int, depending on how many fields there are -- as small as possible. For example, when std::variant has only a few types, the index type is unsigned char, and the npos value will be interpreted by LLDB as 255 when it should be -1.

This change does not special case the variant optimization; it just reads the type instead of assuming it's unsigned int.

Diff Detail

Event Timeline

rupprecht created this revision.Nov 28 2022, 8:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 8:45 PM
Herald added a subscriber: arphaman. · View Herald Transcript
rupprecht requested review of this revision.Nov 28 2022, 8:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 8:45 PM
labath accepted this revision.Nov 29 2022, 2:16 AM
labath added inline comments.
lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
74

I'd probably use fixed with types (uint8_t et al.) here.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
32

Maybe just add a quick note that the number 300 was chosen because it does not fit into a single byte.

This revision is now accepted and ready to land.Nov 29 2022, 2:16 AM
rupprecht updated this revision to Diff 478507.Nov 29 2022, 3:38 AM
  • Add comment about choice of 300 types
  • Use fixed-width types

I plan to land this now so we can remove this from our internal test exclusion list, but I'd be happy to address any post-commit feedback from other reviewers as a followup change.