]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/51256 (ICE with invalid parameter for __atomic builtin)
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 25 Nov 2011 03:00:38 +0000 (03:00 +0000)
committerAndrew Macleod <amacleod@gcc.gnu.org>
Fri, 25 Nov 2011 03:00:38 +0000 (03:00 +0000)
2011-11-24  Andrew MacLeod  <amacleod@redhat.com>

PR c/51256
* c-common.c (get_atomic_generic_size): Check for various error
conditions
(resolve_overloaded_atomic_exchange,
resolve_overloaded_atomic_compare_exchange,
resolve_overloaded_atomic_load, resolve_overloaded_atomic_store): Return
error_mark_node for error conditions.
* gcc.dg/atomic-pr51256.c: New.  Test error conditions.

From-SVN: r181709

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

index 9716cc93f37cb343411872a1cf8fe34c843f3d1b..44631060789d66179f5afb4db329049509c6c4df 100644 (file)
@@ -1,3 +1,13 @@
+2011-11-24  Andrew MacLeod  <amacleod@redhat.com>
+
+       PR c/51256
+       * c-common.c (get_atomic_generic_size): Check for various error 
+       conditions
+       (resolve_overloaded_atomic_exchange, 
+       resolve_overloaded_atomic_compare_exchange, 
+       resolve_overloaded_atomic_load, resolve_overloaded_atomic_store): Return
+       error_mark_node for error conditions.
+       
 2011-11-08  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/51010
index a68233113217fa0622e44fd2293649b94327929e..fbbcb3841dd3d92f021bacd29bea3c24579eb33d 100644 (file)
@@ -9392,7 +9392,7 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params)
       n_model = 2;
       break;
     default:
-      return 0;
+      gcc_unreachable ();
     }
 
   if (VEC_length (tree, params) != n_param)
@@ -9403,13 +9403,33 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params)
 
   /* Get type of first parameter, and determine its size.  */
   type_0 = TREE_TYPE (VEC_index (tree, params, 0));
-  if (TREE_CODE (type_0) != POINTER_TYPE)
+  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",
+               function);
+      return 0;
+    }
+
+  /* Types must be compile time constant sizes. */
+  if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))) != INTEGER_CST)
     {
-      error_at (loc, "argument 1 of %qE must be a pointer type", function);
+      error_at (loc, 
+               "argument 1 of %qE must be a pointer to a constant size type",
+               function);
       return 0;
     }
+
   size_0 = tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (type_0)), 1);
 
+  /* Zero size objects are not allowed.  */
+  if (size_0 == 0)
+    {
+      error_at (loc, 
+               "argument 1 of %qE must be a pointer to a nonzero size object",
+               function);
+      return 0;
+    }
+
   /* Check each other parameter is a pointer and the same size.  */
   for (x = 0; x < n_param - n_model; x++)
     {
@@ -9445,7 +9465,6 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params)
              warning_at (loc, OPT_Winvalid_memory_model,
                          "invalid memory model argument %d of %qE", x + 1,
                          function);
-             return MEMMODEL_SEQ_CST;
            }
        }
       else
@@ -9515,6 +9534,13 @@ resolve_overloaded_atomic_exchange (location_t loc, tree function,
   tree I_type, I_type_ptr;
   int n = get_atomic_generic_size (loc, function, params);
 
+  /* Size of 0 is an error condition.  */
+  if (n == 0)
+    {
+      *new_return = error_mark_node;
+      return true;
+    }
+
   /* If not a lock-free size, change to the library generic format.  */
   if (n != 1 && n != 2 && n != 4 && n != 8 && n != 16)
     {
@@ -9538,8 +9564,7 @@ resolve_overloaded_atomic_exchange (location_t loc, tree function,
 
   /* Convert object pointer to required type.  */
   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
-  VEC_replace (tree, params, 0, p0);
-
+  VEC_replace (tree, params, 0, p0); 
   /* Convert new value to required type, and dereference it.  */
   p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR);
   p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1);
@@ -9574,6 +9599,13 @@ resolve_overloaded_atomic_compare_exchange (location_t loc, tree function,
   tree I_type, I_type_ptr;
   int n = get_atomic_generic_size (loc, function, params);
 
+  /* Size of 0 is an error condition.  */
+  if (n == 0)
+    {
+      *new_return = error_mark_node;
+      return true;
+    }
+
   /* If not a lock-free size, change to the library generic format.  */
   if (n != 1 && n != 2 && n != 4 && n != 8 && n != 16)
     {
@@ -9643,6 +9675,13 @@ resolve_overloaded_atomic_load (location_t loc, tree function,
   tree I_type, I_type_ptr;
   int n = get_atomic_generic_size (loc, function, params);
 
+  /* Size of 0 is an error condition.  */
+  if (n == 0)
+    {
+      *new_return = error_mark_node;
+      return true;
+    }
+
   /* If not a lock-free size, change to the library generic format.  */
   if (n != 1 && n != 2 && n != 4 && n != 8 && n != 16)
     {
@@ -9696,6 +9735,13 @@ resolve_overloaded_atomic_store (location_t loc, tree function,
   tree I_type, I_type_ptr;
   int n = get_atomic_generic_size (loc, function, params);
 
+  /* Size of 0 is an error condition.  */
+  if (n == 0)
+    {
+      *new_return = error_mark_node;
+      return true;
+    }
+
   /* If not a lock-free size, change to the library generic format.  */
   if (n != 1 && n != 2 && n != 4 && n != 8 && n != 16)
     {
index 229e6d8a86d5e1aa1fdfad8983af0ffc8e49574b..ff60be03561954cdf9b98fdc599656adc37c9413 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-24  Andrew MacLeod  <amacleod@redhat.com>
+
+       PR c/51256
+       * gcc.dg/atomic-pr51256.c: New.  Test error conditions.
+       
 2011-11-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/51227
diff --git a/gcc/testsuite/gcc.dg/atomic-pr51256.c b/gcc/testsuite/gcc.dg/atomic-pr51256.c
new file mode 100644 (file)
index 0000000..2d39549
--- /dev/null
@@ -0,0 +1,47 @@
+/* Test generic  __atomic routines for various errors.  */
+/* { dg-do compile } */
+/* { dg-require-effective-target sync_int_long } */
+/* { dg-options "-ansi" } */
+
+void f1 (void* p)
+{
+  __atomic_compare_exchange(p, p, p, 0, 0, 0); /* { dg-error "must be a non-void pointer type" } */
+}
+
+void f2 (int n) 
+{ 
+  int a[n], b[n]; 
+  __atomic_load (&a, &b, __ATOMIC_SEQ_CST); /* { dg-error "must be a pointer to a constant size" } */
+}
+
+struct s { };
+void f3 (void)
+{
+  struct s a,b;
+  __atomic_load (&a, &b, __ATOMIC_SEQ_CST);  /* { dg-error "must be a pointer to a nonzero size" } */
+}
+
+void f4 (int a, int b, int c)
+{
+  __atomic_load (&a, &b, &c,  __ATOMIC_SEQ_CST); /* { dg-error "incorrect number of arguments" } */
+}
+
+void f5 (int a, int b)
+{
+  __atomic_load (&a, b, __ATOMIC_SEQ_CST); /* { dg-error "must be a pointer type" } */
+}
+
+void f6 (int a, char b)
+{
+  __atomic_load (&a, &b, __ATOMIC_SEQ_CST); /* { dg-error "size mismatch in argument" } */
+}
+
+void f7 (int a, int b)
+{
+  __atomic_load (&a, &b, 45); /* { dg-warning "invalid memory model argument" } */
+}
+
+void f8 (int a, int b, float c)
+{
+  __atomic_load (&a, &b, c); /* { dg-error "non-integer memory model argument" } */
+}