<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57953>57953</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DWARF] Static local variable in inlined function missing attributes in DW_TAG_subprogram
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alvinhochun
      </td>
    </tr>
</table>

<pre>
    Using the following code:

```c++
class MyType {
public:
   bool m_field0 {false};
   short m_field1 {100};
   double m_field2 {2.7182818};
   static inline MyType &instance() {
      static MyType s_instance;
      return s_instance;
   }
};

int get_value() {
   if (MyType::instance().m_field0)
      return MyType::instance().m_field1;
   return MyType::instance().m_field1 + 1;
}

float get_valuef() {
   if (MyType::instance().m_field0)
      return MyType::instance().m_field2;
   return MyType::instance().m_field2 + 1;
}
```

Compile with Clang then inspect with llvm-dwarfdump:

```console
$ clang++ -fuse-ld=lld --target=x86_64-linux-gnu -g -O2 -shared -fPIC -o test-clang.so test.cpp
$ llvm-dwarfdump test-clang.so
[,,,]
0x0000008a:   DW_TAG_subprogram

0x0000008b:     DW_TAG_variable
                  DW_AT_name    ("s_instance")
                  DW_AT_type    (0x0000004a "MyType")
                  DW_AT_external        (true)
                  DW_AT_decl_file       ("test.cpp")
                  DW_AT_decl_line       (7)
                  DW_AT_location        (DW_OP_addrx 0x0)

0x00000096:     NULL
[...]
```

Compared to GCC:

```console
$ g++ -g -O2 -shared -fPIC -o test-gcc.so test.cpp
$ llvm-dwarfdump test-gcc.so
[...]
0x00000137:   DW_TAG_subprogram
                DW_AT_specification     (0x00000082 "_ZN6MyType8instanceEv")
                DW_AT_inline    (DW_INL_declared_inlined)

0x0000013d:     DW_TAG_variable
                  DW_AT_name    ("s_instance")
                  DW_AT_decl_file       ("test.cpp")
                  DW_AT_decl_line       (7)
                  DW_AT_decl_column     (0x15)
                  DW_AT_linkage_name    ("_ZZN6MyType8instanceEvE10s_instance")
                  DW_AT_type    (0x00000051 "MyType")
                  DW_AT_external        (true)
                  DW_AT_location        (DW_OP_addr 0x4030)

0x00000157:     NULL
[...]
```

The DWARF debugging info emitted by Clang does not have any attributes in the `DW_TAG_subprogram` tag, while GCC emits `DW_AT_specification` and `DW_AT_inline`.

If we change the `instance()` function to be `__attribute__((noinline))` instead, then Clang emits these:

```
0x0000008e:   DW_TAG_subprogram
                DW_AT_low_pc    (0x00000000000016d0)
                DW_AT_high_pc   (0x00000000000016d8)
                DW_AT_frame_base        (DW_OP_reg7 RSP)
                DW_AT_call_all_calls    (true)
                DW_AT_specification     (0x00000072 "_ZN6MyType8instanceEv")
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFV1tvozoQ_jXJiwUCEwh5yEOa7K4q9XSr3a5W2hdkwIDPcewIm6T992dsLrk0aaKutIsoje2Z8Tcz3wwmlfnr_IdiokS6oqiQnMudGWUyp6NgMfJWI69_Rl57ZyN8Z247m3GiFPrn9fl1Q9Fo2s1umpSzbDCAEEql5GidFIzy3DOCBeGKjqarUXA3CKlK1rqX8o2U73knMrkE27QXwkYIu1M_xrEfn5rTRLMMMcGZoANGHDEBKyKjIxyP8GyPGtmr0-rEVTJIB0diNdVNLS6sGyBt0A4QtU8mNCqpTraEN-cQsAIgxu3uJoDB4hiu2wcRfp_Bc13RPwR6uxagukN73b2H9llwSQ78Kv6GY_hDjuGLjvV8P_RzKdcbBvTbMV2hJSdt4QjgmNrQTLfznG_XTr4jdZE3683FMpJCSU67WTxBmTHX1hZyikZRh-ejYMV5jhxHkxqiC8OXOEqiiQOUbl6cUjTIKZHzFSNHVaSmIFo83S-RI5GmSjvWpqvakZttNvvtjlEei3dSIWBZdnfYhcV78ewVE3AMAr36mTwvviSqSTe1LGuyPnR2EE5b4UF8S2pG0t579OYCscVzIsiampHNGD4oNYxPSPJWV5vqbXV7FBMCI9xR4gYT9EXTWhD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