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

    <tr>
        <th>Summary</th>
        <td>
            Too strong validity checks for [[clang::musttail]]
        </td>
    </tr>

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

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

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

<pre>
    ```
int base(int);

int ok1() { return base(5); }
int ok2(int x, int y /* unused */) { return base(x); }
```

```
ok1():                                # @ok1()
        mov     edi, 5
        jmp     base(int)@PLT                    # TAILCALL
ok2(int, int):                               # @ok2(int, int)
        jmp     base(int)@PLT                    # TAILCALL
```

So clearly LLVM can apply tail call optimization for these cases. But Clang does not think so and emits errors for these cases:
```
int f1() { [[clang::musttail]] return base(5); }
int f2(int x, int y /* unused */) { [[clang::musttail]] return base(5); }

```

error: cannot perform a tail call to function 'base' because its signature is incompatible with the calling function
int f1() { [[clang::musttail]] return base(5); }
                               ^
 error: cannot perform a tail call to function 'base' because its signature is incompatible with the calling function
int f2(int x, int y /* unused */) { [[clang::musttail]] return base(5); }


https://godbolt.org/z/7h6h1YjWT
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVF2PmzAQ_DXmZdUITCDhgQdy10iVUqlSo1Z9NLAJvhiMbJNe7td3TS73kaa9q9qqRSZmmezu7DBQ6vqQszS8X-E1CwvZOSiFRcbndMl4xuLFEXnE9S4imDBgswUYdIPpTknJMYWQ66cJ_FgPbhm_An9xAMaXjBcwdIPFmqJivHGp5u15zTPOF28-kGRxAS8cjMfApuFjyljhhLZ6P-5YS88-eY7etP24PxdtGn5YrX_Ual28W10Vq9WJKD_ljdK8ivID4-9z_yy7i1J_1FApFEYdYLX69B4q0YHoewqdkIpCpUD3TrbyTjipO9hoA65Bi4RZtBNYDA6ulOi2UGu00GlHuOx2YDWIrgZspbOAxmhjz7NJnYvcvK02T53JkgWtyrfxOXHRDtZ5hiy5pvUa525-0bi_2fInmo9aeGOQ2F6uHg3p0oJ4ornTsBm6apSc8dmxywxKrARxBS-pldtOEAeKLM1T6banR1QqhK_SNV7msZSkJ3Mq9XfUfcngydv7__0Xg_8TG4y_jXP9aHlffbnVdamVm2izpeiOzlmTNtGXm8_roM7jOoszETjpFOZrrcE6o2mgvVCylu4AVYPV7vhCvUAxGIzKz3qTTkM5IeUoUGp_2t70Rt9gRV-WpbR2oBeUL5Nplk6DJq-jMJplmQhTsRFpuIkxyiKspvMEcZ5WPFCiRGVzz4bzE5taim2nrZMV1eKejcx5yHk4jebRLMrCbJIJxCoRYh6lUYyipm8atsR-4hl5eQKTj-TKYWsJVNI6-wgK6_2AODam-mJwjTZ5LfbSC7wXnd0dgnGcfJzlG0FACnY">