pepper-project / pequin

A system for verifying outsourced computations, and applying SNARKs. Simplified release of the main Pepper codebase.
Other
122 stars 46 forks source link

Cannot pass struct with an array inside to a function: Address has not been assigned yet. #49

Open noresistence opened 5 years ago

noresistence commented 5 years ago

I try to pass a struct (that contains an array) as a parameter to another function:

struct In { char alibi; };
struct Out { char alibi; };

typedef struct data {
    char name[1];
} data_t;

void foo(data_t data) {
    char *x;
    x = data.name;
}

void compute(struct In *input, struct Out *output) {
    data_t test;
    foo(test);
}

Trying to compile this example fails with the error: Address has not been assigned yet.

If i initialize the struct, the same error occurs. However, passing the struct by reference does not throw the error:

struct In { char alibi; };
struct Out { char alibi; };

typedef struct data {
    char name[1];
} data_t;

void foo(data_t *data) {
    char *x;
    x = data->name;
}

void compute(struct In *input, struct Out *output) {
    data_t test;
    foo(&test);
}

Trying to access something else in the struct that is not an array works as well, even when passed by value:

struct In { char alibi; };
struct Out { char alibi; };

typedef struct data {
    char name;
} data_t;

void foo(data_t data) {
    char x;
    x = data.name;
}

void compute(struct In *input, struct Out *output) {
    data_t test;
    foo(test);
}

I suspect it is a bug that passing the struct by value and then accessing an array does not compile?

maxhowald commented 5 years ago

Thanks for reporting this! I was able to reproduce the error.

Indeed, it looks like a bug in the frontend of the compiler. I'll try to take a look at it more closely soon.

MorelSerge commented 5 years ago

Any update on this?