+2015-01-06 Jakub Jelinek <jakub@redhat.com>
+
+ * opts.c (common_handle_option): Add support for
+ -fno-sanitize=all and -f{,no-}sanitize-recover=all.
+ * doc/invoke.texi: Document -fno-sanitize=all,
+ -f{,no-}sanitize-recover=all. Document that
+ -fsanitize=float-cast-overflow is not enabled
+ by -fsanitize=undefined. Fix up documentation
+ of -f{,no-}sanitize-recover.
+
2015-01-06 Eric Botcazou <ebotcazou@adacore.com>
* config.gcc: Add Visium support.
@opindex fsanitize=float-cast-overflow
This option enables floating-point type to integer conversion checking.
We check that the result of the conversion does not overflow.
+Unlike other similar options, @option{-fsanitize=float-cast-overflow} is
+not enabled by @option{-fsanitize=undefined}.
This option does not work well with @code{FE_INVALID} exceptions enabled.
@item -fsanitize=nonnull-attribute
@option{-fsanitize=undefined} gives a diagnostic message.
This currently works only for the C family of languages.
+@item -fno-sanitize=all
+@opindex fno-sanitize=all
+
+This option disables all previously enabled sanitizers.
+@option{-fsanitize=all} is not allowed, as some sanitizers cannot be used
+together.
+
@item -fasan-shadow-offset=@var{number}
@opindex fasan-shadow-offset
This option forces GCC to use custom shadow offset in AddressSanitizer checks.
except for @option{-fsanitize=unreachable} and @option{-fsanitize=return}),
@option{-fsanitize=float-cast-overflow}, @option{-fsanitize=float-divide-by-zero} and
@option{-fsanitize=kernel-address}. For these sanitizers error recovery is turned on by default.
+@option{-fsanitize-recover=all} and @option{-fno-sanitize-recover=all} is also
+accepted, the former enables recovery for all sanitizers that support it,
+the latter disables recovery for all sanitizers that support it.
Syntax without explicit @var{opts} parameter is deprecated. It is equivalent to
-@option{-fsanitize-recover=undefined,float-cast-overflow,float-divide-by-zero,kernel-address}.
+@option{-fsanitize-recover=undefined,float-cast-overflow,float-divide-by-zero}.
Similarly @option{-fno-sanitize-recover} is equivalent to
-@option{-fno-sanitize-recover=undefined,float-cast-overflow,float-divide-by-zero,kernel-address}.
+@option{-fno-sanitize-recover=undefined,float-cast-overflow,float-divide-by-zero}.
@item -fsanitize-undefined-trap-on-error
@opindex fsanitize-undefined-trap-on-error
sizeof "returns-nonnull-attribute" - 1 },
{ "object-size", SANITIZE_OBJECT_SIZE,
sizeof "object-size" - 1 },
+ { "all", ~0, sizeof "all" - 1 },
{ NULL, 0, 0 }
};
const char *comma;
&& memcmp (p, spec[i].name, len) == 0)
{
/* Handle both -fsanitize and -fno-sanitize cases. */
- if (value)
+ if (value && spec[i].flag == ~0U)
+ {
+ if (code == OPT_fsanitize_)
+ error_at (loc, "-fsanitize=all option is not valid");
+ else
+ *flag |= ~(SANITIZE_USER_ADDRESS | SANITIZE_THREAD
+ | SANITIZE_LEAK);
+ }
+ else if (value)
*flag |= spec[i].flag;
else
*flag &= ~spec[i].flag;
+2015-01-06 Jakub Jelinek <jakub@redhat.com>
+
+ * c-c++-common/asan/sanitize-all-1.c: New test.
+ * c-c++-common/ubsan/sanitize-all-1.c: New test.
+ * c-c++-common/ubsan/sanitize-all-2.c: New test.
+ * c-c++-common/ubsan/sanitize-all-3.c: New test.
+ * c-c++-common/ubsan/sanitize-all-4.c: New test.
+
2015-01-06 Eric Botcazou <ebotcazou@adacore.com>
* lib/target-supports.exp (check_profiling_available): Return 0 for
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fno-sanitize=all" } */
+
+volatile int ten = 10;
+
+int main() {
+ volatile char x[10];
+ x[ten];
+ return 0;
+}
+
+/* { dg-final { scan-assembler-not "__asan_load" } } */
--- /dev/null
+/* Test -f*sanitize*=all */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-options "-fsanitize=all" } */
+
+int i;
+
+/* { dg-error "-fsanitize=all option is not valid" "" { target *-*-* } 0 } */
--- /dev/null
+/* Test -f*sanitize*=all */
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
+/* { dg-options "-fsanitize=undefined,float-cast-overflow,float-divide-by-zero -fno-sanitize=all -fdump-tree-optimized" } */
+
+int a[4];
+
+int
+f1 (int x, int y, int z)
+{
+ return a[x] + (1 << y) + (100 / z);
+}
+
+char *
+f2 (int x)
+{
+ char *p = (char *) __builtin_calloc (64, 1);
+ p[x] = 3;
+ return p;
+}
+
+int
+f3 (int x, int *y, double z, double w)
+{
+ int a[*y];
+ if (x)
+ __builtin_unreachable ();
+ asm volatile ("" : : "r" (&a[0]));
+ return z / w;
+}
+
+int
+main ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "__ubsan_" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "UBSAN_CHECK_" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
--- /dev/null
+/* Test -f*sanitize*=all */
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
+/* { dg-options "-fsanitize=undefined -fsanitize-recover=all -fdump-tree-optimized" } */
+
+int a[4];
+
+int
+f1 (int x, int y, int z)
+{
+ return a[x] + (1 << y) + (100 / z);
+}
+
+char *
+f2 (int x)
+{
+ char *p = (char *) __builtin_calloc (64, 1);
+ p[x] = 3;
+ return p;
+}
+
+int
+f3 (int x, int *y, double z, double w)
+{
+ int a[*y];
+ if (x)
+ __builtin_unreachable ();
+ asm volatile ("" : : "r" (&a[0]));
+ return z / w;
+}
+
+int
+main ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump "__ubsan_" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*_abort" "optimized" } } */
+/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
--- /dev/null
+/* Test -f*sanitize*=all */
+/* { dg-do run } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
+/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
+/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=all -fdump-tree-optimized" } */
+
+int a[4];
+
+int
+f1 (int x, int y, int z)
+{
+ return a[x] + (1 << y) + (100 / z);
+}
+
+char *
+f2 (int x)
+{
+ char *p = (char *) __builtin_calloc (64, 1);
+ p[x] = 3;
+ return p;
+}
+
+int
+f3 (int x, int *y, double z, double w)
+{
+ int a[*y];
+ if (x)
+ __builtin_unreachable ();
+ asm volatile ("" : : "r" (&a[0]));
+ return z / w;
+}
+
+int
+main ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump "__ubsan_\[a-z_\]*_abort" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*\[^et\] " "optimized" } } */
+/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */