v850-elf-gcc, va_list

markku.pihlajamaa@luukku.com markku.pihlajamaa@luukku.com
Wed Apr 24 00:25:00 GMT 2002


Hello,

I have submitted a GCC bug report about this and tried
to solve the problem by the patch below. After v850-elf-gcc
and Newlib have been rebuilt, the first few tests with sprintf()
are succesful.

Markku

----------------------------------------------------------------
*** 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)
----------------------------------------------------------------


> -----Original Message-----
> From: markku.pihlajamaa@luukku.com
> [mailto:markku.pihlajamaa@luukku.com]
> Sent: Thursday, April 18, 2002 12:39 PM
> To: crossgcc@sources.redhat.com
> Subject: v850-elf-gcc, va_list
>
>
>
> Hello everybody!
>
> I suppose my first post was catched by the spam checking,
> so I am trying another time.
>
> I am doing some tests with the 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.
>
> I have such a problem with the variable argument lists
> that the first optional argument is not expanded by
> va_arg() at all, but is skipped. In the example
> below the out() function is called four times,
> but the parameter gets bad values: 2, 3, 4 and a random
> number instead of 1, 2, 3 and 4.
>
> The C code, compiling command I have used and the
> assembly output produced (with my comments added)
> can be seen below.
>
> Any ideas are welcomed.
>
> 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;
> }
> ----------------------------------------------------
> [markku@linux1 va_list]$ v850-elf-gcc -S -v test.c
> Reading specs from /usr/local/lib/gcc-lib/v850-elf/2.96-xscale-
> 010827/specs
> gcc version 2.96-xscale-010827
>  /usr/local/lib/gcc-lib/v850-elf/2.96-xscale-010827/cpp -lang-c -v -
> D__GNUC__=2
> -D__GNUC_MINOR__=96 -D__v851__ -D__v850 -D__v851__ -D__v850 -
> D__v850__ test.c /t
> mp/cc5YEVvf.i
> GNU CPP version 2.96-xscale-010827 (cpplib)
>  (NEC V850)
> ignoring nonexistent directory `/usr/local/v850-elf/sys-include'
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/local/lib/gcc-lib/v850-elf/2.96-xscale-010827/include
>  /usr/local/v850-elf/include
> End of search list.
>  /usr/local/lib/gcc-lib/v850-elf/2.96-xscale-
> 010827/cc1 /tmp/cc5YEVvf.i -quiet -
> dumpbase test.c -version -o test.s
> GNU C version 2.96-xscale-010827 (v850-elf) compiled by GNU C
version
> 2.96 20000
> 731 (Red Hat Linux 7.1 2.96-81).
> [markku@linux1 va_list]$ cat test.s
>         .file   "test.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]
> ----------------------------------------------------
> The copies of the arguments are in the top of
> stack at this point:
> 1st 0[sp]
> 2nd 4[sp]
> 3rd 8[sp]
> 4th 12[sp]
> 5th 16[sp] (pushed by the caller)
> ----------------------------------------------------
>         addi -36,sp,sp
>         st.w r31,32[sp]
>         st.w r28,28[sp]
>         st.w r29,24[sp]
>         mov sp,r29
> ----------------------------------------------------
> r29 is used as a frame pointer
> ----------------------------------------------------
>         st.w r6,36[r29]
> ----------------------------------------------------
> loop counter initialisation, actually done at _test:
> ----------------------------------------------------
>         addi 40,r29,r10
>         st.w r10,20[r29]
> ----------------------------------------------------
> 20[r29] points to the next argument, initially 40[r29]
> or the copy of the 2nd argument
> ----------------------------------------------------
> .L3:
>         ld.w 36[r29],r10
>         cmp r0,r10
>         bne .L5
>         br .L4
> .L5:
>         ld.w 20[r29],r10
>         addi 4,r10,r11
>         st.w r11,20[r29]
> ----------------------------------------------------
> the address of the next argument value has been read,
> incremented and written back
> ----------------------------------------------------
>         ld.w 20[r29],r28
> ----------------------------------------------------
> the address that has already been incremented
> is read again; this way  the first optional argument
> is ignored
> ----------------------------------------------------
>         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"
> ----------------------------------------------------
>
>
> ...............................................
> Oma sähköposti aina käytössä! http://luukku.com
>
>
>
> ------
> Want more information?  See the CrossGCC FAQ,
> http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to
> crossgcc-unsubscribe@sources.redhat.com
>


...............................................
Oma sähköposti aina käytössä! http://luukku.com



------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com



More information about the crossgcc mailing list