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

    <tr>
        <th>Summary</th>
        <td>
            SSP Strong with `-fexceptions` causing code-gen change on a C compilation with a `noreturn` attribute
        </td>
    </tr>

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

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

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

<pre>
    When compiled with SSP Strong (`-fstack-protector-strong`), the following C test-case produces different code depending on whether Exception Handling is enabled:

    extern void my_exit(void) __attribute__((__noreturn__));
    extern void bar(int *);

    void foo(void) {
      int buf[10];
      bar(buf);
 my_exit();
    }

Here is what happens with a modern x86_64 Clang (tested with `main` 3755ea93b4f7):

```
$ clang -S -O2 -fstack-protector-strong -o test.O2.s test.c
$ clang -S -O2 -fstack-protector-strong -fexceptions -o test.O2.eh.s test.c
$ diff test.O2.s test.O2.eh.s
9,10c9,12
<       subq    $40, %rsp
< .cfi_def_cfa_offset 48
---
>       subq    $56, %rsp
> .cfi_def_cfa_offset 64
>       movq    %fs:40, %rax
>       movq %rax, 48(%rsp)
12a15,18
>       movq    %fs:40, %rax
>       cmpq 48(%rsp), %rax
>       jne     .LBB0_2
> # %bb.1: # %SP_return
13a20,21
> .LBB0_2: # %CallStackCheckFailBlk
>       callq __stack_chk_fail@PLT
20a29
>       .addrsig_sym __stack_chk_fail
$
```

Enabling Exception Handling in C compilations shouldn't change the generated code.  More directly, the problem here is that in compiling a `noreturn` C function with `-fexceptions`, we are enabling the generation of the SSP canary, due to the concern of a security hole in exception-handling-unwinding, described in:
https://bugs.chromium.org/p/llvm/issues/detail?id=30

But there isn't any unwinding in a C program, regardless of whether `-fexceptions` was specified.  So that SSP support isn't needed.  And more generally, turning on `-fexceptions` should be a no-op in compiling C code.  Is this a wider (and latent) Clang issue for C compilations, in that we normally tag C functions as `nounwind`, and turning on `-fexceptions` shouldn't change that?

This is a regression in llvm16 (initially related to d656ae280957), and as noted above it still exists in `main`.  (A related aspect was partially addressed in llvm17 fc4494dffa54.  And that was cherry-picked to the llvm16 release (bf80902fdd43).)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVl1v4zoO_TXKC5HAkT8aP-ShTSe4C9zFHaAX2EdDluhYU1nySPKk_fcLyk6TfgywiwsESWxR5CF5eCQRgj5ZxD0rH1j5uBJT7J3fn394HaI7r1qnXvf_6dGCdMOoDSo469jD09N3eIre2RMwvmNVtu5CFPJ5PXoXUUbn1yEtsypjvGb8ALFH6Jwx7qztCQ4QMcS1FAFh9E5NEgMo3XXo0UaQTiEoHNEqsnYWzj3GHj18e5E4Ru0s_CGsMrSqA6AVrUHF8nuWPbJs-QYAwJeI3sIvpxUMrw2-6Mj4jh4Zr6FpRIxet1PEpqFM-K5prPMYJ2_pTU2f_OFrf63wjO-0jcD4_a3h1TzZdc7dxGR3N-4AaHs7dax82GasfHwXDJYQtH6L45rIR3js7vEWwh_okepz7kWEXowj2jB3UMDgFGXysquaqoCDEXMzqS-XNrMqG4S2rMogvytLFHXeFt1dCvqu0tTm-TM_8gJkcrh-gvVfHH5HD1i7RITNX3wT5n_y_3bR4YUT4dYf9l-4JIp9jLjYzkbE1W0m0w9f9uWHuRkQpvZnqjIvioxIzXjpw3g128hONwq7RnaicV0XMEKxm9fX6_XF8Ntnf2X12d-3L_1VxUc3g_u1uCm7wPL7Kzbx8qXtssQPBI5IlKLyejbecrEtKf_dPwkkh_HnR_e_Nf5hMf1u_nx4yBp-XWY8py1tu9my_P7y-PS9mUd0AZwLTkj49qZyi6frpoMw5okodOhRPh-FNg_m-RNqYcxPaJrEtUb2z00ntGFF9v3Pv2dbnolLoa7bNkIpH_SpCa_D590X9n09K-n7GwkYidlX-mbhsOivmFkeejcZZRm_iyB7YU-Y5PWEFr2g6SX93AD823kEpT3KaF4vIjx61xocoF-0IZI26IvCU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