aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2011-11-17 20:51:51 +0000
committerAndrew Macleod <amacleod@gcc.gnu.org>2011-11-17 20:51:51 +0000
commite351ae8587983e9122bb6197f6eaf6f1b9031536 (patch)
tree0452b724a356b47d7c1793b5851f2045d411f1f9
parent29e339fd2e924cb0936242206e8176ba747f869f (diff)
downloadgcc-e351ae8587983e9122bb6197f6eaf6f1b9031536.zip
gcc-e351ae8587983e9122bb6197f6eaf6f1b9031536.tar.gz
gcc-e351ae8587983e9122bb6197f6eaf6f1b9031536.tar.bz2
builtins.c (expand_builtin): Remove 4th parameter representing weak/strong mode when...
2011-11-17 Andrew MacLeod <amacleod@redhat.com> * builtins.c (expand_builtin): Remove 4th parameter representing weak/strong mode when __atomic_compare_exchange becomes a library call. * gcc.dg/atomic-generic-aux.c (__atomic_compare_exchange): Fail if memory model parameters don't match expected values. * gcc.dg/atomic-generic.c: Pass specific memory model parameters to __atomic_compare_exchange. * gcc.dg/atomic-noinline.c: Pass specific memory model parameters to __atomic_compare_exchange_n. * gcc.dg/atomic-noinline-aux.c (__atomic_compare_exchange_2): Remove weak/strong parameter and fail if memory models aren't correct. From-SVN: r181453
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/builtins.c28
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/gcc.dg/atomic-generic-aux.c21
-rw-r--r--gcc/testsuite/gcc.dg/atomic-generic.c4
-rw-r--r--gcc/testsuite/gcc.dg/atomic-noinline-aux.c10
-rw-r--r--gcc/testsuite/gcc.dg/atomic-noinline.c2
7 files changed, 66 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 95924c8..34749f5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2011-11-17 Andrew MacLeod <amacleod@redhat.com>
+
+ * builtins.c (expand_builtin): Remove 4th parameter representing
+ weak/strong mode when __atomic_compare_exchange becomes a library call.
+
2011-11-17 Richard Henderson <rth@redhat.com>
* builtins.c (expand_builtin_mem_thread_fence): Remove.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index fe0260f..0fc5a42 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -6497,12 +6497,28 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8:
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16:
- mode =
- get_builtin_sync_mode (fcode - BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1);
- target = expand_builtin_atomic_compare_exchange (mode, exp, target);
- if (target)
- return target;
- break;
+ {
+ unsigned int nargs, z;
+ VEC(tree,gc) *vec;
+
+ mode =
+ get_builtin_sync_mode (fcode - BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1);
+ target = expand_builtin_atomic_compare_exchange (mode, exp, target);
+ if (target)
+ return target;
+
+ /* If this is turned into an external library call, the weak parameter
+ must be dropped to match the expected parameter list. */
+ nargs = call_expr_nargs (exp);
+ vec = VEC_alloc (tree, gc, nargs - 1);
+ for (z = 0; z < 3; z++)
+ VEC_quick_push (tree, vec, CALL_EXPR_ARG (exp, z));
+ /* Skip the boolean weak parameter. */
+ for (z = 4; z < 6; z++)
+ VEC_quick_push (tree, vec, CALL_EXPR_ARG (exp, z));
+ exp = build_call_vec (TREE_TYPE (exp), CALL_EXPR_FN (exp), vec);
+ break;
+ }
case BUILT_IN_ATOMIC_LOAD_1:
case BUILT_IN_ATOMIC_LOAD_2:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fa073e0..7d94e14 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-17 Andrew MacLeod <amacleod@redhat.com>
+
+ * gcc.dg/atomic-generic-aux.c (__atomic_compare_exchange): Fail if
+ memory model parameters don't match expected values.
+ * gcc.dg/atomic-generic.c: Pass specific memory model parameters to
+ __atomic_compare_exchange.
+ * gcc.dg/atomic-noinline.c: Pass specific memory model parameters to
+ __atomic_compare_exchange_n.
+ * gcc.dg/atomic-noinline-aux.c (__atomic_compare_exchange_2): Remove
+ weak/strong parameter and fail if memory models aren't correct.
+
2011-10-17 Uros Bizjak <ubizjak@gmail.com>
* lib/gcc-simulate-thread.exp (simulate-thread): Run on all targets.
diff --git a/gcc/testsuite/gcc.dg/atomic-generic-aux.c b/gcc/testsuite/gcc.dg/atomic-generic-aux.c
index a6b552a..2f4cb2a 100644
--- a/gcc/testsuite/gcc.dg/atomic-generic-aux.c
+++ b/gcc/testsuite/gcc.dg/atomic-generic-aux.c
@@ -19,17 +19,30 @@ __atomic_exchange (size_t size, void *obj, void *val, void *ret, int model)
}
+/* Note that the external version of this routine has the boolean weak/strong
+ parameter removed. This is required by teh external library. */
bool
-__atomic_compare_exchange (size_t size, void *obj, void *expected,
+__atomic_compare_exchange (size_t size, void *obj, void *expected,
void *desired, int model1, int model2)
{
+ bool ret;
if (!memcmp (obj, expected, size))
{
memcpy (obj, desired, size);
- return true;
+ ret = true;
}
- memcpy (expected, obj, size);
- return false;
+ else
+ {
+ memcpy (expected, obj, size);
+ ret = false;
+ }
+
+ /* Make sure the parameters have been properly adjusted for the external
+ function call (no weak/strong parameter. */
+ if (model1 != __ATOMIC_SEQ_CST || model2 != __ATOMIC_ACQUIRE)
+ ret = !ret;
+
+ return ret;
}
diff --git a/gcc/testsuite/gcc.dg/atomic-generic.c b/gcc/testsuite/gcc.dg/atomic-generic.c
index 8a5528c..d77e97d 100644
--- a/gcc/testsuite/gcc.dg/atomic-generic.c
+++ b/gcc/testsuite/gcc.dg/atomic-generic.c
@@ -41,12 +41,12 @@ main ()
if (memcmp (&b, &ones, size))
abort ();
- if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
+ if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
abort();
if (memcmp (&a, &zero, size))
abort ();
- if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
+ if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
abort();
if (memcmp (&b, &zero, size))
abort ();
diff --git a/gcc/testsuite/gcc.dg/atomic-noinline-aux.c b/gcc/testsuite/gcc.dg/atomic-noinline-aux.c
index b05460e..deab7ae 100644
--- a/gcc/testsuite/gcc.dg/atomic-noinline-aux.c
+++ b/gcc/testsuite/gcc.dg/atomic-noinline-aux.c
@@ -30,9 +30,15 @@ __atomic_store_1 (char *p, char v, int i)
*p = 1;
}
-int __atomic_compare_exchange_2 (short *p, short *a, short b, int x, int y, int z)
+int __atomic_compare_exchange_2 (short *p, short *a, short b, int y, int z)
{
- *p = 1;
+ /* Fail if the memory models aren't correct as that will indicate the external
+ call has failed to remove the weak/strong parameter as required by the
+ library. */
+ if (y != __ATOMIC_SEQ_CST || z != __ATOMIC_ACQUIRE)
+ *p = 0;
+ else
+ *p = 1;
}
char __atomic_fetch_add_1 (char *p, char v, int i)
diff --git a/gcc/testsuite/gcc.dg/atomic-noinline.c b/gcc/testsuite/gcc.dg/atomic-noinline.c
index eb0866e..626254d 100644
--- a/gcc/testsuite/gcc.dg/atomic-noinline.c
+++ b/gcc/testsuite/gcc.dg/atomic-noinline.c
@@ -31,7 +31,7 @@ main ()
if (ac != 1)
abort ();
- __atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ __atomic_compare_exchange_n (&as, &bs, cs, 0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
if (as != 1)
abort ();