diff options
author | Yury Gribov <y.gribov@samsung.com> | 2014-11-18 07:37:17 +0000 |
---|---|---|
committer | Yury Gribov <ygribov@gcc.gnu.org> | 2014-11-18 07:37:17 +0000 |
commit | 24ebfddf68935c1eee6e91296040edc8a0ebb5d8 (patch) | |
tree | 90dca729a9de6cf67659d3f673f4f7000930375a /gcc | |
parent | 005581f187d790a411a6e96e8002cb56bc1ae12c (diff) | |
download | gcc-24ebfddf68935c1eee6e91296040edc8a0ebb5d8.zip gcc-24ebfddf68935c1eee6e91296040edc8a0ebb5d8.tar.gz gcc-24ebfddf68935c1eee6e91296040edc8a0ebb5d8.tar.bz2 |
re PR sanitizer/63802 (UBSan doesn't catch misaligned access if address is 16-bytes (or more) aligned)
2014-11-18 Yury Gribov <y.gribov@samsung.com>
PR sanitizer/63802
gcc/
* stor-layout.c (min_align_of_type): Respect user alignment
more.
gcc/testsuite/
* c-c++-common/ubsan/pr63802.c: New test.
From-SVN: r217689
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/stor-layout.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/ubsan/pr63802.c | 23 |
4 files changed, 35 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0befede..c0649cf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-11-18 Yury Gribov <y.gribov@samsung.com> + + PR sanitizer/63802 + * stor-layout.c (min_align_of_type): Respect user alignment + more. + 2014-11-18 Ilya Enkovich <ilya.enkovich@intel.com> * passes.c (remove_cgraph_node_from_order): New. diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 431b207..db09855 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2430,9 +2430,9 @@ unsigned int min_align_of_type (tree type) { unsigned int align = TYPE_ALIGN (type); - align = MIN (align, BIGGEST_ALIGNMENT); if (!TYPE_USER_ALIGN (type)) { + align = MIN (align, BIGGEST_ALIGNMENT); #ifdef BIGGEST_FIELD_ALIGNMENT align = MIN (align, BIGGEST_FIELD_ALIGNMENT); #endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c97fe88..8a924cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-11-18 Yury Gribov <y.gribov@samsung.com> + + PR sanitizer/63802 + * c-c++-common/ubsan/pr63802.c: New test. + 2014-11-18 Ilya Enkovich <ilya.enkovich@intel.com> * g++.dg/pr63766.C: New. diff --git a/gcc/testsuite/c-c++-common/ubsan/pr63802.c b/gcc/testsuite/c-c++-common/ubsan/pr63802.c new file mode 100644 index 0000000..454c098 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/pr63802.c @@ -0,0 +1,23 @@ +/* Limit this to known non-strict alignment targets. */ +/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ +/* { dg-options "-fsanitize=alignment" } */ + +#define __round_mask(x, y) ((__typeof__(x))((y)-1)) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) + +struct test_struct { + unsigned long a; + int b; +} __attribute__((__aligned__(64))); + +char a[200]; + +int main () +{ + volatile int x = ((struct test_struct*)(round_up((unsigned long)a, 64) + 16))->b; + volatile int y = ((struct test_struct*)(round_up((unsigned long)a, 64) + 15))->b; + + return 0; +} + +/* { dg-output "\.c:18:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct test_struct', which requires 64 byte alignment.*" } */ |