tree-optimization/106984 - tsan and COND_EXPR GIMPLE
Checks
Commit Message
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
new file mode 100644
@@ -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);
+}
@@ -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);