[Lldb-commits] [PATCH] D138892: [DataFormatter] Fix variant npos with `_LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION` enabled.

Jordan Rupprecht via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 28 20:45:33 PST 2022


rupprecht created this revision.
rupprecht added reviewers: labath, Michael137, kastiglione.
Herald added a subscriber: arphaman.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138892

Files:
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138892.478448.patch
Type: text/x-patch
Size: 5507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221129/1aadeb14/attachment.bin>


More information about the lldb-commits mailing list