[all-commits] [llvm/llvm-project] 3c51ea: [DataFormatter] Fix variant npos with `_LIBCPP_ABI...

Jordan Rupprecht via All-commits all-commits at lists.llvm.org
Wed Nov 30 13:20:27 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3c51ea3619e488db19cd26840ed46d58cfc7062f
      https://github.com/llvm/llvm-project/commit/3c51ea3619e488db19cd26840ed46d58cfc7062f
  Author: Jordan Rupprecht <rupprecht at google.com>
  Date:   2022-11-30 (Wed, 30 Nov 2022)

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

  Log Message:
  -----------
  [DataFormatter] Fix variant npos with `_LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION` enabled.

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

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D138892




More information about the All-commits mailing list