From f66d8ec8cad7d28d81b3ce55af92fb0169f8edeb Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 9 Apr 2015 21:51:08 +0200 Subject: [PATCH] re PR tree-optimization/65709 (Bad code for LZ4 decompression with -O3 on x86_64) PR tree-optimization/65709 * ubsan.c (instrument_mem_ref): Use TREE_TYPE (base) instead of TREE_TYPE (TREE_TYPE (t)). * c-c++-common/ubsan/align-9.c: New test. From-SVN: r221958 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 7 ++++++- gcc/testsuite/c-c++-common/ubsan/align-9.c | 21 +++++++++++++++++++++ gcc/ubsan.c | 4 ++-- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/ubsan/align-9.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 17fe5a153e2..cedbd18db9d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-04-09 Jakub Jelinek + + PR tree-optimization/65709 + * ubsan.c (instrument_mem_ref): Use TREE_TYPE (base) instead of + TREE_TYPE (TREE_TYPE (t)). + 2015-04-09 Vladimir Makarov PR target/65710 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da590b1a389..4be085d3bbe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,7 +1,12 @@ +2015-04-09 Jakub Jelinek + + PR tree-optimization/65709 + * c-c++-common/ubsan/align-9.c: New test. + 2013-04-09 Paul Thomas PR fortran/56852 - * gfortran.dg/pr56852.f90 : New test + * gfortran.dg/pr56852.f90: New test. 2015-04-09 Marek Polacek Jakub Jelinek diff --git a/gcc/testsuite/c-c++-common/ubsan/align-9.c b/gcc/testsuite/c-c++-common/ubsan/align-9.c new file mode 100644 index 00000000000..24cba94f277 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/align-9.c @@ -0,0 +1,21 @@ +/* Limit this to known non-strict alignment targets. */ +/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ +/* { dg-options "-O2 -fsanitize=alignment -fsanitize-recover=alignment" } */ + +__attribute__((noinline, noclone)) void +foo (void *p, const void *q) +{ + *(long int *) p = *(const long int *) q; +} + +int +main () +{ + struct S { long c; char f[64]; char d; char e[2 * sizeof (long)]; char g[64]; } s; + __builtin_memset (&s, '\0', sizeof s); + foo (&s.e[0], &s.e[sizeof (long)]); + return 0; +} + +/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'const long int', which requires \[48] byte alignment.*" } */ +/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*store to misaligned address 0x\[0-9a-fA-F]* for type 'long int', which requires \[48] byte alignment" } */ diff --git a/gcc/ubsan.c b/gcc/ubsan.c index b9d9f30e660..701e9f29228 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -1232,9 +1232,9 @@ instrument_mem_ref (tree mem, tree base, gimple_stmt_iterator *iter, tree t = TREE_OPERAND (base, 0); if (!POINTER_TYPE_P (TREE_TYPE (t))) return; - if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && mem != base) + if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (base)) && mem != base) ikind = UBSAN_MEMBER_ACCESS; - tree kind = build_int_cst (TREE_TYPE (t), ikind); + tree kind = build_int_cst (build_pointer_type (TREE_TYPE (base)), ikind); tree alignt = build_int_cst (pointer_sized_int_node, align); gcall *g = gimple_build_call_internal (IFN_UBSAN_NULL, 3, t, kind, alignt); gimple_set_location (g, gimple_location (gsi_stmt (*iter))); -- 2.30.2