<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120671>120671</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed detection of aliasing violaion with tysan
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thesamesam
</td>
</tr>
</table>
<pre>
This comes from a (invalid) testcase reported at https://gcc.gnu.org/PR118141.
```c
#include <stdio.h>
typedef unsigned int v8u32 __attribute__((vector_size(32)));
typedef unsigned short v8b16 __attribute__((vector_size(16)));
// Function to convert 8 fp32 values to 8 bfloat16 values
// We assume that subnormal numbers are not passed. i.e. The CPU is set to do FTZ.
void convert_fp32_to_bfloat16(void* input, unsigned short* output) {
v8u32 input_vec;
for (int i = 0; i < 8; i++) {
input_vec[i] = ((unsigned int*) input)[i];
}
v8u32 shifted_vec = input_vec >> 16;
v8b16 result_vec = __builtin_convertvector(shifted_vec, v8b16);
for (int i = 0; i < 8; i++) {
output[i] = result_vec[i];
}
}
int main() {
float input[8] = {
1.0f, 2.0f, 3.0f, 4.0f,
5.0f, 6.0f, 7.8f, 8.0f
};
unsigned short output[8];
// Convert fp32 to bfloat16
convert_fp32_to_bfloat16(input, output);
// Print output (bfloat16 values as hex)
for (int i = 0; i < 8; i++) {
printf("bfloat16 value %d: 0x%04x\n", i, output[i]);
}
return 0;
}
```
```
$ clang -O3 -march=x86-64-v3 -fsanitize=type
bfloat16 value 0: 0x3f80
bfloat16 value 1: 0x4000
bfloat16 value 2: 0x4040
bfloat16 value 3: 0x4080
bfloat16 value 4: 0x40a0
bfloat16 value 5: 0x40c0
bfloat16 value 6: 0x40f9
bfloat16 value 7: 0x4100
```
godbolt link: https://godbolt.org/z/jd41as4EW
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVV2PqzYQ_TXOyygIbD4feMjH5q3qqtrqSn1BBkzwLdg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