gcc/ChangeLog:
2014-11-14 Marat Zakirov <m.zakirov@samsung.com>
* asan.c (asan_expand_check_ifn): Ignore alignment by option.
* doc/invoke.texi: Document.
* params.def (asan-alignment-optimize): New.
* params.h: Likewise.
gcc/testsuite/ChangeLog:
2014-11-14 Marat Zakirov <m.zakirov@samsung.com>
* c-c++-common/asan/red-align-3.c: New test.
@@ -2518,6 +2518,12 @@ asan_expand_check_ifn (gimple_stmt_iterator *iter, bool use_calls)
HOST_WIDE_INT size_in_bytes
= is_scalar_access && tree_fits_shwi_p (len) ? tree_to_shwi (len) : -1;
+
+ if (!ASAN_ALIGNMENT_OPTIMIZE && size_in_bytes > 1)
+ {
+ size_in_bytes = -1;
+ align = 1;
+ }
if (use_calls)
{
@@ -10580,6 +10580,12 @@ is greater or equal to this number, use callbacks instead of inline checks.
E.g. to disable inline code use
@option{--param asan-instrumentation-with-call-threshold=0}.
+@item asan-alignment-optimize
+Enable asan optimization for aligned accesses.
+It is enabled by default when using @option{-fsanitize=address} option.
+To disable optimization for aligned accesses use
+@option{--param asan-alignment-optimize=0}.
+
@item chkp-max-ctor-size
Static constructors generated by Pointer Bounds Checker may become very
large and significantly increase compile time at optimization level
@@ -1114,6 +1114,11 @@ DEFPARAM (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD,
"in function becomes greater or equal to this number",
7000, 0, INT_MAX)
+DEFPARAM (PARAM_ASAN_ALIGNMENT_OPTIMIZE,
+ "asan-alignment-optimize",
+ "Enable asan optimization for aligned access",
+ 1, 0, 1)
+
DEFPARAM (PARAM_UNINIT_CONTROL_DEP_ATTEMPTS,
"uninit-control-dep-attempts",
"Maximum number of nested calls to search for control dependencies "
@@ -238,5 +238,7 @@ extern void init_param_values (int *params);
PARAM_VALUE (PARAM_ASAN_USE_AFTER_RETURN)
#define ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD \
PARAM_VALUE (PARAM_ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD)
+#define ASAN_ALIGNMENT_OPTIMIZE \
+ PARAM_VALUE (PARAM_ASAN_ALIGNMENT_OPTIMIZE)
#endif /* ! GCC_PARAMS_H */
new file mode 100644
@@ -0,0 +1,34 @@
+/* { dg-options "-fdump-tree-sanopt --param asan-alignment-optimize=0" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void *memset (void *, int, __SIZE_TYPE__);
+#ifdef __cplusplus
+}
+#endif
+
+struct dummy {
+ int a;
+ int b;
+ int c;
+ int d;
+};
+
+volatile struct dummy * new_p;
+volatile struct dummy * old_p;
+
+void foo(void)
+{
+ *(volatile char *)(0x12);
+ *(volatile short int *)(0x12);
+ *(volatile unsigned int *)(0x12);
+ *(volatile unsigned long long *)(0x12);
+ *new_p = *old_p;
+}
+
+/* { dg-final { scan-tree-dump-times ">> 3" 11 "sanopt" } } */
+/* { dg-final { scan-tree-dump-times "& 7" 11 "sanopt" } } */
+/* { dg-final { cleanup-tree-dump "sanopt" } } */