Ticket #73 (accepted defect)

Opened 9 years ago

Last modified 9 years ago

unable to compile aesop function that returns a struct

Reported by: carns Owned by: carns
Priority: major Component: code generator
Version: git repository Keywords:
Cc:

Description

Reported by Matthew Curry:

Here’s the bug: It seems one can’t define a prototype for a function that returns a pointer to a struct. Here’s my reproducer:

#include <aesop/aesop.h>

struct test_struct {
        int i;
};

#ifdef DEFINE_PROTOTYPE
__blocking struct test_struct *ts_ret(int p);
#endif

__blocking struct test_struct *
ts_ret(int p)
{
        return NULL;
}

__blocking int
aemain(int argc, char **argv)
{
        (void)ts_ret(0);
        return 0;
}

aesop_main_set(aemain);

Here’s the output:

s971348:depinst mlcurry$ aecc test.ae -- -DDEFINE_PROTOTYPE
Compilation step failed: 
test.ae:11:5: error: ‘ts_ret’ redeclared as different kind of symbol
 __blocking struct test_struct *
     ^
test.ae:8:8: note: previous declaration of ‘ts_ret’ was here
 __blocking struct test_struct *ts_ret(int p);
        ^
test.ae:11:5: error: ‘ts_ret’ redeclared as different kind of symbol
 __blocking struct test_struct *
     ^
test.ae:8:8: note: previous declaration of ‘ts_ret’ was here
 __blocking struct test_struct *ts_ret(int p);
        ^
s971348:depinst mlcurry$ aecc test.ae
s971348:depinst mlcurry$ 

Change History

comment:1 Changed 9 years ago by carns

  • Status changed from new to accepted

I haven't tried the provided example yet, but there are some functions in the triton source that return pointers to structs. One possible difference is that in each of those cases the struct happens to have been typedef'd to something like this:

typedef struct test_struct *test_struct_p 

__blocking test_struct_p ts_ret(int p);

I don't know if it is necessary to actually typedef the pointer as in that example, or the following might work as well:

typedef struct test_struct test_struct_t

__blocking test_struct_t* ts_ret(int p);

There may be a problem in the aesop parser related to struct types.

comment:2 Changed 9 years ago by carns

Confirmed that typedef in the function prototype and definition (using either style) works as a workaround. See parser/tests/blocking/return-struct-ptr-typedef.ae and parser/tests/blocking/return-struct-ptr.ae. Compilation of the latter is disabled since it fails at compile time.

Note: See TracTickets for help on using tickets.