variable size array declarations
I am trying to check something in Smatch with variable size arrays and I'm running into problems. Here is the function I'm trying to parse.
void func(int x)
{
char buf[x];
}Array symbols have an ->array_size. It gets set correctly in parse.c to expression of type EXPR_SYMBOL. But by the time I parse it in Smatch the ->array_size is now an EXPR_PREOP (a dereference). In fact all the variables seem to get change to dereferences of the variables.
So if I have:
char buf[a + b + *c + 4]; Smatch gets: char buf[*a + *b + **c + 4];
I'm not sure where this is getting changed or why.
regards,
dan carpenter
Quoted 9 lines · Dan Carpenter
I am trying to check something in Smatch with variable size arrays and I'm running into problems. Here is the function I'm trying to parse.
void func(int x)
{ char buf[x]; }
Quoted 6 lines
Array symbols have an ->array_size. It gets set correctly in
parse.cto expression of typeEXPR_SYMBOL. But by the time I parse it in Smatch the ->array_size is now anEXPR_PREOP(a dereference). In fact all the variables seem to get change to dereferences of the variables.
I tracked this down. In smatch, how I use sparse is that I call sparse_keep_tokens() and then I parse the resulting symbol list myself.
In examine_array_type() we call get_expression_value() which changes the symbols from normal symbols to dereferences. The call tree is:examine_array_type()
-> get_expression_value()
-> __get_expression_value()
-> evaluate_expression()
-> evaluate_symbol_expression() <- change happens here.The problem for me is that not all expressions have been evualated like this so it's not consistent.
regards,
dan carpenter