From patchwork Thu Sep 30 19:13:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 66237 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]) by ozlabs.org (Postfix) with SMTP id CA0E2B6EF2 for ; Fri, 1 Oct 2010 05:12:28 +1000 (EST) Received: (qmail 20431 invoked by alias); 30 Sep 2010 19:12:15 -0000 Received: (qmail 20422 invoked by uid 22791); 30 Sep 2010 19:12:14 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Sep 2010 19:12:09 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8UJC804001202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 30 Sep 2010 15:12:08 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8UJC651011437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 30 Sep 2010 15:12:07 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o8UJDj2Q016821; Thu, 30 Sep 2010 21:13:45 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o8UJDjSs016819; Thu, 30 Sep 2010 21:13:45 +0200 Date: Thu, 30 Sep 2010 21:13:45 +0200 From: Jakub Jelinek To: Jan Hubicka , Richard Henderson Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix x86_64 va_arg (PR target/45843) Message-ID: <20100930191345.GM10599@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes 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 Hi! On the attached testcase the first 8 bytes of the struct are NOCLASS, thus construct_container returns a PARALLEL that starts at 8 bytes. The check for last incomplete chunk weren't expecting this. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk and release branches? 2010-09-30 Jakub Jelinek PR target/45843 * config/i386/i386.c (ix86_gimplify_va_arg): Use INTVAL (XEXP (slot, 1)) as prev_size. * g++.dg/torture/pr45843.C: New test. Jakub --- gcc/config/i386/i386.c.jj 2010-09-22 17:15:39.000000000 +0200 +++ gcc/config/i386/i386.c 2010-09-30 14:39:46.000000000 +0200 @@ -7502,6 +7502,8 @@ ix86_gimplify_va_arg (tree valist, tree tree dest_addr, dest; int cur_size = GET_MODE_SIZE (mode); + gcc_assert (prev_size <= INTVAL (XEXP (slot, 1))); + prev_size = INTVAL (XEXP (slot, 1)); if (prev_size + cur_size > size) { cur_size = size - prev_size; @@ -7534,7 +7536,7 @@ ix86_gimplify_va_arg (tree valist, tree dest_addr = fold_convert (daddr_type, addr); dest_addr = fold_build2 (POINTER_PLUS_EXPR, daddr_type, dest_addr, - size_int (INTVAL (XEXP (slot, 1)))); + size_int (prev_size)); if (cur_size == GET_MODE_SIZE (mode)) { src = build_va_arg_indirect_ref (src_addr); --- gcc/testsuite/g++.dg/torture/pr45843.C.jj 2010-09-30 14:45:54.000000000 +0200 +++ gcc/testsuite/g++.dg/torture/pr45843.C 2010-09-30 14:45:33.000000000 +0200 @@ -0,0 +1,28 @@ +// PR target/45843 +// { dg-do run } + +#include + +extern "C" void abort (); +struct S { struct T { } a[14]; char b; }; +struct S arg, s; + +void +foo (int z, ...) +{ + char c; + va_list ap; + va_start (ap, z); + c = 'a'; + arg = va_arg (ap, struct S); + if (c != 'a') + abort (); + va_end (ap); +} + +int +main () +{ + foo (1, s); + return 0; +}