asan.c (build_check_stmt): Alignment arg was added.

gcc/ChangeLog:

2014-09-19  Marat Zakirov  <m.zakirov@samsung.com>

	* asan.c (build_check_stmt): Alignment arg was added.
	(asan_expand_check_ifn): Optimization for alignment >= 8.

gcc/testsuite/ChangeLog:

2014-09-19  Marat Zakirov  <m.zakirov@samsung.com>

	* c-c++-common/asan/red-align-1.c: New test.
	* c-c++-common/asan/red-align-2.c: New test.

From-SVN: r215380
This commit is contained in:
Marat Zakirov 2014-09-19 08:29:04 +00:00 committed by Marat Zakirov
parent 4ce351defb
commit f434eb6997
6 changed files with 60 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2014-09-19 Marat Zakirov <m.zakirov@samsung.com>
* asan.c (build_check_stmt): Alignment arg was added.
(asan_expand_check_ifn): Optimization for alignment >= 8.
2014-09-19 Olivier Hainque <hainque@adacore.com>
* config/i386/vxworksae.h: Remove obsolete definitions.

View File

@ -1667,9 +1667,11 @@ build_check_stmt (location_t loc, tree base, tree len,
if (end_instrumented)
flags |= ASAN_CHECK_END_INSTRUMENTED;
g = gimple_build_call_internal (IFN_ASAN_CHECK, 3,
g = gimple_build_call_internal (IFN_ASAN_CHECK, 4,
build_int_cst (integer_type_node, flags),
base, len);
base, len,
build_int_cst (integer_type_node,
align / BITS_PER_UNIT));
gimple_set_location (g, loc);
if (before_p)
gsi_insert_before (&gsi, g, GSI_SAME_STMT);
@ -2466,6 +2468,7 @@ asan_expand_check_ifn (gimple_stmt_iterator *iter, bool use_calls)
tree base = gimple_call_arg (g, 1);
tree len = gimple_call_arg (g, 2);
HOST_WIDE_INT align = tree_to_shwi (gimple_call_arg (g, 3));
HOST_WIDE_INT size_in_bytes
= is_scalar_access && tree_fits_shwi_p (len) ? tree_to_shwi (len) : -1;
@ -2576,7 +2579,10 @@ asan_expand_check_ifn (gimple_stmt_iterator *iter, bool use_calls)
gimple shadow_test = build_assign (NE_EXPR, shadow, 0);
gimple_seq seq = NULL;
gimple_seq_add_stmt (&seq, shadow_test);
gimple_seq_add_stmt (&seq, build_assign (BIT_AND_EXPR, base_addr, 7));
/* Aligned (>= 8 bytes) access do not need & 7. */
if (align < 8)
gimple_seq_add_stmt (&seq, build_assign (BIT_AND_EXPR,
base_addr, 7));
gimple_seq_add_stmt (&seq, build_type_cast (shadow_type,
gimple_seq_last (seq)));
if (real_size_in_bytes > 1)

View File

@ -55,4 +55,4 @@ DEF_INTERNAL_FN (UBSAN_CHECK_SUB, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
DEF_INTERNAL_FN (UBSAN_CHECK_MUL, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
DEF_INTERNAL_FN (ABNORMAL_DISPATCHER, ECF_NORETURN, NULL)
DEF_INTERNAL_FN (BUILTIN_EXPECT, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
DEF_INTERNAL_FN (ASAN_CHECK, ECF_TM_PURE | ECF_LEAF | ECF_NOTHROW, ".W..")
DEF_INTERNAL_FN (ASAN_CHECK, ECF_TM_PURE | ECF_LEAF | ECF_NOTHROW, ".W...")

View File

@ -1,3 +1,8 @@
2014-09-19 Marat Zakirov <m.zakirov@samsung.com>
* c-c++-common/asan/red-align-1.c: New test.
* c-c++-common/asan/red-align-2.c: New test.
2014-09-18 H.J. Lu <hongjiu.lu@intel.com>
* gcc.dg/pr61053.c: Updated for x32.

View File

@ -0,0 +1,20 @@
/* This tests aligment propagation to structure elem and
abcense of redundant & 7. */
/* { dg-options "-fdump-tree-sanopt" } */
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
struct st {
int a;
int b;
int c;
} __attribute__((aligned(16)));
int foo (struct st * s_p)
{
return s_p->a;
}
/* { dg-final { scan-tree-dump-times "& 7" 0 "sanopt" } } */
/* { dg-final { cleanup-tree-dump "sanopt" } } */

View File

@ -0,0 +1,20 @@
/* This tests aligment propagation to structure elem and
abcense of redundant & 7. */
/* { dg-options "-fdump-tree-sanopt" } */
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
struct st {
int a;
int b;
int c;
} __attribute__((aligned(16)));
int foo (struct st * s_p)
{
return s_p->b;
}
/* { dg-final { scan-tree-dump-times "& 7" 1 "sanopt" } } */
/* { dg-final { cleanup-tree-dump "sanopt" } } */