]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/60689 (Bogus error with atomic::exchange)
authorJakub Jelinek <jakub@redhat.com>
Fri, 28 Mar 2014 18:16:32 +0000 (19:16 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 28 Mar 2014 18:16:32 +0000 (19:16 +0100)
PR c++/60689
* c-tree.h (c_build_function_call_vec): New prototype.
* c-typeck.c (build_function_call_vec): Don't call
resolve_overloaded_builtin here.
(c_build_function_call_vec): New wrapper function around
build_function_call_vec.  Call resolve_overloaded_builtin here.
(convert_lvalue_to_rvalue, build_function_call, build_atomic_assign):
Call c_build_function_call_vec instead of build_function_call_vec.
* c-parser.c (c_parser_postfix_expression_after_primary): Likewise.
* c-decl.c (finish_decl): Likewise.

* c-common.c (add_atomic_size_parameter): When creating new
params vector, push the size argument first.

* c-c++-common/pr60689.c: New test.

From-SVN: r208912

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/c/c-tree.h
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr60689.c [new file with mode: 0644]

index 8d67d1288b371317c1d52cd8fb4c45c78be2525f..250f4cf5b47c5701c19d8da57eba3da0c46c701c 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/60689
+       * c-common.c (add_atomic_size_parameter): When creating new
+       params vector, push the size argument first.
+
 2014-03-26  Jakub Jelinek  <jakub@redhat.com>
 
        * c-ubsan.c (ubsan_instrument_division, ubsan_instrument_shift,
index abd96fbe9aea30d5acfe9429e91757a471da5700..03731b4b81f5864f1bea1cc55912e31927a17848 100644 (file)
@@ -10453,6 +10453,7 @@ add_atomic_size_parameter (unsigned n, location_t loc, tree function,
 
       len = params->length ();
       vec_alloc (v, len + 1);
+      v->quick_push (build_int_cst (size_type_node, n));
       for (z = 0; z < len; z++)
        v->quick_push ((*params)[z]);
       f = build_function_call_vec (loc, vNULL, function, v, NULL);
index b39b7d654bd2535b6ecdec804969f0ba6e503aa5..6b819e9964d24eab1725bb4629db4fff18e4f8c3 100644 (file)
@@ -1,3 +1,16 @@
+2014-03-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/60689
+       * c-tree.h (c_build_function_call_vec): New prototype.
+       * c-typeck.c (build_function_call_vec): Don't call
+       resolve_overloaded_builtin here.
+       (c_build_function_call_vec): New wrapper function around
+       build_function_call_vec.  Call resolve_overloaded_builtin here.
+       (convert_lvalue_to_rvalue, build_function_call, build_atomic_assign):
+       Call c_build_function_call_vec instead of build_function_call_vec.
+       * c-parser.c (c_parser_postfix_expression_after_primary): Likewise.
+       * c-decl.c (finish_decl): Likewise.
+
 2014-03-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/55383
index 2c41bf2ce92c8574f61bd41be913778bdeec4167..df84980e30900c50a5faf73bd2b25894025ace90 100644 (file)
@@ -4568,8 +4568,8 @@ finish_decl (tree decl, location_t init_loc, tree init,
          cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0);
          vec_alloc (v, 1);
          v->quick_push (cleanup);
-         cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl),
-                                            vNULL, cleanup_decl, v, NULL);
+         cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
+                                              vNULL, cleanup_decl, v, NULL);
          vec_free (v);
 
          /* Don't warn about decl unused; the cleanup uses it.  */
index d0d35c5776166eb68025baf19fa4668dbf08bef1..5653e49f4824f59c6d9f51608fb2ffa63090a254 100644 (file)
@@ -7703,8 +7703,9 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
                                              expr.value, exprlist,
                                              sizeof_arg,
                                              sizeof_ptr_memacc_comptypes);
-         expr.value = build_function_call_vec (expr_loc, arg_loc, expr.value,
-                                               exprlist, origtypes);
+         expr.value
+           = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
+                                        exprlist, origtypes);
          expr.original_code = ERROR_MARK;
          if (TREE_CODE (expr.value) == INTEGER_CST
              && TREE_CODE (orig_expr.value) == FUNCTION_DECL
index 84d5e0b08aae79c7de374b7a8fe9aaf3d2067977..85df8858dea398a05d64c33501ea306c4fff6746 100644 (file)
@@ -643,6 +643,8 @@ extern tree c_finish_omp_clauses (tree);
 extern tree c_build_va_arg (location_t, tree, tree);
 extern tree c_finish_transaction (location_t, tree, int);
 extern bool c_tree_equal (tree, tree);
+extern tree c_build_function_call_vec (location_t, vec<location_t>, tree,
+                                      vec<tree, va_gc> *, vec<tree, va_gc> *);
 
 /* Set to 0 at beginning of a function definition, set to 1 if
    a return statement that specifies a return value is seen.  */
index 0bfc12beabe29f553f5e32096c0de2c2a2432f3a..65aad45651c9b29ecac7b217244b3f123c6d4558 100644 (file)
@@ -2016,7 +2016,7 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
       params->quick_push (expr_addr);
       params->quick_push (tmp_addr);
       params->quick_push (seq_cst);
-      func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+      func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
 
       /* EXPR is always read.  */
       mark_exp_read (exp.value);
@@ -2801,7 +2801,7 @@ build_function_call (location_t loc, tree function, tree params)
   vec_alloc (v, list_length (params));
   for (; params; params = TREE_CHAIN (params))
     v->quick_push (TREE_VALUE (params));
-  ret = build_function_call_vec (loc, vNULL, function, v, NULL);
+  ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
   vec_free (v);
   return ret;
 }
@@ -2840,14 +2840,6 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
   /* Convert anything with function type to a pointer-to-function.  */
   if (TREE_CODE (function) == FUNCTION_DECL)
     {
-      /* Implement type-directed function overloading for builtins.
-        resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
-        handle all the type checking.  The result is a complete expression
-        that implements this function call.  */
-      tem = resolve_overloaded_builtin (loc, function, params);
-      if (tem)
-       return tem;
-
       name = DECL_NAME (function);
 
       if (flag_tm)
@@ -2970,6 +2962,30 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
     }
   return require_complete_type (result);
 }
+
+/* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
+
+tree
+c_build_function_call_vec (location_t loc, vec<location_t> arg_loc,
+                          tree function, vec<tree, va_gc> *params,
+                          vec<tree, va_gc> *origtypes)
+{
+  /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
+  STRIP_TYPE_NOPS (function);
+
+  /* Convert anything with function type to a pointer-to-function.  */
+  if (TREE_CODE (function) == FUNCTION_DECL)
+    {
+      /* Implement type-directed function overloading for builtins.
+        resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
+        handle all the type checking.  The result is a complete expression
+        that implements this function call.  */
+      tree tem = resolve_overloaded_builtin (loc, function, params);
+      if (tem)
+       return tem;
+    }
+  return build_function_call_vec (loc, arg_loc, function, params, origtypes);
+}
 \f
 /* Convert the argument expressions in the vector VALUES
    to the types in the list TYPELIST.
@@ -3634,7 +3650,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
       params->quick_push (lhs_addr);
       params->quick_push (rhs);
       params->quick_push (seq_cst);
-      func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+      func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
       add_stmt (func_call);
 
       /* Finish the compound statement.  */
@@ -3666,7 +3682,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
   params->quick_push (lhs_addr);
   params->quick_push (old_addr);
   params->quick_push (seq_cst);
-  func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   add_stmt (func_call);
   params->truncate (0);
 
@@ -3705,7 +3721,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
   params->quick_push (integer_zero_node);
   params->quick_push (seq_cst);
   params->quick_push (seq_cst);
-  func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
 
   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
   SET_EXPR_LOCATION (goto_stmt, loc);
index 30756a1006d1ad55bf476b28ce1d24e7860931ce..5b27941db2557323af53b6ade86899578e44b2a9 100644 (file)
@@ -1,5 +1,8 @@
 2014-03-28  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/60689
+       * c-c++-common/pr60689.c: New test.
+
        PR c++/58678
        * g++.dg/abi/thunk6.C: Scan assembler for _ZTv0_n32_N1CD1Ev
        only for lp64 targets and scan for _ZTv0_n16_N1CD1Ev for ilp32
diff --git a/gcc/testsuite/c-c++-common/pr60689.c b/gcc/testsuite/c-c++-common/pr60689.c
new file mode 100644 (file)
index 0000000..9475bd8
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR c++/60689 */
+/* { dg-do compile } */
+
+struct S { char x[9]; };
+
+void
+foo (struct S *x, struct S *y, struct S *z)
+{
+  __atomic_exchange (x, y, z, __ATOMIC_SEQ_CST);
+}