opts.c (common_handle_option): Add support for -fno-sanitize=all and -f{,no-}sanitize...
authorJakub Jelinek <jakub@redhat.com>
Tue, 6 Jan 2015 09:52:06 +0000 (10:52 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 6 Jan 2015 09:52:06 +0000 (10:52 +0100)
* 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.

* 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.

From-SVN: r219241

gcc/ChangeLog
gcc/doc/invoke.texi
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/sanitize-all-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c [new file with mode: 0644]

index 812f980938b9fbe6204e8a4d02b9e82848bff0b8..daae241544f25a09246f97b8a279d63acd7df454 100644 (file)
@@ -1,3 +1,13 @@
+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.
index 2e587f5d8423563850c9f0f274895000e036e513..09706783a9a120b043c2232f1cf554c7dddbd8c0 100644 (file)
@@ -5689,6 +5689,8 @@ be a legitimate way of obtaining infinities and NaNs.
 @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
@@ -5724,6 +5726,13 @@ While @option{-ftrapv} causes traps for signed overflows to be emitted,
 @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.
@@ -5747,11 +5756,14 @@ Currently this feature only works for @option{-fsanitize=undefined} (and its sub
 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
index 1e7a2cc871012139d00a4a6826f837ceeb7c6a57..8a16116665f1bbc00eda0fba566b62f894ddb1be 100644 (file)
@@ -1588,6 +1588,7 @@ common_handle_option (struct gcc_options *opts,
                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;
@@ -1611,7 +1612,15 @@ common_handle_option (struct gcc_options *opts,
                  && 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;
index cbd491cc49de9bf39bc78526e298f8dcba0fa4db..634953cb0d5dc802c224930503dd11c1f109267f 100644 (file)
@@ -1,3 +1,11 @@
+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
diff --git a/gcc/testsuite/c-c++-common/asan/sanitize-all-1.c b/gcc/testsuite/c-c++-common/asan/sanitize-all-1.c
new file mode 100644 (file)
index 0000000..58e4079
--- /dev/null
@@ -0,0 +1,12 @@
+/* { 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" } } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c
new file mode 100644 (file)
index 0000000..9ffba50
--- /dev/null
@@ -0,0 +1,8 @@
+/* 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 } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c
new file mode 100644 (file)
index 0000000..6ae6f3c
--- /dev/null
@@ -0,0 +1,41 @@
+/* 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" } } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c
new file mode 100644 (file)
index 0000000..9be62ac
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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" } } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c
new file mode 100644 (file)
index 0000000..1f7ec2b
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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" } } */