aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-12-07 15:55:59 +0100
committerMartin Liska <mliska@suse.cz>2020-12-16 10:25:32 +0100
commit8833eab4461b4b7050f06a231c3311cc1fa87523 (patch)
tree311bae63eda19649eb32f3383b3408d1e7891598 /gcc
parent5c5eb7e4872025e8d5e8ae2f0e568403f7c8803d (diff)
downloadgcc-8833eab4461b4b7050f06a231c3311cc1fa87523.zip
gcc-8833eab4461b4b7050f06a231c3311cc1fa87523.tar.gz
gcc-8833eab4461b4b7050f06a231c3311cc1fa87523.tar.bz2
Add -Wtsan.
gcc/ChangeLog: PR sanitizer/97868 * common.opt: Add new warning -Wtsan. * doc/invoke.texi: Likewise. * tsan.c (instrument_builtin_call): Warn users about unsupported std::atomic_thread_fence. gcc/testsuite/ChangeLog: PR sanitizer/97868 * gcc.dg/tsan/atomic-fence.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/common.opt4
-rw-r--r--gcc/doc/invoke.texi12
-rw-r--r--gcc/testsuite/gcc.dg/tsan/atomic-fence.c11
-rw-r--r--gcc/tsan.c6
4 files changed, 32 insertions, 1 deletions
diff --git a/gcc/common.opt b/gcc/common.opt
index 6645539..4ab5fe4 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -842,6 +842,10 @@ Wvector-operation-performance
Common Var(warn_vector_operation_performance) Warning
Warn when a vector operation is compiled outside the SIMD.
+Wtsan
+Common Var(warn_tsan) Init(1) Warning
+Warn about unsupported features in ThreadSanitizer.
+
Xassembler
Driver Separate
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 2cebe7a..054b837 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -387,7 +387,7 @@ Objective-C and Objective-C++ Dialects}.
-Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum @gol
-Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol
-Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs @gol
--Wtype-limits -Wundef @gol
+-Wtsan -Wtype-limits -Wundef @gol
-Wuninitialized -Wunknown-pragmas @gol
-Wunsuffixed-float-constants -Wunused @gol
-Wunused-but-set-parameter -Wunused-but-set-variable @gol
@@ -8023,6 +8023,16 @@ Note that the code above is invalid in C++11.
This warning is enabled by default.
+@item -Wtsan
+@opindex Wtsan
+@opindex Wno-tsan
+Warn about unsupported features in ThreadSanitizer.
+
+ThreadSanitizer does not support @code{std::atomic_thread_fence} and
+can report false positives.
+
+This warning is enabled by default.
+
@item -Wtype-limits
@opindex Wtype-limits
@opindex Wno-type-limits
diff --git a/gcc/testsuite/gcc.dg/tsan/atomic-fence.c b/gcc/testsuite/gcc.dg/tsan/atomic-fence.c
new file mode 100644
index 0000000..013720c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tsan/atomic-fence.c
@@ -0,0 +1,11 @@
+/* PR sanitizer/97868 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=thread" } */
+
+int
+main ()
+{
+ __atomic_thread_fence (__ATOMIC_RELAXED); /* { dg-warning ".atomic_thread_fence. is not supported with .-fsanitize=thread." } */
+ return 0;
+}
+
diff --git a/gcc/tsan.c b/gcc/tsan.c
index 4d62234..1bc020e 100644
--- a/gcc/tsan.c
+++ b/gcc/tsan.c
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see
#include "asan.h"
#include "builtins.h"
#include "target.h"
+#include "diagnostic-core.h"
/* Number of instrumented memory accesses in the current function. */
@@ -500,6 +501,11 @@ instrument_builtin_call (gimple_stmt_iterator *gsi)
continue;
else
{
+ if (fcode == BUILT_IN_ATOMIC_THREAD_FENCE)
+ warning_at (gimple_location (stmt), OPT_Wtsan,
+ "%qs is not supported with %qs", "atomic_thread_fence",
+ "-fsanitize=thread");
+
tree decl = builtin_decl_implicit (tsan_atomic_table[i].tsan_fcode);
if (decl == NULL_TREE)
return;