Address space of struct member
Hello,
I'm trying to obtain the address space of a member struct variable, e.g. Given the following test code:
struct astruct {
int __attribute__((address_space(5))) member1;
};int main(void)
{
struct astruct thestruct;
int __attribute__((address_space(5))) local;
if (local > 1)
;
if (thestruct.member1 > 1)
;
return 0;
}And the following smatch check:
static void check(struct expression *expr)
{
struct symbol *sym;
expr_to_var_sym(expr, &sym);
if (sym)
sm_warning("Address space %d\n", sym->ctype.as);
}void check_as(int id)
{
add_hook(&check, SYM_HOOK);
}When I run this check, it correctly picks up that 'local' has address space 5 - however it incorrectly indicates that 'member1' has address space 0.
Is there something that I am doing wrong? Or is this something I need to fix?
Thanks,
Andrew Murray
I'm still not back. I hopefully will be around next week sometime.
The expr_to_var_sym() function, is returning the wrong symbol for you. If you pass it foo->bar->baz then the symbol it returns is for "foo". There isn't really a symbol for ->baz because that's not a variable by itself. If you try expr to var sym() on foo[bar] then it fails because there are two symbols.
But you should be able to use get_type() to look up the information you want.
The symbol hook is not really useful for you in this situation either.w
Regards,
Dan Carpenter