<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96054>96054</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Excessive optimization removes necessary code in Clang Compiler for ARM and AARCH64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
P1119r1m
</td>
</tr>
</table>
<pre>
## TL;DR.
The Clang compiler, starting from version 15.0.0, demonstrates a critical issue where aggressive optimization removes essential code in scenarios targeting both ARM and AARCH64 platforms.
#### Clang 15.0.0 - ARM - NO PROBLEM
- https://godbolt.org/z/39sn3TT61
#### Clang (trunk) - AARCH64 - BUG
- https://godbolt.org/z/6cY6ob5e6
#### Clang (trunk) - ARM - BUG
- https://godbolt.org/z/5YE3f5M3K
## Steps to reproduce the issues.
C code:
```
#include <stdint.h>
#include <stddef.h>
typedef struct {
uint8_t arr[16];
void (*show)(uint8_t arr[16]);
} CONTEXT;
static void xor16(uint8_t out[16], uint8_t a[16], uint8_t b[16]) {
for (size_t i = 0; i < 16; i ++)
out[i] = a[i] ^ b[i];
}
int function_that_is_incorrectly_compiled(CONTEXT *ctx) {
volatile uint8_t block[16];
xor16(ctx->arr, ctx->arr, block); // BUG. This code has no effect!!!
ctx->show(ctx->arr);
return 0;
}
```
The disassembly of the compiled code doesn't contain code, related to the "xor16(...)" function call:
```
function_that_is_incorrectly_compiled:
push {r11, lr}
mov r11, sp
ldr r1, [r0, #16]
blx r1
mov r0, #0
pop {r11, pc}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVVuvozgM_jXpi1UEodDywEOvu9LOTWe70s5TFYIp2QkEJaZzzvn1Ky69njO7MxUiJY79fbZjWzinjjViyqIVizYT0VJpbPolCILEBtUkM_lLynjIeAj7DyxcbZ485m-Yvxze-xJhrUV9BGmqRmm0jK_BkbCk6iMU1lRwQuuUqSGIP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