Bug 6431 - [v850] va_arg() fails in expanding arguments
Summary: [v850] va_arg() fails in expanding arguments
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 2.96
: P3 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-04-23 11:16 UTC by markku.pihlajamaa
Modified: 2003-08-12 13:35 UTC (History)
2 users (show)

See Also:
Host:
Target: v850-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-06-27 03:25:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description markku.pihlajamaa 2002-04-23 11:16:01 UTC
The first optional argument is not expanded by
va_arg() at all, but is skipped, and the last
optional argument is expanded to a random number.

Release:
2.96-xscale-010827

Environment:
GNU C cross compiler, configured for the v850-elf target, the compiler is run on a PC and the operating system is
Red Hat Linux 7.1.

How-To-Repeat:
#include <stdarg.h>

extern int out ( int );

void test( int parc, ... )
{
    va_list list;

    va_start( list, parc );

    while( parc )
    {
        int i;

        i = va_arg( list, int );

        out( i );

        parc --;
    }

    va_end( list );
}


int main( void )
{
    test( 4, 1, 2, 3, 4 );

    return 0;
}
Comment 1 markku.pihlajamaa 2002-04-23 11:16:01 UTC
Fix:
*** gcc/config/v850/v850.c.original	Sat Jan  8 10:15:57 2000
--- gcc/config/v850/v850.c	Tue Apr 23 13:55:30 2002
***************
*** 3653,3659 ****
    incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
    TREE_SIDE_EFFECTS (incr) = 1;
-   expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
  
    addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
  
    if (indirect)
--- 3653,3660 ----
    incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
    TREE_SIDE_EFFECTS (incr) = 1;
  
    addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
+ 
+   expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
  
    if (indirect)
Comment 2 Dara Hazeghi 2003-05-16 18:52:21 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: markku.pihlajamaa@luukku.com, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: target/6431: [v850] va_arg() fails in expanding arguments
Date: Fri, 16 May 2003 18:52:21 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=6431
 
 Hello,
 
 gcc-2.96 is both very old and not an official gcc release by the GNU  
 project. Would it be possible for you to test your code on a recent  
 official gcc release (e.g. 3.3) and determine whether this bug is still  
 present? Thank you,
 
 Dara
 
Comment 3 Giovanni Bajo 2003-05-17 06:58:21 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: See Dara's question.
Comment 4 Dara Hazeghi 2003-06-02 02:26:06 UTC
Nick,

would you mind having a brief look at  this bug report? It seems to be a pretty old one which may 
no longer even be present, but it also includes a patch... Thanks,

Dara
Comment 5 Nick Clifton 2003-06-03 13:03:33 UTC
Subject: Re:  [v850] va_arg() fails in expanding arguments

Hi Dara,

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6431

> Nick,
>
> would you mind having a brief look at  this bug report? It seems to
> be a pretty old one which may no longer even be present, but it also
> includes a patch... Thanks,

Unfortunately the v850 port does not even build at the moment, so I
cannot test the patch.  Once I have fixed the build problems I will
have a look at it though, OK ?

Cheers
        Nick

Comment 6 Dara Hazeghi 2003-06-03 17:22:01 UTC
Thanks, sounds good... I'll leave it in WAITING in case the submitter can confirm it's fixed on 
previous versions.

Dara
Comment 7 markku.pihlajamaa 2003-06-04 10:04:48 UTC
Thank you. I have just been able to try with 3.1.1., 
and as far as I understand it seems to be O.K.
Regards, 
Markku

***************************************************

#include <stdarg.h>

extern int out ( int );

void test( int parc, ... )
{
    va_list list;
    
    va_start( list, parc );
    
    while( parc )
    {
        int i;
        
        i = va_arg( list, int );

        out( i );
        
        parc --;
    }

    va_end( list );
}


int main( void )
{
    test( 4, 1, 2, 3, 4 );
    
    return 0;
}


************************************************************


	.file	"va_arg.c"
gcc2_compiled.:
	.section .text
	.align 1
	.global _test
	.type	 _test,@function
_test:
	st.w r6,0[sp]
	st.w r7,4[sp]
	st.w r8,8[sp]
	st.w r9,12[sp]
	addi -36,sp,sp
	st.w r31,32[sp]
	st.w r28,28[sp]
	st.w r29,24[sp]
	mov sp,r29
	st.w r6,36[r29]
	addi 40,r29,r10
	st.w r10,20[r29]
.L3:
	ld.w 36[r29],r10
	cmp r0,r10
	bne .L5
	br .L4
.L5:
	ld.w 20[r29],r28
	ld.w 20[r29],r10
	addi 4,r10,r11
	st.w r11,20[r29]
	ld.w 0[r28],r10
	st.w r10,16[r29]
	ld.w 16[r29],r6
	jarl _out,r31
	ld.w 36[r29],r10
	addi -1,r10,r11
	st.w r11,36[r29]
	br .L3
.L4:
.L2:
	mov r29,sp
	ld.w 32[sp],r31
	ld.w 28[sp],r28
	ld.w 24[sp],r29
	addi 36,sp,sp
	jmp [r31]
.Lfe1:
	.size	 _test,.Lfe1-_test
	.align 1
	.global _main
	.type	 _main,@function
_main:
	addi -28,sp,sp
	st.w r31,24[sp]
	st.w r29,20[sp]
	mov sp,r29
	mov 4,r10
	st.w r10,16[sp]
	mov 4,r6
	mov 1,r7
	mov 2,r8
	mov 3,r9
	jarl _test,r31
	mov 0,r10
	br .L6
.L6:
	mov r29,sp
	ld.w 24[sp],r31
	ld.w 20[sp],r29
	addi 28,sp,sp
	jmp [r31]
.Lfe2:
	.size	 _main,.Lfe2-_main
	.ident	"GCC: (GNU) 2.96-xscale-010827"


***********************************************************


	.file	"va_arg.c"
	.section .text
	.align 1
	.global _test
	.type	_test,@function
_test:
	st.w r6,0[sp]
	st.w r7,4[sp]
	st.w r8,8[sp]
	st.w r9,12[sp]
	addi -32,sp,sp
	st.w r31,28[sp]
	st.w r29,24[sp]
	mov sp,r29
	st.w r6,32[r29]
	addi 36,r29,r10
	st.w r10,20[r29]
.L2:
	ld.w 32[r29],r10
	cmp r0,r10
	bne .L4
	br .L1
.L4:
	ld.w 20[r29],r11
	addi 4,r11,r10
	st.w r10,20[r29]
	ld.w 0[r11],r10
	st.w r10,16[r29]
	ld.w 16[r29],r6
	jarl _out,r31
	ld.w 32[r29],r10
	add -1,r10
	st.w r10,32[r29]
	br .L2
.L1:
	mov r29,sp
	ld.w 28[sp],r31
	ld.w 24[sp],r29
	addi 32,sp,sp
	jmp [r31]
.Lfe1:
	.size	_test,.Lfe1-_test
	.align 1
	.global _main
	.type	_main,@function
_main:
	addi -28,sp,sp
	st.w r31,24[sp]
	st.w r29,20[sp]
	mov sp,r29
	mov 4,r10
	st.w r10,16[sp]
	mov 4,r6
	mov 1,r7
	mov 2,r8
	mov 3,r9
	jarl _test,r31
	mov 0,r10
	mov r29,sp
	ld.w 24[sp],r31
	ld.w 20[sp],r29
	addi 28,sp,sp
	jmp [r31]
.Lfe2:
	.size	_main,.Lfe2-_main
	.ident	"GCC: (GNU) 3.1.1"

Comment 8 Dara Hazeghi 2003-06-04 10:58:10 UTC
Thanks for the feedback. I think we should leave this open until v850 bootstraps, and Nick can 
make certain the problem is fixed. Thanks,

Dara

P.S. Nick, if you disagree, feel free to close this report.
Comment 9 Andrew Pinski 2003-06-27 03:25:33 UTC
v850 does not build now but the patch does fix the problem in 3.1.1 si I am changing this 
to new.
Comment 10 Dara Hazeghi 2003-08-11 18:49:29 UTC
Now that v850-elf builds again, it looks like 3.4 produces identical asm to 
3.1.1 for this testcase. Nick, does this mean this problem is fixed? 
Thanks,

Dara
Comment 11 Nick Clifton 2003-08-12 13:32:03 UTC
Subject: Re:  [v850] va_arg() fails in expanding arguments

Hi Dara,

> Now that v850-elf builds again, it looks like 3.4 produces identical
> asm to  3.1.1 for this testcase. Nick, does this mean this problem
> is fixed?

Yes - this one can be closed.

Cheers
        Nick
        

Comment 12 Andrew Pinski 2003-08-12 13:35:32 UTC
Closing as this is fixed on the mainline.