Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, Manfred <mx2927@gmail.com>
Cc: gdb@sourceware.org, gcc@gcc.gnu.org
Subject: Re: gdb 8.x - g++ 7.x compatibility
Date: Sun, 04 Feb 2018 19:17:00 -0000	[thread overview]
Message-ID: <39845077-6bdf-f60d-9bfc-a491e7fa4fc7@gmail.com> (raw)
In-Reply-To: <1b58e2df-5425-4f22-510c-d2e9f51040ba@polymtl.ca>

On 02/03/2018 10:01 PM, Simon Marchi wrote:
> On 2018-02-03 13:35, Manfred wrote:
>> n4659 17.4 (Type equivalence) p1.3:
>>
>> Two template-ids refer to the same class, function, or variable if
>> ...
>> their corresponding non-type template arguments of integral or
>> enumeration type have identical values
>> ...
>>
>> It looks that for non-type template arguments the template type
>> equivalence is based on argument /value/ not /type/ (and value), so
>> IMHO gcc is correct where it considers foo<10u> and foo<10> to be the
>> same type, i.e. "refer to the same class"
>>
>> FWIW, type_info reports the same class name for both templates, which
>> appears to be correct as per the above.
>>
>> I would think someone from gcc might be more specific on why both
>> templates print 4294967286, and what debug info is actually stored by
>> -g in this case.
>
> I think that Roman's example clearly shows that they are not equivalent in
> all cases.
>
> Building Roman's example with g++ 7.3 results in a single instantiated type.  You
> can see that both "new foo<10>()" and "new foo<10u>()" end up calling the same
> constructor.  It seems like which type is instantiated depends on which template
> parameter (the signed or unsigned one) you use first.  So with this:
>
>      base * fi = new foo<10>();
>      base * fu = new foo<10u>();
>
> the output is -10 for both, and with
>
>      base * fu = new foo<10u>();
>      base * fi = new foo<10>();
>
> the output is 4294967286 for both.  But it's probably a bogus behavior.  I tested
> with clangd, it instantiates two different types, so you get 4294967286 for the
> <10u> case and -10 for the <10> case.  I also just built gcc from master, and it
> also instantiates two types, so it seems like that was fixed recently.
>
> So let's see what debug info gcc master generates for these two instances of foo
> (clang master generates the equivalent).
>
>   <1><9257>: Abbrev Number: 66 (DW_TAG_structure_type)
>      <9258>   DW_AT_name        : (indirect string, offset: 0x8455): foo<10>
>      <925c>   DW_AT_byte_size   : 16
>      <925d>   DW_AT_decl_file   : 1
>      <925e>   DW_AT_decl_line   : 7
>      <925f>   DW_AT_decl_column : 8
>      <9260>   DW_AT_containing_type: <0x92fd>
>      <9264>   DW_AT_sibling     : <0x92f8>
> ...
>  <1><93be>: Abbrev Number: 66 (DW_TAG_structure_type)
>     <93bf>   DW_AT_name        : (indirect string, offset: 0x8455): foo<10>
>     <93c3>   DW_AT_byte_size   : 16
>     <93c4>   DW_AT_decl_file   : 1
>     <93c5>   DW_AT_decl_line   : 7
>     <93c6>   DW_AT_decl_column : 8
>     <93c7>   DW_AT_containing_type: <0x92fd>
>     <93cb>   DW_AT_sibling     : <0x945f>
>
> If there are two types with the same name, how is gdb expected to differentiate
> them?
>
> If we can't rely on the DW_AT_name anymore to differentiate templated types, then
> the only alternative I see would be to make GDB ignore the template part of the
> DW_AT_name value, and reconstruct it in the format it expects (with the u) from the
> DW_TAG_template_value_param DIEs children of DW_TAG_structure_type (there's already
> code to do that in dwarf2_compute_name).  Their types correctly point to the signed
> int or unsigned int DIE, so we have the necessary information.  However, that would
> mean reading many more full DIEs early on, when just building partial symbols, which
> would slow done loading the symbols of pretty much any C++ program.
>
> From what I understand from the original change that caused all this [1], removing
> the suffixes was meant to make the error messages more readable for the user.

Readability was a factor but it wasn't the main motivation for
the change.

Printing the suffix is unhelpful because it leads to unnecessary
differences in diagnostics (even in non-template contexts).  For
templates with non-type template parameters there is no difference
between, say A<1>, A<1U>, A<(unsigned) 1>, or even A<Green> when
Green is an enumerator that evaluates to 1, so including the suffix
serves no useful purpose.  In the GCC test suite, it would tend to
cause failures due to differences between the underlying type of
common typedefs like size_t and ptrdiff_t.  Avoiding these
unnecessary differences was the main motivation for the change.
Not necessarily just in the GCC test suite but in all setups that
process GCC messages.

> However, since foo<10>::print() and foo<10u>::print() are not the same function,
> I think it would actually be more confusing if an error message talked about the
> instantiation with the unsigned type, but mentioned "foo<10>::print()".  For example,
> if you put a
>
>   static_assert (std::is_signed<decltype(x)>::value);
>
> in the print method, this is the error message from gcc:
>
>   test.cpp: In instantiation of 'void foo<IVAL>::print() [with auto IVAL = 10]':
>   test.cpp:24:1:   required from here
>   test.cpp:12:22: error: static assertion failed
>          static_assert (std::is_signed<decltype(x)>::value);
>                         ^~~
>
> Wouldn't the message make more sense with a u suffix?

I think this message would be the most meaningful if the "auto"
part were replaced with the deduced type.  With that, the suffix
of the constant isn't important, just as in other contexts.

I didn't consider the use of auto as a template parameter but
I don't think it changes anything.  There, just like in other
contexts, what's important is the deduced types and the values
of constants, not the minute details of how they are spelled.

That said, it wasn't my intention to make things difficult for
the debugger.  But changing GCC back to include the suffix,
even just in the debug info, isn't a solution.  There are other
compilers besides GCC that don't emit the suffixes, and there
even are some that prepend a cast to the number, so if GDB is
to be usable with all these kinds of producers it needs to be
able to handle all of these forms.

Martin


  parent reply	other threads:[~2018-02-04 19:17 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-03  3:17 Roman Popov
2018-02-03  3:57 ` carl hansen
2018-02-03  4:54 ` Simon Marchi
2018-02-03  5:02   ` Roman Popov
2018-02-03  6:43   ` Roman Popov
2018-02-03 14:20   ` Paul Smith
2018-02-03 17:18     ` Roman Popov
2018-02-03 18:36       ` Manfred
2018-02-04  5:02         ` Simon Marchi
2018-02-04 17:09           ` Manfred
2018-02-04 19:17           ` Martin Sebor [this message]
2018-02-05  5:07             ` Simon Marchi
2018-02-05 16:45               ` Martin Sebor
2018-02-05 16:59                 ` Simon Marchi
2018-02-05 17:44                   ` Roman Popov
2018-02-05 20:08                     ` Jonathan Wakely
2018-02-05 20:10                       ` Roman Popov
2018-02-05 20:12                         ` Jonathan Wakely
2018-02-05 20:17                           ` Roman Popov
2018-02-06  3:52                   ` Martin Sebor
2018-02-07  7:21                     ` Daniel Berlin
2018-02-07 13:44                       ` Simon Marchi
2018-02-07 15:07                         ` Manfred
2018-02-07 15:16                           ` Jonathan Wakely
2018-02-07 16:19                             ` Manfred
2018-02-07 16:26                         ` Michael Matz
2018-02-07 16:43                           ` Simon Marchi
2018-02-07 16:51                             ` Jonathan Wakely
2018-02-07 17:03                               ` Simon Marchi
2018-02-07 17:08                                 ` Jonathan Wakely
2018-02-07 17:20                                   ` Simon Marchi
2018-02-07 17:30                                     ` Jonathan Wakely
2018-02-07 18:28                                       ` Simon Marchi
2018-02-08 11:26                                         ` Michael Matz
2018-02-08 14:05                                           ` Paul Smith
2018-02-08 14:07                                             ` Jonathan Wakely
2018-02-07 17:31                                     ` Marc Glisse
2018-02-07 17:04                         ` Daniel Berlin
2018-02-07 17:11                           ` Daniel Berlin
2018-02-07 22:00                             ` Nathan Sidwell
2018-02-07 20:29                           ` Tom Tromey
2018-02-08 15:05               ` Richard Biener
2018-03-01 20:18                 ` Roman Popov
2018-03-01 20:26                   ` Andrew Pinski
2018-03-01 21:03                     ` Jason Merrill
2018-03-02 23:06                       ` Roman Popov
2018-03-03  4:01                         ` Roman Popov
2018-03-04  4:28                         ` Daniel Berlin
2018-02-05 11:05             ` Jonathan Wakely
2018-02-07 15:19           ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=39845077-6bdf-f60d-9bfc-a491e7fa4fc7@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdb@sourceware.org \
    --cc=mx2927@gmail.com \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox