Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#762 Similar bug to 907733 with pointers as parameters

closed-fixed
Erik Petrich
5
2014-08-15
2004-05-17
No

Hi,
When I compile the following code compiler creates code
with second pointer in memory, but it don't allocate
space for this pointer.
(Functions 'set_endfnc_1' and 'set_endfnc_5' are OK,
but 'set_endfnc_2', '..._3' and '..._4' are bad.)
See to created assembler.

---
typedef void endfnc_t( struct str_in_t *ps) reentrant;

typedef struct stest_t {
endfnc_t *efnc;
int i;
} stest_t;
void efnc_test( stest_t *st)
{
st->i = 1000;
}

// It's OK. Pointer is in registers
void set_endfnc_1( stest_t *st)
{
st->efnc = (void *)0;
}
// The first pointer is in registers,
// but the second pointer is in memory, and compiler
doesn't allocate memory :-(
void set_endfnc_2( stest_t *st, endfnc_t *efnc)
{
st->efnc = efnc;
}
// The first pointer is in registers,
// the second pointer should be in memory (but isn't),
// the last parameter is in memory.
void set_endfnc_3( stest_t *st, endfnc_t *efnc, int ii)
{
st->efnc = efnc;
st->i = ii;
}
// The first pointer is in registers,
// the second pointer should be in memory (but isn't),
// the last pointer should be in memory too.
void set_endfnc_4( stest_t *st, endfnc_t *efnc, int *pi)
{
st->efnc = efnc;
st->i = *pi;
}
// The first pointer is in registers,
// the second pointer is in stack.
void set_endfnc_5( stest_t *st, endfnc_t *efnc) reentrant
{
st->efnc = efnc;
}

void main(void)
{
int i=0;
stest_t test;

set_endfnc_1( &test); //, efnc_test);
set_endfnc_2( &test, efnc_test);
set_endfnc_3( &test, efnc_test, 100);
set_endfnc_4( &test, efnc_test, &i);
set_endfnc_5( &test, efnc_test);

test.efnc( &test);
}
---

Compiler create bad code with with these warnings:

$ sdcc parm_bug.c
?ASlink-Warning-Undefined Global '_set_endfnc_2_PARM_2'
referenced by module 'parm_bug'
?ASlink-Warning-Undefined Global '_set_endfnc_3_PARM_2'
referenced by module 'parm_bug'
?ASlink-Warning-Undefined Global '_set_endfnc_4_PARM_2'
referenced by module 'parm_bug'

$ sdcc -v
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.4.1 (Apr 23 2004) (UNIX)

Discussion

  •  
    Attachments
  • Erik Petrich
    Erik Petrich
    2004-05-18

    Logged In: YES
    user_id=635249

    Fixed in src/SDCCmem.c 1.67

     
  • Erik Petrich
    Erik Petrich
    2004-05-18

    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed