[all-commits] [llvm/llvm-project] 798494: [clang][TypePrinter] Support expression template a...

Michael Buch via All-commits all-commits at lists.llvm.org
Thu Jan 26 18:35:18 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 798494ed4f112bf64dcabbe8b60becb42b23208f
      https://github.com/llvm/llvm-project/commit/798494ed4f112bf64dcabbe8b60becb42b23208f
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M clang/lib/AST/TypePrinter.cpp
    M clang/unittests/AST/TypePrinterTest.cpp

  Log Message:
  -----------
  [clang][TypePrinter] Support expression template arguments when checking defaultedness

This patch adds support for `TemplateArgument`s of kind
`TemplateArgument::Expression` to `clang::isSubstitutedDefaultArgument`.
We do so by evaluating both the `Pattern` and `Arg` expression to an
`APInt`, if we can, and comparing the results.

This will be useful in an upcoming change where
`clang::isSubstitutedDefaultArgument` gets called from `clang::Sema`
where the `TemplateArgument`s are instantiated as expressions (without
being evaluted to `APInt` beforehand).

**Testing**

- Added unit-tests

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


  Commit: 8b4279b66fc2f535184642b739b573ead1733711
      https://github.com/llvm/llvm-project/commit/8b4279b66fc2f535184642b739b573ead1733711
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M clang/include/clang/AST/PropertiesBase.td
    M clang/include/clang/AST/TemplateBase.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/TemplateBase.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    M clang/unittests/AST/DeclTest.cpp

  Log Message:
  -----------
  [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument

**Summary**

This patch adds a `IsDefaulted` field to `clang::TemplateArgument`.

To prevent memory footprint increase we still 1 bit from `ArgKind`.

**Changes**

1. `getIsDefaulted`/`setIsDefaulted` to allow clients to communicate
   an argument's defaulted-ness to the TypePrinter
2. The `TemplateArgument` properties description had to be changed
   to make sure we correctly mark the defaulted-ness of arguments
   that came from a deserialized AST (caught by the HLSL test-suite)
3. The `TemplateArgument` constructors now accept a `IsDefaulted`
   parameter to simplify construction from the tablegen description.
   Though if people don't want to clutter the constructors we can
   instead call `setIsDefaulted` from tablegen
4. When `clang::Sema` checks the template arguments against template
   parameters we now call `setIsDefaulted`. This makes sure that
   whenever a specialization decl gets constructed, the defaulted-ness
   of the associated `TemplateArgument`s has already been deduced.
   This preserves the immutability of `TemplateArgumentList`s

**Background**

In LLDB we construct ASTs from debug-info and hand it to clang
to perform actions such as printing/formatting a typenames.
Some debug formats, specifically DWARF, may only encode information
about class template instantiations, losing the structure of the generic
class definition. However, the `clang::TypePrinter` needs a properly
constructed `ClassTemplateDecl` with generic default argument decls
to be able to deduce whether a `ClassTemplateSpecializationDecl` was
instantiatiated with `TemplateArgument`s that correspond to the
defaults. LLDB does know whether a particular template argument was
defaulted, but can't currently tell clang about it.

This patch allows LLDB to set the defaulted-ness of a `TemplateArgument`
and thus benefit more from `clang::TypePrinter`.

See discussion in https://reviews.llvm.org/D140423

**Testing**

* Added unit-test
* LLDB/clang/llvm test-suite passes

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


  Commit: 3d7dcec5db2f86bd8b9142d180716725a8fc0b0f
      https://github.com/llvm/llvm-project/commit/3d7dcec5db2f86bd8b9142d180716725a8fc0b0f
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M clang/lib/AST/TypePrinter.cpp

  Log Message:
  -----------
  [clang][TypePrinter] Test TemplateArgument::IsDefaulted when omitting default arguments

**Summary**

This patch allows clients who can't properly construct
a `ClassTemplateDecl` to still benefit from the `clang::TypePrinter`s
ability to skip printing defaulted template arguments. The
clients simply have to call `TemplateArgument::setIsDefaulted`
in advance.

See discussion in https://reviews.llvm.org/D140423

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


  Commit: 29ecf0e62cd7899dee84732a31875179ec4d5a80
      https://github.com/llvm/llvm-project/commit/29ecf0e62cd7899dee84732a31875179ec4d5a80
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M clang/lib/CodeGen/CGDebugInfo.cpp

  Log Message:
  -----------
  [clang][DebugInfo] Check TemplateArgument::IsDefaulted

Since `ClassTemplateSpecializationDecl`s now set the
`TemplateArgument::IsDefaulted` bit, there's no need
to derive it here.

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


  Commit: a29e06bbeaad7012ac85b221f1aaba3fe1d5fd35
      https://github.com/llvm/llvm-project/commit/a29e06bbeaad7012ac85b221f1aaba3fe1d5fd35
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
    M lldb/unittests/Symbol/TestTypeSystemClang.cpp

  Log Message:
  -----------
  [lldb][TypeSystemClang][NFC] Make TemplateParameterInfos members private

This patch makes the members of `TemplateParameterInfos` only accessible
via public APIs. The motivation for this is that
`TemplateParameterInfos` attempts to maintain two vectors in tandem
(`args` for the template arguments and `names` for the corresponding
name). Working with this structure as it's currently designed makes
it easy to run into out-of-bounds accesses later down the line.

This patch proposes to introduce a new
`TemplateParameterInfos::InsertArg` which is the only way to
set the `TemplateArgument` and name of an entry and since we
require both to be specified we maintain the vectors in sync
out-of-the-box.

To avoid adding non-const getters just for unit-tests a new
`TemplateParameterInfosManipulatorForTests` is introduced
that can be used to control internal state from tests.


  Commit: 1aee040c6545ad65d87b14a694078c182b9fa359
      https://github.com/llvm/llvm-project/commit/1aee040c6545ad65d87b14a694078c182b9fa359
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    M lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
    M lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
    M lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string_view/TestDataFormatterLibcxxStringView.py
    M lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py
    M lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
    M lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
    A lldb/unittests/SymbolFile/DWARF/Inputs/DW_AT_default_value-test.yaml

  Log Message:
  -----------
  [lldb] Add support for DW_AT_default_value in template params

**Summary**

This patch makes LLDB understand the `DW_AT_default_value` on
template argument DIEs. As a result, type summaries will no
longer contain the defaulted template arguments, reducing
noise substantially. E.g.,

Before:
```
(lldb) v nested
(std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator <char> > > > > >) nested = size=0 {}
```

After:
```
(lldb) v nested
(std::vector<std::vector<std::basic_string<char> > >) nested = size=0 {}
```

See discussion in https://reviews.llvm.org/D140423

**Testing**

* Adjust API tests
* Added unit-test

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


  Commit: 5c8ddf64ecf545e8d62f4916ceec275bd8f425ea
      https://github.com/llvm/llvm-project/commit/5c8ddf64ecf545e8d62f4916ceec275bd8f425ea
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-01-27 (Fri, 27 Jan 2023)

  Changed paths:
    M llvm/docs/ReleaseNotes.rst

  Log Message:
  -----------
  [ReleaseNotes] Add release notes for LLDB/Clang changes to handling of defaulted template arguments

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


Compare: https://github.com/llvm/llvm-project/compare/dd9b31e2c2a2...5c8ddf64ecf5


More information about the All-commits mailing list