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

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo] Missing (unused) types with -fstandalone-debug
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            debuginfo
      </td>
    </tr>

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

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

<pre>
    Consider this program:

    struct Type
    {
        enum { Unused };
 int value = 0;
    };
    int main()
    {
        Type t;
        return t.value;
    }

The enumeration type isn't used anywhere and clang doesn't allocate any storage for it -- which is fine. However, the name "Unused" is still technically a name in the type that could be addressed by some other piece of C++.

In DWARF however, we don't describe that name at all. Using `-O2 -g -c -fstandalone-debug` doesn't produce a DW_TAG_enumeration_type inside the type Type. This is a slight surprise to me: I was under the impression that -fstandalone-debug is supposed to emit all the debug-info that can be emitted, regardless of optimisations or space-saving reductions, as if there was going to be no other DWARF produced for the final program. Do other people have similar expectations, i.e., even though "Unused" is optimised out of struct Type completely, we should still describe it as a name in the type with -fstandalone-debug?

Implementing this feels tricky though. I see in `CGDebugInfo::CreateTypeDefinition` that we would normally collect the enum data into the DICompositeType via CollectRecordFields, however because the enum doesn't have a field it doesn't get an element in the DICompositeType. As far as I understand it, DICompositeType doesn't have a field for "names that are in this type but not used by anything".
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8Vc2O2zgTfBr60rCgUPGMdfBhxoLzzeHDAsEEOQYU2ZKYpUiBTdnrt180pYmdTLI-2LDYP1XV1ZQisr1HPIjds9g1GzWnIcTD9zFEwk0bzPVwDJ6swQhpsARTDH1Uo6ieRNmIcv0GAKAUZ53g9Trh7aF4fL794Q_6eeSn8MXPhAbEYyOqtxjrE5yVmxFE1UB5O8iVmp_-c-yorBdyL2T9Hx0ZEKSfcvkTMc3RQypyw3et7si9DphhY1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