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

    <tr>
        <th>Summary</th>
        <td>
            Clang crashes when trying to emit some relative calls for 32-bit architectures.
        </td>
    </tr>

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

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

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

<pre>
    Take my speculation regarding causes with a grain of salt. Clang occasionally pushes relative call offsets outside the range of 32-bit values and then crashes upon attempting to emit assembly for them as they cannot be converted back to 32-bit values. Expected behavior (in my opinion) is that the values should over- or under-flow (and then resolve to the correct address).
[https://godbolt.org/z/czM5976cG](Godbolt link) or the source code below:

```
// For best results, compile with `clang -m32 -O1 -c example.c`. Compiling with -c 
// is not necessary, but produces a considerably more verbose output, including
// an llvm stack dump. This crash occurs with every optimization level except -O0.

// The return type of this function has to be a struct, although the contents (or lack thereof)
// don't matter. I don't know enough about C to know why.
struct someStruct {} arbitrary_function();
int main() {
    // The bug happens regardless of the ordering of these two lines. You can add lots of 
    // other things to main() and the crash still occurs, but you cannot remove anything here.

    //If this is deleted, the crash goes away. Why?
    arbitrary_function();
    
    // This line causes the crash. The literal must be extremely close to 2^31 bytes away from the current
    // instruction pointer, as the crash is a result of the offset of the relative jump generated.
    // for this line being pushed slightly out of the domain of 32-bit integers.
    // Presumably, if the offset of the relative jump successfully underflowed, this bug
    // would be avoided.
    ((void(*)())0x80000000)();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVk9v2z4S_TT0ZWBBluN_Bx-apC56WHSBLbDY04KixhIbihQ4Qzvqp_9hKDmJm0ODIJIozbzhvMc30US29YhHtXlUm-eFTtyFeBxSM1YP-0UdmvH4U78g9CPQgCY5zTZ4iNjq2FjfgtGJkOBquQMNbdTWQzgDaccFPDntWwjGaLLBa-dGGBJ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