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; }
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)
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
State-Changed-From-To: open->feedback State-Changed-Why: See Dara's question.
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
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
Thanks, sounds good... I'll leave it in WAITING in case the submitter can confirm it's fixed on previous versions. Dara
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"
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.
v850 does not build now but the patch does fix the problem in 3.1.1 si I am changing this to new.
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
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
Closing as this is fixed on the mainline.