From patchwork Thu Jan 7 21:46:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 564468 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 16D04140323 for ; Fri, 8 Jan 2016 08:46:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vfLsvPYZ; dkim-atps=neutral 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:mime-version :content-type; q=dns; s=default; b=MguQowjZ7yrhAimmRaARjNdFo29Vy 6ThyUehsSv+sOhOcKGU26c9Dv/mwH1/ea0PomD/abx2fJh4qdUSVkNUvEFhEThUY aZbHYhoSAfHWeNT8GDykQxfQ7m9eaQHTeZK3sGANDdv6fwj2nmJ+MBhv7Zlm6wEs Uq7ENTaRLpgf6w= 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:mime-version :content-type; s=default; bh=p/l6lpBzv89N4q8Nf25F7/gmeWk=; b=vfL svPYZAFNHsfsvLLic9dKGtvJCRY643afHEwHBmp/zzF3ZaIdFeUn03+YTbqGJReu 88lG7mnEtuA0uBXTieiql8obVKxXbOAqjhiXAZAwKKiHvjzedH2WA4tDkblxmJPE WIJ/p2vQvCZhT7fcwU0El+98WiiGgXyLXXt7KDiE= Received: (qmail 119055 invoked by alias); 7 Jan 2016 21:46:34 -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 119030 invoked by uid 89); 7 Jan 2016 21:46:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Weve, 1018, 7, sk:tree-st, sk:treest 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 07 Jan 2016 21:46:32 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id CA417C0AD1FB; Thu, 7 Jan 2016 21:46:30 +0000 (UTC) Received: from tucnak.zalov.cz ([10.3.113.3]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u07LkT9u028973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 7 Jan 2016 16:46:30 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u07LkQ3B025662; Thu, 7 Jan 2016 22:46:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u07LkPCr025661; Thu, 7 Jan 2016 22:46:25 +0100 Date: Thu, 7 Jan 2016 22:46:25 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE with va_arg (PR tree-optimization/69162) Message-ID: <20160107214625.GQ18720@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! The addition of IFN_VA_ARG which is only during stdarg pass lowered introduced ICE on the following testcase. The problem is that we expected that the type the first argument of the internal call points to will remain the one that used to be there during gimplification, but as pointer conversions are useless, that is not guaranteed, it can become void * or any other pointer type. Fixed by remembering the type on another argument. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-01-07 Jakub Jelinek PR tree-optimization/69162 * gimplify.c (gimplify_va_arg_expr): Encode original type of valist argument in another argument. (gimplify_modify_expr): Adjust for the above change. Cleanup. * tree-stdarg.c (expand_ifn_va_arg_1): Use new 3rd argument to determine the va_list type, build a MEM_REF instead of build_fold_indirect_ref. * gcc.dg/pr69162.c: New test. Jakub --- gcc/gimplify.c.jj 2016-01-04 14:55:53.000000000 +0100 +++ gcc/gimplify.c 2016-01-07 15:19:17.283215609 +0100 @@ -4724,12 +4724,12 @@ gimplify_modify_expr (tree *expr_p, gimp tree type = TREE_TYPE (call); tree ap = CALL_EXPR_ARG (call, 0); tree tag = CALL_EXPR_ARG (call, 1); + tree aptag = CALL_EXPR_ARG (call, 2); tree newcall = build_call_expr_internal_loc (EXPR_LOCATION (call), IFN_VA_ARG, type, nargs + 1, ap, tag, - vlasize); - tree *call_p = &(TREE_OPERAND (*from_p, 0)); - *call_p = newcall; + aptag, vlasize); + TREE_OPERAND (*from_p, 0) = newcall; } } @@ -11501,7 +11501,7 @@ gimplify_va_arg_expr (tree *expr_p, gimp tree promoted_type, have_va_type; tree valist = TREE_OPERAND (*expr_p, 0); tree type = TREE_TYPE (*expr_p); - tree t, tag; + tree t, tag, aptag; location_t loc = EXPR_LOCATION (*expr_p); /* Verify that valist is of the proper type. */ @@ -11555,7 +11555,10 @@ gimplify_va_arg_expr (tree *expr_p, gimp } tag = build_int_cst (build_pointer_type (type), 0); - *expr_p = build_call_expr_internal_loc (loc, IFN_VA_ARG, type, 2, valist, tag); + aptag = build_int_cst (TREE_TYPE (valist), 0); + + *expr_p = build_call_expr_internal_loc (loc, IFN_VA_ARG, type, 3, + valist, tag, aptag); /* Clear the tentatively set PROP_gimple_lva, to indicate that IFN_VA_ARG needs to be expanded. */ --- gcc/tree-stdarg.c.jj 2016-01-04 14:55:52.000000000 +0100 +++ gcc/tree-stdarg.c 2016-01-07 15:20:14.340424740 +0100 @@ -1018,7 +1018,7 @@ expand_ifn_va_arg_1 (function *fun) for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i)) { gimple *stmt = gsi_stmt (i); - tree ap, expr, lhs, type; + tree ap, aptype, expr, lhs, type; gimple_seq pre = NULL, post = NULL; if (!gimple_call_ifn_va_arg_p (stmt)) @@ -1028,9 +1028,12 @@ expand_ifn_va_arg_1 (function *fun) type = TREE_TYPE (TREE_TYPE (gimple_call_arg (stmt, 1))); ap = gimple_call_arg (stmt, 0); + aptype = TREE_TYPE (gimple_call_arg (stmt, 2)); + gcc_assert (POINTER_TYPE_P (aptype)); /* Balanced out the &ap, usually added by build_va_arg. */ - ap = build_fold_indirect_ref (ap); + ap = build2 (MEM_REF, TREE_TYPE (aptype), ap, + build_int_cst (aptype, 0)); push_gimplify_context (false); saved_location = input_location; @@ -1053,7 +1056,7 @@ expand_ifn_va_arg_1 (function *fun) if (chkp_function_instrumented_p (fun->decl)) chkp_fixup_inlined_call (lhs, expr); - if (nargs == 3) + if (nargs == 4) { /* We've transported the size of with WITH_SIZE_EXPR here as the last argument of the internal fn call. Now reinstate --- gcc/testsuite/gcc.dg/pr69162.c.jj 2016-01-07 15:27:10.215660347 +0100 +++ gcc/testsuite/gcc.dg/pr69162.c 2016-01-07 15:27:47.127148736 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/69162 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include + +int +foo (void *a) +{ + va_list *b = a; + return va_arg (*b, int); +}