Return content of flag_sanitize_coverage when fn is null.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
PR c++/101331
gcc/ChangeLog:
* asan.h (sanitize_coverage_p): Handle when fn == NULL.
gcc/testsuite/ChangeLog:
* g++.dg/pr101331.C: New test.
---
gcc/asan.h | 5 +++--
gcc/testsuite/g++.dg/pr101331.C | 7 +++++++
2 files changed, 10 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/pr101331.C
diff --git a/gcc/asan.h b/gcc/asan.h
index 8c0b2baf170..820c18bbd0a 100644
--- a/gcc/asan.h
+++ b/gcc/asan.h
@@ -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 */
diff --git a/gcc/testsuite/g++.dg/pr101331.C b/gcc/testsuite/g++.dg/pr101331.C
new file mode 100644
index 00000000000..015aba200d3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr101331.C
@@ -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) };
--
2.32.0