Add pretty printer for ASAN_MARK and add a helper fn
authorMartin Liska <mliska@suse.cz>
Tue, 13 Dec 2016 09:14:47 +0000 (10:14 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 13 Dec 2016 09:14:47 +0000 (09:14 +0000)
* asan.c (asan_mark_poison_p): Remove.
(asan_mark_p): New function.
(transform_statements): Use the function.
(asan_expand_mark_ifn): Do not use masked enum.
* asan.h (enum asan_mark_flags): Declare it via a macro.
* gimple-pretty-print.c (dump_gimple_call_args): Dump first
argument of ASAN_MARK.
* gimplify.c (build_asan_poison_call_expr): Use new enum values.
(asan_poison_variable): Likewise.
* gcc.dg/asan/use-after-scope-goto-1.c: Update first argument of
scanned pattern ASAN_MARK.
* gcc.dg/asan/use-after-scope-goto-2.c: Likewise.
* gcc.dg/asan/use-after-scope-switch-1.c: Likewise.
* gcc.dg/asan/use-after-scope-switch-2.c: Likewise.
* gcc.dg/asan/use-after-scope-switch-3.c: Likewise.

From-SVN: r243597

12 files changed:
gcc/ChangeLog
gcc/asan.c
gcc/asan.h
gcc/gimple-pretty-print.c
gcc/gimple.c
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/use-after-scope-goto-1.c
gcc/testsuite/gcc.dg/asan/use-after-scope-goto-2.c
gcc/testsuite/gcc.dg/asan/use-after-scope-switch-1.c
gcc/testsuite/gcc.dg/asan/use-after-scope-switch-2.c
gcc/testsuite/gcc.dg/asan/use-after-scope-switch-3.c

index 5b478a3045e85a549f1dd52e5af46acb229df43c..9ae13c5ed054be31ea65619a3480115329376676 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-13  Martin Liska  <mliska@suse.cz>
+
+       * asan.c (asan_mark_poison_p): Remove.
+       (asan_mark_p): New function.
+       (transform_statements): Use the function.
+       (asan_expand_mark_ifn): Do not use masked enum.
+       * asan.h (enum asan_mark_flags): Declare it via a macro.
+       * gimple-pretty-print.c (dump_gimple_call_args): Dump first
+       argument of ASAN_MARK.
+       * gimplify.c (build_asan_poison_call_expr): Use new enum values.
+       (asan_poison_variable): Likewise.
+
 2016-12-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR ipa/77905
index 5af95472db9cafc08321fe805f4912f47d0b078a..e297784270d18cf19270eea3307ad8a7e710128d 100644 (file)
@@ -245,15 +245,6 @@ static unsigned HOST_WIDE_INT asan_shadow_offset_value;
 static bool asan_shadow_offset_computed;
 static vec<char *> sanitized_sections;
 
-/* Return true if STMT is ASAN_MARK poisoning internal function call.  */
-static inline bool
-asan_mark_poison_p (gimple *stmt)
-{
-  return (gimple_call_internal_p (stmt, IFN_ASAN_MARK)
-         && tree_to_uhwi (gimple_call_arg (stmt, 0)) == ASAN_MARK_CLOBBER);
-
-}
-
 /* Set of variable declarations that are going to be guarded by
    use-after-scope sanitizer.  */
 
@@ -303,6 +294,13 @@ set_sanitized_sections (const char *sections)
     }
 }
 
+bool
+asan_mark_p (gimple *stmt, enum asan_mark_flags flag)
+{
+  return (gimple_call_internal_p (stmt, IFN_ASAN_MARK)
+         && tree_to_uhwi (gimple_call_arg (stmt, 0)) == flag);
+}
+
 bool
 asan_sanitize_stack_p (void)
 {
@@ -2222,7 +2220,8 @@ transform_statements (void)
                 miss some instrumentation opportunities.  Do the same
                 for a ASAN_MARK poisoning internal function.  */
              if (is_gimple_call (s)
-                 && (!nonfreeing_call_p (s) || asan_mark_poison_p (s)))
+                 && (!nonfreeing_call_p (s)
+                     || asan_mark_p (s, ASAN_MARK_POISON)))
                empty_mem_ref_hash_table ();
 
              gsi_next (&i);
@@ -2777,9 +2776,8 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter)
 {
   gimple *g = gsi_stmt (*iter);
   location_t loc = gimple_location (g);
-  HOST_WIDE_INT flags = tree_to_shwi (gimple_call_arg (g, 0));
-  gcc_assert (flags < ASAN_MARK_LAST);
-  bool is_clobber = (flags & ASAN_MARK_CLOBBER) != 0;
+  HOST_WIDE_INT flag = tree_to_shwi (gimple_call_arg (g, 0));
+  bool is_poison = ((asan_mark_flags)flag) == ASAN_MARK_POISON;
 
   tree base = gimple_call_arg (g, 1);
   gcc_checking_assert (TREE_CODE (base) == ADDR_EXPR);
@@ -2827,7 +2825,7 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter)
          if (s > size_in_bytes)
            last_chunk_size = ASAN_SHADOW_GRANULARITY - (s - size_in_bytes);
 
-         asan_store_shadow_bytes (iter, loc, shadow, offset, is_clobber,
+         asan_store_shadow_bytes (iter, loc, shadow, offset, is_poison,
                                   size, last_chunk_size);
          offset += size;
        }
@@ -2840,7 +2838,7 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter)
       gsi_insert_before (iter, g, GSI_SAME_STMT);
       tree sz_arg = gimple_assign_lhs (g);
 
-      tree fun = builtin_decl_implicit (is_clobber ? BUILT_IN_ASAN_CLOBBER_N
+      tree fun = builtin_decl_implicit (is_poison ? BUILT_IN_ASAN_CLOBBER_N
                                        : BUILT_IN_ASAN_UNCLOBBER_N);
       g = gimple_build_call (fun, 2, base_addr, sz_arg);
       gimple_set_location (g, loc);
index 9cf5904618b09d2076f26122cbfa24f803bb9e29..355a350bfeb8c91ca09d9ee4a2de8b9ea7db234d 100644 (file)
@@ -75,13 +75,18 @@ enum asan_check_flags
 };
 
 /* Flags for Asan check builtins.  */
+#define IFN_ASAN_MARK_FLAGS DEF(POISON), DEF(UNPOISON)
+
 enum asan_mark_flags
 {
-  ASAN_MARK_CLOBBER = 1 << 0,
-  ASAN_MARK_UNCLOBBER = 1 << 1,
-  ASAN_MARK_LAST = 1 << 2
+#define DEF(X) ASAN_MARK_##X
+  IFN_ASAN_MARK_FLAGS
+#undef DEF
 };
 
+/* Return true if STMT is ASAN_MARK with FLAG as first argument.  */
+extern bool asan_mark_p (gimple *stmt, enum asan_mark_flags flag);
+
 /* Return the size of padding needed to insert after a protected
    decl of SIZE.  */
 
index b5e866d36fabeb3cd354d9f98f690522f166e833..1bd4cde03cf0e06f46e182503b9ef21f51c299d1 100644 (file)
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "value-prof.h"
 #include "trans-mem.h"
 #include "cfganal.h"
+#include "asan.h"
 
 #define INDENT(SPACE)                                                  \
   do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
@@ -644,6 +645,14 @@ dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
          limit = ARRAY_SIZE (reduction_args);
          break;
 
+       case IFN_ASAN_MARK:
+#define DEF(X) #X
+         static const char *const asan_mark_args[] = {IFN_ASAN_MARK_FLAGS};
+#undef DEF
+         enums = asan_mark_args;
+         limit = ARRAY_SIZE (asan_mark_args);
+         break;
+
        default:
          break;
        }
index 0a3dc72ea216b5bd07104ed0704bdd289c3d96f8..23e59c2f12354905f614ac7e739d516a081320fc 100644 (file)
@@ -2631,7 +2631,7 @@ nonfreeing_call_p (gimple *call)
       case IFN_ABNORMAL_DISPATCHER:
         return true;
       case IFN_ASAN_MARK:
-       return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNCLOBBER;
+       return tree_to_uhwi (gimple_call_arg (call, 0)) == ASAN_MARK_UNPOISON;
       default:
        if (gimple_call_flags (call) & ECF_LEAF)
          return true;
index b738855a63754afdb47aa945f44dbde09fef2abe..87615a95fb5c714e40b8c866430eed783634f33a 100644 (file)
@@ -1109,7 +1109,7 @@ build_asan_poison_call_expr (tree decl)
   return build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_ASAN_MARK,
                                       void_type_node, 3,
                                       build_int_cst (integer_type_node,
-                                                     ASAN_MARK_CLOBBER),
+                                                     ASAN_MARK_POISON),
                                       base, unit_size);
 }
 
@@ -1138,7 +1138,7 @@ asan_poison_variable (tree decl, bool poison, gimple_stmt_iterator *it,
   if (DECL_ALIGN_UNIT (decl) <= ASAN_SHADOW_GRANULARITY)
     SET_DECL_ALIGN (decl, BITS_PER_UNIT * ASAN_SHADOW_GRANULARITY);
 
-  HOST_WIDE_INT flags = poison ? ASAN_MARK_CLOBBER : ASAN_MARK_UNCLOBBER;
+  HOST_WIDE_INT flags = poison ? ASAN_MARK_POISON : ASAN_MARK_UNPOISON;
 
   gimple *g
     = gimple_build_call_internal (IFN_ASAN_MARK, 3,
index ac2a4f509a7a51760cfaa152142a8eacb33677dd..ff7bd7868bce1447c6db1380da62be21d9f6baca 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-13  Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/asan/use-after-scope-goto-1.c: Update first argument of
+       scanned pattern ASAN_MARK.
+       * gcc.dg/asan/use-after-scope-goto-2.c: Likewise.
+       * gcc.dg/asan/use-after-scope-switch-1.c: Likewise.
+       * gcc.dg/asan/use-after-scope-switch-2.c: Likewise.
+       * gcc.dg/asan/use-after-scope-switch-3.c: Likewise.
+
 2016-12-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR ipa/77905
index c47a5e8db023a7e87fa5f583898beb07b12d0622..c1538e4e29b63b34d39877823f475739c38dd69a 100644 (file)
@@ -42,6 +42,6 @@ int main(int argc, char **argv)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, 4\\);" 2 "asan0" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &c, 4\\);" 2 "asan0" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &e, 4\\);" 2 "asan0" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, 4\\);" 2 "asan0" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &c, 4\\);" 2 "asan0" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &e, 4\\);" 2 "asan0" } }  */
index 73ef4e0eb1ed4ca427b79e6f06c4b1b67023dfdc..7c396141d9bc7ff119f915a0223fbe563fb78a3d 100644 (file)
@@ -22,4 +22,4 @@ int main(int argc, char **argv)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, 4\\);" 1 "asan0" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, 4\\);" 1 "asan0" } }  */
index a8342686d4eb66ad8efb84100c965b2af18f0dba..d4d753936bb4899e78d6fbf87d98e8707e49e09d 100644 (file)
@@ -21,5 +21,5 @@ main (int argc, char **argv)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 2 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 2 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } }  */
index 8aeca5a3b7ad7805500e86288040ba50cbabccbe..5a5ea375e183ea671c477e269117f9b34abfa32b 100644 (file)
@@ -25,9 +25,9 @@ main (int argc, char **argv)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 2 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &b, \[0-9\]\\);" 2 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &c, \[0-9\]\\);" 2 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &b, \[0-9\]\\);" 1 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &c, \[0-9\]\\);" 1 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 2 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &b, \[0-9\]\\);" 2 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &c, \[0-9\]\\);" 2 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &b, \[0-9\]\\);" 1 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &c, \[0-9\]\\);" 1 "gimple" } }  */
index 828cb7c3b2abc5f9da31601b7dde3258a8129f59..f361591351b7ed16e913368c31b631cd58ee9731 100644 (file)
@@ -32,5 +32,5 @@ main (int argc, char **argv)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(2, &a, \[0-9\]\\);" 4 "gimple" } }  */
-/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(1, &a, \[0-9\]\\);" 1 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &a, \[0-9\]\\);" 4 "gimple" } }  */
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(POISON, &a, \[0-9\]\\);" 1 "gimple" } }  */