public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Missing DWARF children for variable templates
       [not found] <fe095294-92fc-43b9-9afb-5723876a3f58@Spark>
@ 2023-11-11  1:59 ` Nima Hamidi
  2023-11-11  2:05   ` Nima Hamidi
  0 siblings, 1 reply; 3+ messages in thread
From: Nima Hamidi @ 2023-11-11  1:59 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Hello all,

When I compile

```
template <typename T>
struct Cls {
 static const int v = 0;
};

template <typename T>
int constexpr Cls_v = Cls<T>::v;

int func() {
 return Cls_v<int> + Cls_v<float>;
}
```

using `g++ -c main.cpp -o main.o -g`, I see two indistinguishable DIEs in the generated debug info:

```
< 1><0x0000003a> DW_TAG_variable
 DW_AT_name Cls_v
 DW_AT_decl_file 0x00000001
 DW_AT_decl_line 0x00000007
 DW_AT_decl_column 0x0000000f
 DW_AT_type <0x00000035>
 DW_AT_const_expr yes(1)
 DW_AT_location len 0x0009: 0x030000000000000000:
 DW_OP_addr 0x00000000

< 1><0x0000004d> DW_TAG_variable
 DW_AT_name Cls_v
 DW_AT_decl_file 0x00000001
 DW_AT_decl_line 0x00000007
 DW_AT_decl_column 0x0000000f
 DW_AT_type <0x00000035>
 DW_AT_const_expr yes(1)
 DW_AT_location len 0x0009: 0x030400000000000000:
 DW_OP_addr 0x00000004
```

Clang, however, generates DW_TAG_template_type_parameter children for these DIEs too:

```
< 1><0x0000003c> DW_TAG_variable
 DW_AT_name (indexed string: 0x00000003)Cls_v
 DW_AT_type <0x00000033>
 DW_AT_decl_file 0x00000001 /main.cpp
 DW_AT_decl_line 0x00000007
 DW_AT_const_value 0
< 2><0x00000045> DW_TAG_template_type_parameter
 DW_AT_type <0x0000004c>
 DW_AT_name (indexed string: 0x00000005)T
```

I was wondering if this is intentional or it’s just forgotten to be generated.

Thanks,
Nima

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Missing DWARF children for variable templates
  2023-11-11  1:59 ` Missing DWARF children for variable templates Nima Hamidi
@ 2023-11-11  2:05   ` Nima Hamidi
  2023-11-14 10:34     ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Nima Hamidi @ 2023-11-11  2:05 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1018 bytes --]

Another similar issue is with alias templates. The following code:

```
template <typename T>
struct Cls {
 using ptr = T *;
};

template <typename T>
using Cls_ptr = typename Cls<T>::ptr;

Cls_ptr<int> ai;
Cls_ptr<float> af;
```

produces

```
< 1><0x00000029> DW_TAG_typedef
 DW_AT_type <0x0000003d>
 DW_AT_name (indexed string: 0x00000008)Cls_ptr<int>
 DW_AT_decl_file 0x00000001 /main.cpp
 DW_AT_decl_line 0x00000007
```

by  clang, but produces the following by gcc. (Note the difference in DW_AT_name’s.)

```
< 1><0x00000044> DW_TAG_typedef
 DW_AT_name Cls_ptr
 DW_AT_decl_file 0x00000001
 DW_AT_decl_line 0x00000007
 DW_AT_decl_column 0x00000007
 DW_AT_type <0x00000027>
```
On Nov 10, 2023 at 7:59 PM -0600, Nima Hamidi <nimaa.hamidi@gmail.com>, wrote:
>
> template <typename T>
> struct Cls {
>  static const int v = 0;
> };
>
> template <typename T>
> int constexpr Cls_v = Cls<T>::v;
>
> int func() {
>  return Cls_v<int> + Cls_v<float>;
> }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Missing DWARF children for variable templates
  2023-11-11  2:05   ` Nima Hamidi
@ 2023-11-14 10:34     ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-11-14 10:34 UTC (permalink / raw)
  To: Nima Hamidi; +Cc: gcc

On Sat, 11 Nov 2023 at 02:06, Nima Hamidi via Gcc <gcc@gcc.gnu.org> wrote:
>
> Another similar issue is with alias templates. The following code:

Please report both cases to Bugzilla, thanks.


>
> ```
> template <typename T>
> struct Cls {
>  using ptr = T *;
> };
>
> template <typename T>
> using Cls_ptr = typename Cls<T>::ptr;
>
> Cls_ptr<int> ai;
> Cls_ptr<float> af;
> ```
>
> produces
>
> ```
> < 1><0x00000029> DW_TAG_typedef
>  DW_AT_type <0x0000003d>
>  DW_AT_name (indexed string: 0x00000008)Cls_ptr<int>
>  DW_AT_decl_file 0x00000001 /main.cpp
>  DW_AT_decl_line 0x00000007
> ```
>
> by  clang, but produces the following by gcc. (Note the difference in DW_AT_name’s.)
>
> ```
> < 1><0x00000044> DW_TAG_typedef
>  DW_AT_name Cls_ptr
>  DW_AT_decl_file 0x00000001
>  DW_AT_decl_line 0x00000007
>  DW_AT_decl_column 0x00000007
>  DW_AT_type <0x00000027>
> ```
> On Nov 10, 2023 at 7:59 PM -0600, Nima Hamidi <nimaa.hamidi@gmail.com>, wrote:
> >
> > template <typename T>
> > struct Cls {
> >  static const int v = 0;
> > };
> >
> > template <typename T>
> > int constexpr Cls_v = Cls<T>::v;
> >
> > int func() {
> >  return Cls_v<int> + Cls_v<float>;
> > }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-14 10:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <fe095294-92fc-43b9-9afb-5723876a3f58@Spark>
2023-11-11  1:59 ` Missing DWARF children for variable templates Nima Hamidi
2023-11-11  2:05   ` Nima Hamidi
2023-11-14 10:34     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).