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

    <tr>
        <th>Summary</th>
        <td>
            [PAC] Do not support label arithmetic with indirect gotos signing
        </td>
    </tr>

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

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

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

<pre>
    #97647 introduced indirect gotos signing.

When building llvm-test-suite with `-fptrauth-indirect-gotos`, we have incorrect codegen for two tests: we should fail to compile code with label arithmetic, but instead, we emit incorrect instruction sequence.

**SingleSource/Regression/C/gcc-c-torture/execute/920302-1**: fails during second `execute` function invocation on this piece of code (which corresponds to 19th line `goto *(base + *ip++);`). With x10 holding a non-zero integer offset, we try to add that to an already signed pointer and then perform an authenticated branch, which is wrong.

```
adrp x16, 0xaaaaaaab0000
add     x16, x16, #0x990
mov     x17, #0xb764
pacia   x16, x17
add     x10, x16, x10
mov     x17, #0xb764
braa    x10, x17
```

**SingleSource/Regression/C/gcc-c-torture/execute/comp-goto-1**: fails inside `simulator_kernel` function on this piece of code (which corresponds to 85..88th lines ending with `goto *(base_addr + insn.f1.offset);`). With x16 holding an already signed pointer and x11 holding a non-zero offset, we try to add them and get an ill-signed pointer in x14, and then try to perform an authenticated branch on it, which is wrong.

```
adrp    x16, 0xaaaaaaab0000
add     x16, x16, #0xae0
mov     x17, #0xb59f
pacia   x16, x17
lsl     x11, x10, #46
lsr     x12, x10, #52
ubfx    x13, x10, #20, #12
add     x10, x1, #0x410
add     x14, x16, x11, asr #46
and     x11, x12, #0x3fc
and     x13, x13, #0x3fc
ldr     w12, [x8, x11]
add     x11, x1, #0x418
mov     x17, #0xb59f
braa    x14, x17
```

As already pointer in the original PR, not all the cases are handled in terms of not supporting label arithmetic and emitting a compile error: see https://github.com/llvm/llvm-project/pull/97647#discussion_r1687258996. This issue reports particular tests failures for such unhandled cases.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVltv4yoX_TXkZSsRxpfYD3lop-rzaOaT5nGEYdvmGwI-XJrM-fVHYKdt0s7t6ERWjcvaa19YbODeq9EgHkh9T-qHDY9hsu7wzT5Jbmix6a38fiCs7PZNtQdlgrMyCpSgjFQORYDRBushsSgz7gh9IPRu-ftlQgN9VFoqM4LWT8dtQB-2PqqAcFJhAtLQ7TAHl9xuL5TbTEkaStgHOCFM_AlBGWFddiisxBENDNZBOFlInJ6UdwnqJxu1hIErDcGCsMdZacwmi0PNe9TAnQrTEYMSyUUfAyjjA3K5esSjCq88pkkXRVDWgMe_IhqBV5kSlp7PyowaP9voBBL2-AlHh94rawh7_EDY4yjEVmyDdSG6BMAzihjSqGO0pGxbLDwpl5SBBxldKp1HYY1MxbqYNBSGaJaIlHmyguehNRAm5WFWKBDssCROWHualJgg5-Nna6RP1Sm6VBBlMDGnmkP23_bcJ6P79Klmwu7z05HyPq9Jt4MvqZTngsJkl8XlYKzZ_o3OJo3giA7sMHgMa0GD-548cikhTDzksQGuHXL5PYsHJcw22TrgJqHQwIxusO6YoTH9JyjBA0roHTdiytw5MeXh5OyN_FKwy5M_uXQznIsmWdEzX349pfR5XkL6rZD1RVhJz123Yo72acXsnyf7fVMtszMXir9m2N8y01fM6es3SHvH-ZXx_t3s_hsdpv2Sd99bKSrjlcxK8eoYNQ_Wff2GzqC-EuOfKbCtd7u2XVXoAU0W06Uz3EjyK5fSZV0q481uKHYXib0jzeZFmj_V2bko3hPxj8WLx2w3YkjMSuvtDasycC6qZPqs45XgF3JOtVPhX4j6RXJ_qGuOP5Ng3Q0_17X2erUqLoJejKvmAnArgF0DarYAYj-cF0B5DWCXQcF-sIee46yKN4lWV9ssQ7l3ryNLS3MVOnvmKwdxi1mDK99itFwyPK0E9f25vXitH27jKt6E3v5O_V9aQPXrFnDnn-X-SpFhQrBOjcpwDR8_JRpjA3Ct85TgHj1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