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

    <tr>
        <th>Summary</th>
        <td>
            clang++ -fexceptions doesn't enable unwind information generation as documented for all targets
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:driver
      </td>
    </tr>

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

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

<pre>
    At the time of writing, `clang/docs/CommandGuide/clang.rst` states "  Enable generation of unwind information. This allows exceptions to be thrown through Clang compiled stack frames.  This is on by default in x86-64."

However, this doesn't seem to actually turn on unwind information for a number of targets (note that the precise triple matters - e.g. a [recent patch](https://github.com/llvm/llvm-project/commit/be437f3bb8b657f4d2de4603734f24daa624d204) enabled asynchronous unwind tables by default on riscv linux targets, which hides this issue somewhat):

```
$ cat test.cpp 
int main(void) {
  return 0;
}
$ for TGT in mips64 riscv64 sparc64 systemz; do echo $TGT; ./llvm-project/build/default/bin/clang++ -target $TGT test.cpp -fexceptions -S -o - | grep cfi; done
mips64
riscv64
sparc64
systemz
```

And here's what you get when explicitly enabling unwind tables:
```
$ for TGT in mips64 riscv64 sparc64 systemz; do echo $TGT; ./llvm-project/build/default/bin/clang++ -target $TGT test.cpp -funwind-tables -S -o - | grep cfi; done
mips64
        .cfi_startproc
        .cfi_def_cfa_offset 32
        .cfi_offset 31, -8
        .cfi_offset 30, -16
        .cfi_def_cfa_register 30
        .cfi_endproc
riscv64
        .cfi_startproc
        .cfi_def_cfa_offset 32
        .cfi_offset ra, -8
        .cfi_offset s0, -16
        .cfi_def_cfa s0, 0
        .cfi_endproc
sparc64
        .cfi_startproc
        .cfi_def_cfa_register %fp
        .cfi_window_save
        .cfi_register %o7, %i7
        .cfi_endproc
systemz
        .cfi_startproc
        .cfi_offset %r11, -72
        .cfi_offset %r15, -40
        .cfi_def_cfa_offset 328
        .cfi_def_cfa_register %r11
        .cfi_endproc
```

Given the quoted documentation, I think I'd expect this same output for `-fexceptions`. Thanks to @mtvec for raising this issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk2P4zYP_jXKhYghy1_JIYf5eDPvnjv3gSzRtrq25Ep0MumvL2RnNgkmne0CPRQIYpuU6YfPI5GUIZjWIu5Y8ciK55WcqHN-J0O9qp0-7R4IqEMgMyC4Bo7ekLEtE0_ASq56Ge_32qnAxP7JDYO0-mUyGpnYz97EB2Ilh0CSMAATAuB_VtY9QosWvSTjbIw82aOxGoxtnB9mawKvnQkg-94dA-C7wjGaA5CDGoE67452vkxtB0_xa6DcMJoedfye-g6NlwOGBJZIJoCzUJ9AYyOnnsBYeN-U6zJPmBCMPzP-sPz_3x3xgD6mSfFN7TBYJiqCgDhEAFLRJPv-BDR5G8N-xg-N8yDBTkONPqZI0rdIkYSNdRQzkAu7o0dlAgJ5M_YIgyRCH2ANmLQJSGDFo0eFlmCUpDpWPDOx6YjGwLIHJvZM7FtD3VQnyg1M7Pv-8HFZj979joqiHm4YTLypMc-qJqvrTV0WVZNroTEveVZleSNyLWUpci14zsQWcNZKgwwnqzrvrJvCR64UXeGaUGfBm6AO0Bs7vX8kHGk8dkZ10BmNYaHUhDAhBDfgsZPExDamciUBK_n5tzyKHFSkCwMlahxhMRtLMEhjmdgcnNERMaseFx-Ax1kdzrKziVXPl3BRnteX17gLBjOGMl-wlzmEUXoVr6dAOPzJskfQDlB1DpjIX19eoyX5zHA9mV7H87DQES0R2v58Th6ZeIT1Qso50CWfdXO1w9e_wdrBGlj1BK3HEVRjFhQWlwQWxMv9GfbycMZ-fjgncJfR-f_BaujQIxNVgKgEnNwEEeCxQwv4PvZGGepPy04wtr1V_6LaZ73-awQvwNfnbftrHDO-TVRj3gJJT6N36tassXlTjXxzTROQIBO37g9zGo_CenPfyWdnWt6P7LE1gdDHdTcL0OoLnput8K9g9vILzOFLzGf3V3hvdus_xPuDCSaKZrxdE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