Bug in QualTypeNames.cpp and adding an option to prepend "::" to fully qualified names.

Jean-Baptiste Lespiau via cfe-commits cfe-commits at lists.llvm.org
Mon May 11 16:25:33 PDT 2020


Hi,

*Context and history:*

I have found a bug in CLIF <https://github.com/google/clif>, which does not
correctly fully qualify templated names when they are nested, e.g.

::tensorfn::Nested< ::std::variant<Tensor, DeviceTensor> >

should have been:

::tensorfn::Nested<
::std::variant<::tensorflow::Tensor,::tensorfn::DeviceTensor> >

I tracked it down to
https://github.com/google/clif/blob/master/clif/backend/matcher.cc#L172
which calls
https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp
and the error is exactly at the line, but I could not really understand why.
https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp#L457

Historically, it has been added by the developers of CLIF
(including Sterling Augustine)
https://github.com/llvm/llvm-project/commit/0dd191a5c4bf27cc8a2b6033436b00f0cbdc4ce7
.
They explained to me, that they pushed this to Clang hoping it would be
used by other tools and maintained by the community, but that it kind of
failed at that, and it (i.e. QualTypeName.pp) is not much used, and not
much maintained.

I was not able to understand this file to provide a fix. On the other side,
it was easy to understand TypePrinter.cpp and PrettyPrinter.cpp, so I tried
extending it to fit my need.

*Suggestion*

 As I wanted fully qualified types (it's usually more convenient for tools
generating code), to prevent some complex errors), I added ~10 lines that
add an option to prepend "::" to qualified types (see the patch).

In practice, it is still a different display at what QualTypeNames.cpp was
doing, as, for example, it displays

::tensorfn::Nested<::std*::__u*::variant<tensorflow::Tensor,
::tensorfn::DeviceTensor>>

but I was able to solve my issues. More generally, it is more verbose, as
it displays the exact underlying type, including default parameter types in
template arguments. So it's verbose, but it's correct (what is best?^^).

I am contacting you, so we can discuss:

- Whether QualTypeNames.cpp
<https://github.com/llvm-mirror/clang/blob/master/lib/AST/QualTypeNames.cpp> is
something useful for the Clang project, whether you think we should fix the
bug I have found (but I cannot, as I do not understand it), or whether we
should deprecate it, or modify the current printing mechanism
(TypePrinter.cpp and PrettyPrinter.cpp) to add more options to tune the
display in ways people may want to.
- Whether adding the CL I have attached is positive, and if yes, what
should be done in addition to that (does it need tests? Are there more
types that we may want to prepend "::" to its fully qualified name?).

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200512/ee7f0624/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.patch
Type: text/x-patch
Size: 2630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200512/ee7f0624/attachment-0001.bin>


More information about the cfe-commits mailing list