zanmato1984 commented on PR #46124: URL: https://github.com/apache/arrow/pull/46124#issuecomment-2814416656
OK, I did some [experiments](https://godbolt.org/z/vhcGY3xhd) that can further justify this fix. This experiment proves that merely changing the pointer type passed into `std::memcpy` will affect how the compiler generates UB detection stub code which reports arguably false alarm (otherwise we can't explain why changing the pointer type from `uint64_t *` to `uint8_t *` (and passing into `std::memcpy` as `void *`) eliminates the sanitizer error). For function (64-bit pointer) ``` int64_t read_mc64(const uint64_t* src, size_t n) { uint64_t result = 0; std::memcpy(&result, src, n); return result; } ``` The compiler generates an alignment checking stub: ``` tst x0, #0x7 b.ne .LBB2_4 ``` If the check failed (unaligned to 8-byte), it invokes UBSAN reporting routine `__ubsan_handle_type_mismatch_v1` regardless of how it is used (in this function, passed into `std::memcpy` as a `void *`, which IMO is NOT UB). Whereas for function (8-bit pointer) ``` uint64_t read_mc8(const uint8_t* src, size_t n) { uint64_t result = 0; std::memcpy(&result, src, n); return result; } ``` No alignment checking stub so everything is fine. Hope this could help people to understand better. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org