* 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.
Change-Id: Ife3e6037a03ec2b25a15d45bb301f43b750e6649
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@
243597138bc75d-0d04-0410-961f-
82ee72b054a4
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. */
}
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)
{
return ((flag_sanitize & SANITIZE_ADDRESS)
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);
{
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);
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;
}
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);
};
/* 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. */
#include "dumpfile.h" /* for dump_flags */
#include "value-prof.h"
#include "trans-mem.h"
+#include "asan.h"
#define INDENT(SPACE) \
do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
static void
dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
{
- size_t i;
+ size_t i = 0;
- for (i = 0; i < gimple_call_num_args (gs); i++)
+ /* Pretty print first arg to certain internal fns. */
+ if (gimple_call_internal_p (gs))
{
- dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
- if (i < gimple_call_num_args (gs) - 1)
+ const char *const *enums = NULL;
+ unsigned limit = 0;
+
+ switch (gimple_call_internal_fn (gs))
+ {
+ 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;
+ }
+ if (limit)
+ {
+ tree arg0 = gimple_call_arg (gs, 0);
+ HOST_WIDE_INT v;
+
+ if (TREE_CODE (arg0) == INTEGER_CST
+ && tree_fits_shwi_p (arg0)
+ && (v = tree_to_shwi (arg0)) >= 0 && v < limit)
+ {
+ i++;
+ pp_string (buffer, enums[v]);
+ }
+ }
+ }
+
+
+ for (; i < gimple_call_num_args (gs); i++)
+ {
+ if (i)
pp_string (buffer, ", ");
+ dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
}
if (gimple_call_va_arg_pack_p (gs))
{
- if (gimple_call_num_args (gs) > 0)
- {
- pp_comma (buffer);
- pp_space (buffer);
- }
+ if (i)
+ pp_string (buffer, ", ");
pp_string (buffer, "__builtin_va_arg_pack ()");
}
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;
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);
}
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,
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" } } */
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" } } */
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" } } */
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" } } */
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" } } */