]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
asan.c (build_check_stmt): Alignment arg was added.
authorMarat Zakirov <m.zakirov@samsung.com>
Fri, 19 Sep 2014 08:29:04 +0000 (08:29 +0000)
committerMarat Zakirov <mzakirov@gcc.gnu.org>
Fri, 19 Sep 2014 08:29:04 +0000 (08:29 +0000)
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

gcc/ChangeLog
gcc/asan.c
gcc/internal-fn.def
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/red-align-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/red-align-2.c [new file with mode: 0644]

index 827e5d2f79306e56a68710425fa714223b34563e..ecfb1a66b408efbc1cd11c36612fab4a1db5a190 100644 (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.
index 6ff85bbf8dd0e5e79113471c07e6d764455c1d75..2a90d863d072c61e0ff5f32f9f738bd49bbdfd70 100644 (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)
index 7ae60f31c62461a8b65b7edf86d76c9bd2191569..54ade9f1cb53c45230fe10615112c5d27743f506 100644 (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...")
index ddf4cde8ccdf3cc56892d8f40942a03421b59a1c..083c78bf30a7e843ebc42504d2458b12301a879e 100644 (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.
diff --git a/gcc/testsuite/c-c++-common/asan/red-align-1.c b/gcc/testsuite/c-c++-common/asan/red-align-1.c
new file mode 100644 (file)
index 0000000..afd7467
--- /dev/null
@@ -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" } } */
diff --git a/gcc/testsuite/c-c++-common/asan/red-align-2.c b/gcc/testsuite/c-c++-common/asan/red-align-2.c
new file mode 100644 (file)
index 0000000..d30b1ad
--- /dev/null
@@ -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" } } */