Commit fb153d02 by Jakub Jelinek Committed by Jakub Jelinek

opts.c (common_handle_option): Add support for -fno-sanitize=all and -f{,no-}sanitize-recover=all.

	* 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
parent a1954e97
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> 2015-01-06 Eric Botcazou <ebotcazou@adacore.com>
* config.gcc: Add Visium support. * config.gcc: Add Visium support.
......
...@@ -5689,6 +5689,8 @@ be a legitimate way of obtaining infinities and NaNs. ...@@ -5689,6 +5689,8 @@ be a legitimate way of obtaining infinities and NaNs.
@opindex fsanitize=float-cast-overflow @opindex fsanitize=float-cast-overflow
This option enables floating-point type to integer conversion checking. This option enables floating-point type to integer conversion checking.
We check that the result of the conversion does not overflow. 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. This option does not work well with @code{FE_INVALID} exceptions enabled.
@item -fsanitize=nonnull-attribute @item -fsanitize=nonnull-attribute
...@@ -5724,6 +5726,13 @@ While @option{-ftrapv} causes traps for signed overflows to be emitted, ...@@ -5724,6 +5726,13 @@ While @option{-ftrapv} causes traps for signed overflows to be emitted,
@option{-fsanitize=undefined} gives a diagnostic message. @option{-fsanitize=undefined} gives a diagnostic message.
This currently works only for the C family of languages. 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} @item -fasan-shadow-offset=@var{number}
@opindex fasan-shadow-offset @opindex fasan-shadow-offset
This option forces GCC to use custom shadow offset in AddressSanitizer checks. 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 ...@@ -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}), except for @option{-fsanitize=unreachable} and @option{-fsanitize=return}),
@option{-fsanitize=float-cast-overflow}, @option{-fsanitize=float-divide-by-zero} and @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=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 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 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 @item -fsanitize-undefined-trap-on-error
@opindex fsanitize-undefined-trap-on-error @opindex fsanitize-undefined-trap-on-error
......
...@@ -1588,6 +1588,7 @@ common_handle_option (struct gcc_options *opts, ...@@ -1588,6 +1588,7 @@ common_handle_option (struct gcc_options *opts,
sizeof "returns-nonnull-attribute" - 1 }, sizeof "returns-nonnull-attribute" - 1 },
{ "object-size", SANITIZE_OBJECT_SIZE, { "object-size", SANITIZE_OBJECT_SIZE,
sizeof "object-size" - 1 }, sizeof "object-size" - 1 },
{ "all", ~0, sizeof "all" - 1 },
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
const char *comma; const char *comma;
...@@ -1611,7 +1612,15 @@ common_handle_option (struct gcc_options *opts, ...@@ -1611,7 +1612,15 @@ common_handle_option (struct gcc_options *opts,
&& memcmp (p, spec[i].name, len) == 0) && memcmp (p, spec[i].name, len) == 0)
{ {
/* Handle both -fsanitize and -fno-sanitize cases. */ /* 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; *flag |= spec[i].flag;
else else
*flag &= ~spec[i].flag; *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> 2015-01-06 Eric Botcazou <ebotcazou@adacore.com>
* lib/target-supports.exp (check_profiling_available): Return 0 for * lib/target-supports.exp (check_profiling_available): Return 0 for
......
/* { 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" } } */
/* 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 } */
/* 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" } } */
/* 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" } } */
/* 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" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment