Issue 120671
Summary Missed detection of aliasing violaion with tysan
Labels new issue
Assignees
Reporter thesamesam
    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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to