c++: fix -fsanitize-coverage=trace-pc ICE [PR101331]

PR c++/101331

gcc/ChangeLog:

	* asan.h (sanitize_coverage_p): Handle when fn == NULL.

gcc/testsuite/ChangeLog:

	* g++.dg/pr101331.C: New test.
This commit is contained in:
Martin Liska 2021-08-12 17:49:14 +02:00
parent a7f59856ea
commit 90ac6edc3c
2 changed files with 10 additions and 2 deletions

View File

@ -255,8 +255,9 @@ static inline bool
sanitize_coverage_p (const_tree fn = current_function_decl)
{
return (flag_sanitize_coverage
&& lookup_attribute ("no_sanitize_coverage",
DECL_ATTRIBUTES (fn)) == NULL_TREE);
&& (fn == NULL_TREE
|| lookup_attribute ("no_sanitize_coverage",
DECL_ATTRIBUTES (fn)) == NULL_TREE));
}
#endif /* TREE_ASAN */

View File

@ -0,0 +1,7 @@
// PR c++/101331
// { dg-do compile }
// { dg-options "-fsanitize-coverage=trace-pc -O2 -std=c++11" }
int a[2];
int b = 1;
int c { b && (a[b] = 0) };