From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11556 invoked by alias); 15 Mar 2011 21:02:43 -0000 Received: (qmail 11521 invoked by uid 22791); 15 Mar 2011 21:02:41 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,TW_MG X-Spam-Check-By: sourceware.org Received: from mail-ww0-f41.google.com (HELO mail-ww0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Mar 2011 21:02:35 +0000 Received: by wwi18 with SMTP id 18so3027160wwi.2 for ; Tue, 15 Mar 2011 14:02:33 -0700 (PDT) Received: by 10.227.130.96 with SMTP id r32mr13032761wbs.67.1300222953247; Tue, 15 Mar 2011 14:02:33 -0700 (PDT) Received: from localhost (rsandifo.gotadsl.co.uk [82.133.89.107]) by mx.google.com with ESMTPS id u9sm217748wbg.12.2011.03.15.14.02.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Mar 2011 14:02:32 -0700 (PDT) From: Richard Sandiford To: Nick Clifton Mail-Followup-To: Nick Clifton ,echristo@apple.com, gcc-bugs@gcc.gnu.org, rdsandiford@googlemail.com Cc: echristo@apple.com, gcc-bugs@gcc.gnu.org Subject: Re: MIPS: va_arg is unable to correct extract an empty zero-length array References: Date: Tue, 15 Mar 2011 23:39:00 -0000 In-Reply-To: (Nick Clifton's message of "Tue, 15 Mar 2011 17:53:52 +0000") Message-ID: <87ei6814im.fsf@firetop.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg01618.txt.bz2 Nick Clifton writes: > Hi Eric, Hi Richard, > > A customer has reported the following bug with the MIPS target. Since > it is for a GNU extension to the C language (zero-length arrays) that > is being used in a non-intended fashion (the zero-length array is in a > structure with no other fields) I doubt if you will want to > investigate the problem too much, but I thought that it was worth > reporting anyway: > > % mips64vr-elf-gcc -mgp32 -O2 -Tddb.ld -march=vr5500 bug.c > % mips64vr-elf-run a.out > assertion "arg4 == va4" failed: file "bug.c", line 40, function: foo > > As an aside if the type3 structure in bug.c is given another, > non-zero-length field, then the test passes. Interesting test case :-) Certainly looks like a genuine bug though. I see the same thing happens for varargs that are passed on the stack as well (not just those passed in registers). Fortunately, it looks like the bug is on the varargs side, so no ABI change is needed. Does the attached patch work? I'll try to do a full test this weekend. Richard Index: gcc/config/mips/mips.c =================================================================== --- gcc/config/mips/mips.c (revision 170697) +++ gcc/config/mips/mips.c (working copy) @@ -5625,6 +5625,10 @@ NULL_TREE); size = int_size_in_bytes (type); + /* Even zero-sized arguments occupy one byte. */ + if (size == 0) + size = 1; + if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE) {