<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - DW_AT_artificial for structured bindings is incorrectly set"
   href="https://bugs.llvm.org/show_bug.cgi?id=49565">49565</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DW_AT_artificial for structured bindings is incorrectly set
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>brettw@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24634" name="attach_24634" title="Test case">attachment 24634</a> <a href="attachment.cgi?id=24634&action=edit" title="Test case">[details]</a></span>
Test case

With structured bindings:

  auto [test_i, test_s] = GetTest();

Clang generates three variables in the DWARF symbols, one unnamed one for the
std::pair returned from GetTest(), and then test_i and test_s. But test_i and
test_s are marked as DW_AT_artifical even though they were user-declared, and
the unnamed one is *not*, even though it was not user-declared:

0x000048c6:     DW_TAG_variable
                  DW_AT_location        (DW_OP_fbreg -40)
                  DW_AT_decl_file       ("/home/brettw/eraseme3.cc")
                  DW_AT_decl_line       (13)
                  DW_AT_type    (0x00002b98 "pair<int,
std::__2::basic_string<char, std::__2::char_traits<char>,
std::__2::allocator<char>>>")

0x000048d0:     DW_TAG_variable
                  DW_AT_location        (DW_OP_fbreg -48)
                  DW_AT_name    ("test_i")
                  DW_AT_type    (0x0000484a "int&&")
                  DW_AT_artificial      (true)

0x000048dc:     DW_TAG_variable
                  DW_AT_location        (DW_OP_fbreg -56)
                  DW_AT_name    ("test_s")
                  DW_AT_type    (0x000030db "basic_string<char,
std::__2::char_traits<char>, std::__2::allocator<char>>&&")
                  DW_AT_artificial      (true)

This is backwards. The unnamed pair should be marked "artificial" while the two
named variables in the structured bindings should not.

GCC encodes the artificial tags in way I propose:

0x00005ed0:     DW_TAG_variable
                  DW_AT_type    (0x00003316 "pair<int,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
<span class="quote">>")</span >
                  DW_AT_artificial      (true)
                  DW_AT_location        (DW_OP_fbreg -96)

0x00005ed9:     DW_TAG_variable
                  DW_AT_name    ("test_i")
                  DW_AT_decl_file       ("/home/brettw/eraseme3.cc")
                  DW_AT_decl_line       (13)
                  DW_AT_decl_column     (0x09)
                  DW_AT_type    (0x00005ef8 "type&&")
                  DW_AT_location        (DW_OP_fbreg -40)

0x00005ee8:     DW_TAG_variable
                  DW_AT_name    ("test_s")
                  DW_AT_decl_file       ("/home/brettw/eraseme3.cc")
                  DW_AT_decl_line       (13)
                  DW_AT_decl_column     (0x11)
                  DW_AT_type    (0x00005efe "type&&")
                  DW_AT_location        (DW_OP_fbreg -48)

Fuchsia clang version 11.0.0
(<a href="https://fuchsia.googlesource.com/a/third_party/llvm-project">https://fuchsia.googlesource.com/a/third_party/llvm-project</a>
65f58878e72a40d68ef3899c766846ee9ec7cf29)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>