public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/106984 - tsan and COND_EXPR GIMPLE
@ 2022-09-21 10:43 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-09-21 10:43 UTC (permalink / raw)
  To: gcc-patches

The following adjusts a missed spot in TSAN for the RHS COND_EXPR
GIMPLE IL rework.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/106984
	* tsan.cc (instrument_builtin_call): Build the COND_EXPR condition in
	a separate statement.

	* gcc.dg/tsan/pr106984.c: New testcase.
---
 gcc/testsuite/gcc.dg/tsan/pr106984.c |  7 +++++++
 gcc/tsan.cc                          | 13 +++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tsan/pr106984.c

diff --git a/gcc/testsuite/gcc.dg/tsan/pr106984.c b/gcc/testsuite/gcc.dg/tsan/pr106984.c
new file mode 100644
index 00000000000..69cf83d547a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tsan/pr106984.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=thread" } */
+
+int svcsw (int *ptr, int oldval, int newval)
+{
+  return __sync_val_compare_and_swap (ptr, oldval, newval);
+}
diff --git a/gcc/tsan.cc b/gcc/tsan.cc
index 79d4582acd1..2406527c96a 100644
--- a/gcc/tsan.cc
+++ b/gcc/tsan.cc
@@ -620,15 +620,16 @@ instrument_builtin_call (gimple_stmt_iterator *gsi)
 	    maybe_clean_or_replace_eh_stmt (stmt, gsi_stmt (*gsi));
 	    if (tsan_atomic_table[i].action == val_cas && lhs)
 	      {
-		tree cond;
 		stmt = gsi_stmt (*gsi);
-		g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
+		tree t2 = make_ssa_name (TREE_TYPE (t));
+		g = gimple_build_assign (t2, t);
 		gsi_insert_after (gsi, g, GSI_NEW_STMT);
 		t = make_ssa_name (TREE_TYPE (TREE_TYPE (decl)), stmt);
-		cond = build2 (NE_EXPR, boolean_type_node, t,
-			       build_int_cst (TREE_TYPE (t), 0));
-		g = gimple_build_assign (lhs, COND_EXPR, cond, args[1],
-					 gimple_assign_lhs (g));
+		tree cond = make_ssa_name (boolean_type_node);
+		g = gimple_build_assign (cond, NE_EXPR,
+					 t, build_zero_cst (TREE_TYPE (t)));
+		gsi_insert_after (gsi, g, GSI_NEW_STMT);
+		g = gimple_build_assign (lhs, COND_EXPR, cond, args[1], t2);
 		gimple_call_set_lhs (stmt, t);
 		update_stmt (stmt);
 		gsi_insert_after (gsi, g, GSI_NEW_STMT);
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-21 10:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 10:43 [PATCH] tree-optimization/106984 - tsan and COND_EXPR GIMPLE Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).