From patchwork Fri Mar 28 15:24:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 334727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 91EE6140092 for ; Sat, 29 Mar 2014 02:24:45 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=DAHR3/ebDl6ZjzZaZ sNm0qBHu29EmyCMP9Z0JOUO9pAxsG8gVBaQXM7wu6eakqb2HV7Lv4lU+e/x0TPj1 gpta63zhndljmBj1vQ6e/YgTGgKFhTWoTC+14BRRQd3n37NOs0spgyJ5EdS27TYT 948OJbgqMa9rJbFZ6GClyUshhQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=dQtLWV/2KSskzHhL2nFN3as sR1w=; b=BiFjNP5YPKZ3p4jn8lQBas55FGwYaWBsfs0TW/Q1mcZ3x3lHuKa4d1n KMvB/csNWrWG3uWmyzNUMRO3d/2Ly7goddF5k6B5gbqVpjjo6lMAIekp+9N//O3w N4aLmtv/vgJ735EjY+/dZFjCAZpe0/aCuzoov8ioK+MOYkix77Qc= Received: (qmail 31086 invoked by alias); 28 Mar 2014 15:24:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31071 invoked by uid 89); 28 Mar 2014 15:24:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Mar 2014 15:24:35 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2SFOWlF016205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Mar 2014 11:24:32 -0400 Received: from tucnak.zalov.cz (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2SFOU4m008606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Mar 2014 11:24:31 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.8/8.14.7) with ESMTP id s2SFOTcc023560; Fri, 28 Mar 2014 16:24:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.8/8.14.8/Submit) id s2SFORbl023558; Fri, 28 Mar 2014 16:24:27 +0100 Date: Fri, 28 Mar 2014 16:24:27 +0100 From: Jakub Jelinek To: Jason Merrill , Richard Henderson , Torvald Riegel , "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: Re: [C++ PATCH] Fix __atomic_exchange (PR c++/60689) Message-ID: <20140328152427.GM1817@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20140328104752.GJ1817@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140328104752.GJ1817@tucnak.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On Fri, Mar 28, 2014 at 11:47:52AM +0100, Jakub Jelinek wrote: > Yet another possibility would be to rename all calls in C FE to > build_function_call_vec to say c_build_function_call_vec and add that > function which would call resolve_overloaded_builtin and then tail call to > build_function_call_vec which wouldn't do that. Then c-family/ would keep > its current two calls to that function, which wouldn't recurse anymore, and > we'd need to change add_atomic_size_parameter to push the argument. Here is the variant patch, which implements the above. Also bootstrapped/regtested on x86_64-linux and i686-linux. 2014-03-28 Jakub Jelinek 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. Jakub --- gcc/c/c-tree.h.jj 2014-02-08 00:53:15.000000000 +0100 +++ gcc/c/c-tree.h 2014-03-28 12:30:49.155395381 +0100 @@ -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, tree, + vec *, vec *); /* Set to 0 at beginning of a function definition, set to 1 if a return statement that specifies a return value is seen. */ --- gcc/c/c-typeck.c.jj 2014-03-19 08:14:35.000000000 +0100 +++ gcc/c/c-typeck.c 2014-03-28 12:34:57.803066414 +0100 @@ -2016,7 +2016,7 @@ convert_lvalue_to_rvalue (location_t loc 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, tre 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, /* 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, } 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 arg_loc, + tree function, vec *params, + vec *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); +} /* 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, tre 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, tre 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, tre 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); --- gcc/c/c-parser.c.jj 2014-03-06 13:05:17.000000000 +0100 +++ gcc/c/c-parser.c 2014-03-28 12:33:54.553404774 +0100 @@ -7703,8 +7703,9 @@ c_parser_postfix_expression_after_primar 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 --- gcc/c/c-decl.c.jj 2014-03-07 13:57:21.000000000 +0100 +++ gcc/c/c-decl.c 2014-03-28 12:34:12.246309772 +0100 @@ -4568,8 +4568,8 @@ finish_decl (tree decl, location_t 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. */ --- gcc/testsuite/c-c++-common/pr60689.c.jj 2014-03-28 12:29:05.323950531 +0100 +++ gcc/testsuite/c-c++-common/pr60689.c 2014-03-28 12:29:05.323950531 +0100 @@ -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); +} --- gcc/c-family/c-common.c.jj 2014-03-28 11:01:44.000000000 +0100 +++ gcc/c-family/c-common.c 2014-03-28 12:35:40.111840480 +0100 @@ -10453,6 +10453,7 @@ add_atomic_size_parameter (unsigned n, l 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);