Issue 136592
Summary UBSan: Incorrect generated `__ubsan_handle_type_mismatch_v1`?
Labels new issue
Assignees
Reporter zanmato1984
    In apache/arrow we encountered a weird UBSan error (https://github.com/apache/arrow/pull/46124#issuecomment-2814416656) which seems to be a false alarm. A reduced case can be found [here](https://godbolt.org/z/GsYcn155q) .

To summarize, for function:
```
uint64_t read64(const uint64_t* src, size_t n) {
 uint64_t result = 0;
    std::memcpy(&result, src, n);
    return result;
}
```
A misaligned `src` shouldn't be considered UB because it is merely passed into `std::memcpy` as `void *` which requires no alignment. However the generated code jumps to `__ubsan_handle_type_mismatch_v1` once misaligned regardless of how it is used afterwards.

As a comparison, changing the pointer type from `uint64_t *` to `uint8_t *` gets the correct codegen - no alignment checking:
```
uint64_t read8(const uint8_t* src, size_t n) {
    uint64_t result = 0;
    std::memcpy(&result, src, n);
 return result;
}
```

The same behavior is observed on X86 as well, and as early as 18.1.0 (17.0.1 is fine) for both Arm and X86.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to