From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D15C7385840C for ; Wed, 21 Sep 2022 10:43:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D15C7385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 9D5B121AE4 for ; Wed, 21 Sep 2022 10:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663757025; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=7qWAK9dvZht9DTKx3v2FEz84bVgf9gps6zxAX4Q/H80=; b=J6Wbkd0bjBj6p2ENy2yPqibzbyJv2W0Cz6XR6SpVjJiPlENEMfEqEgkNitlFg7PPGVBG7F UZNhZzKDFusd1325d2eMXyVWhB2N1txOCaKWRl8F1w1w6xCRGgs5Q1VnrrNfKvXlcgrPkw 6HeU8IlAYCwrsuQXaPIWT3pLH7GtWVY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663757025; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=7qWAK9dvZht9DTKx3v2FEz84bVgf9gps6zxAX4Q/H80=; b=dszQ5BozhzcpGxCMCMa1Bc+hSslQZI4BOQnF5bAldp791kbRyzSx9oASlKzHEf2MDxuA5A +3TmMVv9ogISNSBw== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 978362C141 for ; Wed, 21 Sep 2022 10:43:45 +0000 (UTC) Date: Wed, 21 Sep 2022 10:43:45 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106984 - tsan and COND_EXPR GIMPLE User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20220921104345.V19hPQ1H0jcgInBe2-rNox6dPzpaB1J19LLngd5vG-E@z> 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