[Lldb-commits] [PATCH] D127481: [LLDB][formatters] Add formatter for libc++'s std::span

Michael Buch via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 10 03:30:48 PDT 2022


Michael137 created this revision.
Michael137 added reviewers: aprantl, shafik.
Herald added a subscriber: mgorny.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds a libcxx formatter for std::span. The
implementation is based on the libcxx formatter for
std::vector. The main difference is the fact that
std::span conditionally has a __size member based
on whether it has a static or dynamic extent.

Example output of formatted span:

  (std::span<const int, 18446744073709551615>) $0 = size=6 {
    [0] = 0
    [1] = 1
    [2] = 2
    [3] = 3
    [4] = 4
    [5] = 5
  }

The second template parameter here is actually `std::dynamic_extent`,
but the type declaration we get back from the `TypeSystemClang` is the
actual value (which in this case is `(size_t)-1`). This is consistent
with diagnostics from clang, which doesn't desugar this value either.
E.g.,:

  span.cpp:30:31: error: implicit instantiation of undefined template
      'Undefined<std::span<int, 18446744073709551615>>'

Testing:

- Added API-tests
- Confirmed manually using LLDB cli that printing spans works in various scenarios


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127481

Files:
  lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/Makefile
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/main.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127481.435854.patch
Type: text/x-patch
Size: 17007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220610/712e8a6f/attachment-0001.bin>


More information about the lldb-commits mailing list