builtins.c (expand_builtin): Remove 4th parameter representing weak/strong mode when...
authorAndrew MacLeod <amacleod@redhat.com>
Thu, 17 Nov 2011 20:51:51 +0000 (20:51 +0000)
committerAndrew Macleod <amacleod@gcc.gnu.org>
Thu, 17 Nov 2011 20:51:51 +0000 (20:51 +0000)
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

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/atomic-generic-aux.c
gcc/testsuite/gcc.dg/atomic-generic.c
gcc/testsuite/gcc.dg/atomic-noinline-aux.c
gcc/testsuite/gcc.dg/atomic-noinline.c

index 95924c81ce21fd907478c3f9e015220a7ef6efde..34749f504a97c6e482bdc3ca2d6b249847a8d33f 100644 (file)
@@ -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.
index fe0260ff33ef71583290e4e1b0a6acf605d2bae2..0fc5a420c82f03aeb523774f7fb218ff4befc886 100644 (file)
@@ -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:
index fa073e0c022dc302bae1189865dbf967d803a3dd..7d94e14f6c8d67495413f024646b4e76283f16b9 100644 (file)
@@ -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.
index a6b552a5dfdd087dcae5f06a7a1bbd3e3a1fe8e7..2f4cb2a88f7d72f2ffe63c6e3d24d4f292b575f1 100644 (file)
@@ -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;
 }
 
 
index 8a5528c36539b205f622132b08d2b787fe5ec76d..d77e97dbf8aa433efbeaf22e9dcbcdcc6076e692 100644 (file)
@@ -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 ();
index b05460e469b92e36b9c7b940ca281e177bffa41e..deab7ae1de36ff85532c4bc4181ef4996cbc604d 100644 (file)
@@ -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)
index eb0866e549ef87ff72c8df40ede47098bf7ca006..626254d8a9a72092f71d3122447d396a5776a689 100644 (file)
@@ -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 ();