Hi!

As the testcase shows, deciding on whether to convert an argument or not
based on TYPE_SIZE is wrong.  While the old __sync_* builtins in the
_[1248]/_16 variants only had a VPTR as first argument and optionally
I[1248]/I16 argument or arguments that should be converted, the new
__atomic_* builtins also have PTR arguments (e.g. the expected pointer),
BOOL (e.g. weak argument) or INT (e.g. the *memmodel arguments).
Those have invariant types that shouldn't be adjusted based on what type the
first pointer points to.  I[1248]/I16 arguments are unsigned integers,
the arguments that we don't want to adjust are BOOLEAN_TYPE/POINTER_TYPE
or signed integers, so I think we should convert only unsigned
INTEGER_TYPEs.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2012-02-13  Jakub Jelinek  <ja...@redhat.com>

        PR c++/52215
        * c-common.c (sync_resolve_params): Don't decide whether to convert
        or not based on TYPE_SIZE comparison, convert whenever arg_type
        is unsigned INTEGER_TYPE.

        * g++.dg/ext/atomic-1.C: New test.

--- gcc/c-family/c-common.c.jj  2012-01-26 09:22:17.000000000 +0100
+++ gcc/c-family/c-common.c     2012-02-13 14:49:15.204685590 +0100
@@ -9336,10 +9336,12 @@ sync_resolve_params (location_t loc, tre
          return false;
        }
 
-      /* Only convert parameters if the size is appropriate with new format
-        sync routines.  */
-      if (orig_format
-         || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (arg_type)))
+      /* Only convert parameters if arg_type is unsigned integer type with
+        new format sync routines, i.e. don't attempt to convert pointer
+        arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
+        bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
+        kinds).  */
+      if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type))
        {
          /* Ideally for the first conversion we'd use convert_for_assignment
             so that we get warnings for anything that doesn't match the pointer
--- gcc/testsuite/g++.dg/ext/atomic-1.C.jj      2012-02-13 14:54:33.337864794 
+0100
+++ gcc/testsuite/g++.dg/ext/atomic-1.C 2012-02-13 14:53:13.000000000 +0100
@@ -0,0 +1,12 @@
+// PR c++/52215
+// { dg-do compile }
+
+enum E { ZERO };
+
+int
+main ()
+{
+  E e = ZERO;
+  __atomic_compare_exchange_n (&e, &e, e, true, __ATOMIC_ACQ_REL,
+                              __ATOMIC_RELAXED);
+}

        Jakub

Reply via email to