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
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
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
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
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
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
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`.
>
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
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
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
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
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
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
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
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.
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
@@ -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
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
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
@@ -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
@@ -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
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
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
@@ -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
@@ -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
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
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
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));
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)
29 matches
Mail list logo