[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 30 22:43:47 PDT 2023
MaskRay wrote:
Thanks for the comment.
> I think the choice we're making here is probably worth it, though we should probably document it better. I think you can remove the alignment assumption by explicitly casting the operands to char* before passing them to memcpy; if you can't, I'd be more worried that we're doing something problematic here.
Yes. The correct implementation correctly drops the alignment check on the dst parameter for `memcpy((char *)a, b, sz);`
> Also, it'd seem like a good idea to make the sanitizer message as clear as possible for this case, because Clang's behavior here is surprising.
@zygoloid
Is reusing the message for regular stores clear (current behavior) enough?
```
// CHECK-MEMCPY-STORE: misaligned.cpp:[[#@LINE+4]]{{(:12)?}}: runtime error: store to misaligned address [[PTR:0x[0-9a-f]*]] for type 'int *', which requires 4 byte alignment
```
https://github.com/llvm/llvm-project/pull/67766
More information about the cfe-commits
mailing list