[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-10 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay closed https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-09 Thread Fangrui Song via cfe-commits
MaskRay wrote: Add the test to `clang/test/CodeGen/catch-undef-behavior.c` ca810073b3e4cef8ed58c03dcc724771f8f8615b ``` + /// Casting to void * or char * drops the alignment requirement. + memcpy((void *)p, (char *)q, sz); ``` https://github.com/llvm/llvm-project/pull/67766

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-09 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/67766 >From ca810073b3e4cef8ed58c03dcc724771f8f8615b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 28 Sep 2023 15:22:38 -0700 Subject: [PATCH] -fsanitize=alignment: check memcpy/memmove arguments The

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-09 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-09 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-09 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/67766 >From 24d675673844f22e8aef8dc183874696216abb1d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 28 Sep 2023 15:22:38 -0700 Subject: [PATCH 1/2] -fsanitize=alignment: check memcpy/memmove arguments Similar

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-08 Thread Fangrui Song via cfe-commits
MaskRay wrote: > @zygoloid Thanks for the explanation! I wasn't aware this fell under > unspecified behavior. It's weird that alignment information can survive a > `void *` cast, but it does make some sense. Yes, `(void *)x` decreases the alignment requirement to 1 byte like `(char *)x`. >

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-02 Thread Nikita Popov via cfe-commits
nikic wrote: @zygoloid Thanks for the explanation! I wasn't aware this fell under unspecified behavior. It's weird that alignment information can survive a `void *` cast, but it does make some sense. What seems worrying here is that apparently GCC and Clang do not agree on semantics in this

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-02 Thread Fangrui Song via cfe-commits
MaskRay wrote: > > @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

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-10-01 Thread Richard Smith via cfe-commits
zygoloid wrote: > @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

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-30 Thread Fangrui Song via cfe-commits
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

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Richard Smith via cfe-commits
zygoloid wrote: > Uh, why are we allowed to assume that memcpy pointer arguments are aligned? > This looks like a miscompile to me. This is definitely a bit weird, but... > A plain `int *` pointer is not required to be aligned, and memcpy works on > `void *` pointers, so I'm not sure where

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
https://github.com/vitalybuka approved this pull request. https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
vitalybuka wrote: LGTM, but you probably want @rjmccall or @zygoloid review. https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Nikita Popov via cfe-commits
nikic wrote: Uh, why are we allowed to assume that memcpy pointer arguments are aligned? This looks like a miscompile to me. A plain `int *` pointer is not required to be aligned, and memcpy works on `void *` pointers, so I'm not sure where an alignment requirement would appear from.

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
@@ -47,6 +50,16 @@ int main(int, char **argv) { return *p && 0; // CHECK-STACK-LOAD: #0 {{.*}}main{{.*}}misaligned.cpp + case 'L': { +int x; +// CHECK-MEMCPY-LOAD: misaligned.cpp:[[#@LINE+4]]{{(:16)?}}: runtime error: load of misaligned address

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/67766 >From 993c23c8cce72e3e1b4ad0924d96c9eac1955d85 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 28 Sep 2023 15:22:38 -0700 Subject: [PATCH 1/2] -fsanitize=alignment: check memcpy/memmove arguments Similar

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/67766 >From 993c23c8cce72e3e1b4ad0924d96c9eac1955d85 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 28 Sep 2023 15:22:38 -0700 Subject: [PATCH 1/2] -fsanitize=alignment: check memcpy/memmove arguments Similar

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
@@ -47,6 +50,16 @@ int main(int, char **argv) { return *p && 0; // CHECK-STACK-LOAD: #0 {{.*}}main{{.*}}misaligned.cpp + case 'L': { +int x; +// CHECK-MEMCPY-LOAD: misaligned.cpp:[[#@LINE+4]]{{(:16)?}}: runtime error: load of misaligned address

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
@@ -47,6 +50,16 @@ int main(int, char **argv) { return *p && 0; // CHECK-STACK-LOAD: #0 {{.*}}main{{.*}}misaligned.cpp + case 'L': { +int x; +// CHECK-MEMCPY-LOAD: misaligned.cpp:[[#@LINE+4]]{{(:16)?}}: runtime error: load of misaligned address

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
https://github.com/vitalybuka deleted https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
https://github.com/vitalybuka deleted https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
@@ -47,6 +50,16 @@ int main(int, char **argv) { return *p && 0; // CHECK-STACK-LOAD: #0 {{.*}}main{{.*}}misaligned.cpp + case 'L': { +int x; +// CHECK-MEMCPY-LOAD: misaligned.cpp:[[#@LINE+4]]{{(:16)?}}: runtime error: load of misaligned address

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Vitaly Buka via cfe-commits
@@ -47,6 +50,16 @@ int main(int, char **argv) { return *p && 0; // CHECK-STACK-LOAD: #0 {{.*}}main{{.*}}misaligned.cpp + case 'L': { +int x; +// CHECK-MEMCPY-LOAD: misaligned.cpp:[[#@LINE+4]]{{(:16)?}}: runtime error: load of misaligned address

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/67766 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-29 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/67766 >From b1201f3fd4d758b739b04e3d5e474549917added Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 28 Sep 2023 15:22:38 -0700 Subject: [PATCH] -fsanitize=alignment: check memcpy/memmove arguments Similar to

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-28 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Changes Similar to https://reviews.llvm.org/D9673, emit -fsanitize=alignment check for arguments of builtin memcpy and memmove functions to catch misaligned load like: ``` // Check a void unaligned_load(int *a, void *b) { memcpy(a, b, sizeof(*a));

[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-28 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/67766 Similar to https://reviews.llvm.org/D9673, emit -fsanitize=alignment check for arguments of builtin memcpy and memmove functions to catch misaligned load like: ``` // Check a void unaligned_load(int *a, void *b)