re PR c/71514 (ICE on C11 code with atomic exchange at -O1 and above on x86_64-linux...
authorMarek Polacek <polacek@redhat.com>
Thu, 18 Aug 2016 16:38:49 +0000 (16:38 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 18 Aug 2016 16:38:49 +0000 (16:38 +0000)
PR c/71514
* c-common.c (get_atomic_generic_size): Disallow pointer-to-function
and pointer-to-VLA.

* gcc.dg/pr71514.c: New test.

From-SVN: r239581

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr71514.c [new file with mode: 0644]

index ada2be00ffacbe3f7c6e0f3708585f8c0372c3c4..cc823701fec53b17916913ea088cf8863a630229 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c/71514
+       * c-common.c (get_atomic_generic_size): Disallow pointer-to-function
+       and pointer-to-VLA.
+
 2016-08-16  David Malcolm  <dmalcolm@redhat.com>
 
        PR c/72857
index d41314693ca009fb1e701778f9064ebad13fbfbb..22e3844f43ebfca6178b0b5cada3459ce48623ef 100644 (file)
@@ -11081,6 +11081,20 @@ get_atomic_generic_size (location_t loc, tree function,
                    function);
          return 0;
        }
+      else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
+              && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
+                 != INTEGER_CST)
+       {
+         error_at (loc, "argument %d of %qE must be a pointer to a constant "
+                   "size type", x + 1, function);
+         return 0;
+       }
+      else if (FUNCTION_POINTER_TYPE_P (type))
+       {
+         error_at (loc, "argument %d of %qE must not be a pointer to a "
+                   "function", x + 1, function);
+         return 0;
+       }
       tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
       size = type_size ? tree_to_uhwi (type_size) : 0;
       if (size != size_0)
index c35808f9402f8bfa002fc4d6bcd05f692bd2528c..e37bff498e4d575873f90c8e05ac27fef5836cb7 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c/71514
+       * gcc.dg/pr71514.c: New test.
+
 2015-08-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/72839
diff --git a/gcc/testsuite/gcc.dg/pr71514.c b/gcc/testsuite/gcc.dg/pr71514.c
new file mode 100644 (file)
index 0000000..8bfa805
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR c/71514 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo ()
+{
+}
+
+int a, b;
+
+void
+fn1 (void)
+{
+  __atomic_exchange (&a, &foo, &b, __ATOMIC_RELAXED); /* { dg-error "must not be a pointer to a function" } */
+}
+
+void
+fn2 (int n)
+{
+  int arr[n];
+  __atomic_exchange (&a, &arr, &b, __ATOMIC_RELAXED); /* { dg-error "must be a pointer to a constant size type" } */
+}