public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-2759] tree-optimization/106984 - tsan and COND_EXPR GIMPLE
Date: Wed, 21 Sep 2022 10:44:12 +0000 (GMT)	[thread overview]
Message-ID: <20220921104412.57E4238582BA@sourceware.org> (raw)

https://gcc.gnu.org/g:41b5edaa5c03db36ad45a9cf524881de221a1812

commit r13-2759-g41b5edaa5c03db36ad45a9cf524881de221a1812
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Sep 21 11:30:57 2022 +0200

    tree-optimization/106984 - tsan and COND_EXPR GIMPLE
    
    The following adjusts a missed spot in TSAN for the RHS COND_EXPR
    GIMPLE IL rework.
    
            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.

Diff:
---
 gcc/testsuite/gcc.dg/tsan/pr106984.c |  7 +++++++
 gcc/tsan.cc                          | 13 +++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

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);

                 reply	other threads:[~2022-09-21 10:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220921104412.57E4238582BA@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).