re PR c++/57926 (Atomic functions broken with C++ but not C?)
authorJason Merrill <jason@redhat.com>
Fri, 11 Apr 2014 18:25:13 +0000 (14:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 11 Apr 2014 18:25:13 +0000 (14:25 -0400)
PR c++/57926
* c-common.c (sync_resolve_size, get_atomic_generic_size): Call
default_conversion for an array argument.

From-SVN: r209316

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/g++.dg/ext/atomic-2.C [new file with mode: 0644]

index 152c3b7def33c690d388deaa18644f1c9f56d8e0..c780dfd834f54b5837a8de52d643d5e7d9a89e77 100644 (file)
@@ -1,3 +1,9 @@
+2014-04-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/57926
+       * c-common.c (sync_resolve_size, get_atomic_generic_size): Call
+       default_conversion for an array argument.
+
 2014-04-08  Marek Polacek  <polacek@redhat.com>
 
        PR sanitizer/60745
index 03731b4b81f5864f1bea1cc55912e31927a17848..1d56bc02ec82aff259100c7ba261c00802700312 100644 (file)
@@ -10202,6 +10202,13 @@ sync_resolve_size (tree function, vec<tree, va_gc> *params)
     }
 
   type = TREE_TYPE ((*params)[0]);
+  if (TREE_CODE (type) == ARRAY_TYPE)
+    {
+      /* Force array-to-pointer decay for C++.  */
+      gcc_assert (c_dialect_cxx());
+      (*params)[0] = default_conversion ((*params)[0]);
+      type = TREE_TYPE ((*params)[0]);
+    }
   if (TREE_CODE (type) != POINTER_TYPE)
     goto incompatible;
 
@@ -10353,6 +10360,13 @@ get_atomic_generic_size (location_t loc, tree function,
 
   /* Get type of first parameter, and determine its size.  */
   type_0 = TREE_TYPE ((*params)[0]);
+  if (TREE_CODE (type_0) == ARRAY_TYPE)
+    {
+      /* Force array-to-pointer decay for C++.  */
+      gcc_assert (c_dialect_cxx());
+      (*params)[0] = default_conversion ((*params)[0]);
+      type_0 = TREE_TYPE ((*params)[0]);
+    }
   if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0)))
     {
       error_at (loc, "argument 1 of %qE must be a non-void pointer type",
diff --git a/gcc/testsuite/g++.dg/ext/atomic-2.C b/gcc/testsuite/g++.dg/ext/atomic-2.C
new file mode 100644 (file)
index 0000000..ac363eb
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/57926
+
+long Mutex[1];
+
+int AcquireLogMutex(void)
+{
+  return __atomic_exchange_n(Mutex, 1, __ATOMIC_SEQ_CST);
+}
+
+void ReleaseLogMutex(void)
+{
+  long i = 0;
+  __atomic_store(Mutex, &i, __ATOMIC_SEQ_CST);
+}