options: Fix up -fsanitize-coverage= [PR104158]

This is incremental patch to fix up -fsanitize-coverage= option
handling, allow -fno-sanitize-coverage= again, allow both
options together in one option or make
-fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp
actually enable both suboptions rather than the last one.

2022-01-24  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/104158
	* common.opt (flag_sanitize_coverage): Remove Variable entry.
	(fsanitize-coverage=): Remove RejectNegative property, add
	Var(flag_sanitize_coverage) and EnumSet properties.
	(trace-pc): Add Set(1) property.
	(trace-cmp): Add Set(2) property.
	* opts.cc (common_handle_option): Don't handle
	OPT_fsanitize_coverage_.

	* gcc.dg/spellcheck-options-24.c: New test.
	* gcc.dg/sancov/pr104158-1.c: New test.
	* gcc.dg/sancov/pr104158-2.c: New test.
	* gcc.dg/sancov/pr104158-3.c: New test.
	* gcc.dg/sancov/pr104158-4.c: New test.
	* gcc.dg/sancov/pr104158-5.c: New test.
	* gcc.dg/sancov/pr104158-6.c: New test.
	* gcc.dg/sancov/pr104158-7.c: New test.
This commit is contained in:
Jakub Jelinek 2022-01-24 11:51:49 +01:00
parent 385196adb5
commit cd0377a460
10 changed files with 79 additions and 11 deletions

View File

@ -223,10 +223,6 @@ unsigned int flag_sanitize
Variable
unsigned int flag_sanitize_recover = (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT | SANITIZE_KERNEL_ADDRESS | SANITIZE_KERNEL_HWADDRESS) & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN)
; What the coverage sanitizers should instrument
Variable
unsigned int flag_sanitize_coverage
; Flag whether a prefix has been added to dump_base_name
Variable
bool dump_base_name_prefixed = false
@ -1076,17 +1072,17 @@ Common Driver Joined
Select what to sanitize.
fsanitize-coverage=
Common Joined RejectNegative Enum(sanitize_coverage)
Common Joined Enum(sanitize_coverage) Var(flag_sanitize_coverage) EnumSet
Select type of coverage sanitization.
Enum
Name(sanitize_coverage) Type(int)
EnumValue
Enum(sanitize_coverage) String(trace-pc) Value(SANITIZE_COV_TRACE_PC)
Enum(sanitize_coverage) String(trace-pc) Value(SANITIZE_COV_TRACE_PC) Set(1)
EnumValue
Enum(sanitize_coverage) String(trace-cmp) Value(SANITIZE_COV_TRACE_CMP)
Enum(sanitize_coverage) String(trace-cmp) Value(SANITIZE_COV_TRACE_CMP) Set(2)
fasan-shadow-offset=
Common Joined RejectNegative Var(common_deferred_options) Defer

View File

@ -2621,10 +2621,6 @@ common_handle_option (struct gcc_options *opts,
&= ~(SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
break;
case OPT_fsanitize_coverage_:
opts->x_flag_sanitize_coverage = value;
break;
case OPT_O:
case OPT_Os:
case OPT_Ofast:

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-cmp -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump-not "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-pc -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-not "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-cmp,trace-pc -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-pc,trace-cmp -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-cmp -fsanitize-coverage=trace-pc -fno-sanitize-coverage=trace-cmp -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-not "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,11 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-cmp -fsanitize-coverage=trace-pc -fno-sanitize-coverage=trace-pc,trace-cmp -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-not "__sanitizer_cov_trace_cmp" "optimized" } } */
/* { dg-final { scan-tree-dump-not "__sanitizer_cov_trace_pc" "optimized" } } */
int
foo (int a, int b)
{
return a == b;
}

View File

@ -0,0 +1,5 @@
/* PR sanitizer/104158 */
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-cmp,trace-cmp -fdump-tree-optimized" } */
/* { dg-error "invalid argument in option '-fsanitize-coverage=trace-cmp,trace-cmp'" "" { target *-*-* } 0 } */
/* { dg-message "'trace-cmp' specified multiple times in the same option" "" { target *-*-* } 0 } */

View File

@ -0,0 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-fsanitize-coverage=trace-pc,tracecmp" } */
/* { dg-error "unrecognized argument in option '-fsanitize-coverage=trace-pc,tracecmp'" "" { target *-*-* } 0 } */
/* { dg-message "valid arguments to '-fsanitize-coverage=' are: trace-cmp trace-pc; did you mean 'trace-cmp'?" "" { target *-*-* } 0 } */