#733 Incorrect code generation calling variable argument function


If a called function has a variable number of arguments
and one of the arguments is the result of an inline
function call (see below), and the code is compiled
with the --stack-auto option, sdcc generates the wrong
assembly code for the call. The parameters are passed
the wrong way around and (possibly, didn't investigate
fully and probably not apparent in this small example)
one is overwritten with the other during the start of
the execution of the inline function. This is the
smallest test case I could make:

unsigned char foo(unsigned char a, ...) { return a; }
unsigned char bar(unsigned char a, unsigned char b) {
return a + b; }

void main(void) { foo(0, bar(1, 2)); }

If you compile using "sdcc --stack-auto" and inspect
the resulting .asm file you will see this:

;Allocation info for local variables in function 'main'
;sdcctest.c:4: void main(void) { foo(0, bar(1, 2)); }
; -----------------------------------------
; function main
; -----------------------------------------
push _bp
mov _bp,sp
; genIpush
mov a,#0x01
push acc
; genCall
mov dpl,#0x02
lcall _bar

"sdcc -v" gives:

2.4.1 (Mar 30 2004) (CYGWIN)

You can contact me at samghost@mpx.net for further
correspondence. Thanks,

Sam Brightman


  • Bernhard Held

    Bernhard Held - 2004-04-11

    Logged In: YES

    Fixed in SDCCast.c 1.234

  • Bernhard Held

    Bernhard Held - 2004-04-11
    • labels: --> C-Front End
    • milestone: --> fixed
    • assigned_to: nobody --> bernhardheld
    • status: open --> closed-fixed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks