Closed
Description
In apache/arrow we encountered a weird UBSan error (apache/arrow#46124 (comment)) which seems to be a false alarm. A reduced case can be found here .
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.