spatch issue with C struct initialization
Hi,
I tried to use the coccinellery/doubleinit/doubleinit.cocci script using the latest spatch version (1.0.0-rc20, I tried prev versions too).
I received the following error:init_defs_builtins: /usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400
around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};
Any help will be appreciated,
Thanks,
Marcel
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
julia
Quoted 24 lines · Julia Lawall
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};
Quoted 2 lines
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
Hi Julia,
Thank you for your fast response.
I could compile after adding a comma(thanks!), but it still doesn't work. For example, I am not able to delete a field which is not the first one in the initialization list.
Ex:
c file:
struct my_struct {
int fld1;
int fld2;
int fld3;
};
static const my_struct m1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
}
cocci:
@@
identifier I;
expression E,
@@
struct my_struct I = {
...,
- .fld2 = E,
...
};
The above compiles fine but does not remove the field. I think it should work, any idea why is not working?
Thank you,
Marcel
Quoted 2 lines
julia
Quoted 42 lines · Marcel Apfelbaum
Quoted 24 lines · Julia Lawall
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};Quoted 2 lines
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
Hi Julia,
Thank you for your fast response.I could compile after adding a comma(thanks!), but it still doesn't work. For example, I am not able to delete a field which is not the first one in the initialization list.
Ex:
c file:
structmy_struct{
int fld1;
int fld2;
int fld3;
};
Quoted 5 lines
static const
my_structm1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
}
Is this your exact program? Because I think there should be the word "struct" somewhere? If code doesn't compile, Coccinelle just ignores it silently, unless you use the --verbose-parsing option.
I'll double check whether that is the only problem.
julia
Quoted 23 lines
cocci:
@@
identifier I;
expression E,
@@
structmy_structI = {
...,
- .fld2 = E,
...
};The above compiles fine but does not remove the field. I think it should work, any idea why is not working?
Thank you,
MarcelQuoted 2 lines
julia
For me, it worked fine with exactly the following files:
C file:
struct my_struct {
int fld1;
int fld2;
int fld3;
};
static const struct my_struct m1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
};
Cocci file:
@@
identifier I;
expression E;
@@
struct my_struct I = {
...,
- .fld1 = E,
...
};
I tried with fld1, fld2, and fld3, and all were fine.
julia
Quoted 52 lines · Julia Lawall
Quoted 42 lines · Marcel Apfelbaum
Quoted 24 lines · Julia Lawall
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};Quoted 2 lines
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
Hi Julia,
Thank you for your fast response.I could compile after adding a comma(thanks!), but it still doesn't work. For example, I am not able to delete a field which is not the first one in the initialization list.
Ex:
c file:
structmy_struct{
int fld1;
int fld2;
int fld3;
};Quoted 5 lines
static const
my_structm1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
}
Quoted 5 lines
Is this your exact program? Because I think there should be the word "struct" somewhere? If code doesn't compile, Coccinelle just ignores it silently, unless you use the --verbose-parsing option.
I'll double check whether that is the only problem.
Hi Julia,
No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)
However, using your verbose flag (thanks!!! I was looking for it) I got:
bad: static const VMStateDescription vmstate_stellaris_gptm = {
bad: .name = "stellaris_gptm",
bad: .version_id = 1,
bad: .minimum_version_id = 1,
bad: .minimum_version_id_old = 1,
BAD:!!!!! .fields = (VMStateField[]) {
bad: VMSTATE_UINT32(config, gptm_state),
bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
bad: VMSTATE_UINT32(control, gptm_state),
bad: VMSTATE_UINT32(state, gptm_state),
bad: VMSTATE_UINT32(mask, gptm_state),
bad: VMSTATE_UNUSED(8),
bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
bad: VMSTATE_UINT32(rtc, gptm_state),
bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
bad: VMSTATE_END_OF_LIST()
bad: }
bad: };Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Appreciate your involvement,
Marcel
Quoted 26 lines
julia
Quoted 23 lines
cocci:
@@
identifier I;
expression E,
@@
structmy_structI = {
...,
- .fld2 = E,
...
};The above compiles fine but does not remove the field. I think it should work, any idea why is not working?
Thank you,
MarcelQuoted 2 lines
julia
Quoted 62 lines · Marcel Apfelbaum
Quoted 52 lines · Julia Lawall
Quoted 42 lines · Marcel Apfelbaum
Quoted 24 lines · Julia Lawall
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};Quoted 2 lines
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
Hi Julia,
Thank you for your fast response.I could compile after adding a comma(thanks!), but it still doesn't work. For example, I am not able to delete a field which is not the first one in the initialization list.
Ex:
c file:
structmy_struct{
int fld1;
int fld2;
int fld3;
};Quoted 5 lines
static const
my_structm1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
}Quoted 5 lines
Is this your exact program? Because I think there should be the word "struct" somewhere? If code doesn't compile, Coccinelle just ignores it silently, unless you use the --verbose-parsing option.
I'll double check whether that is the only problem.
Hi Julia,
No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)
Quoted 8 lines
However, using your verbose flag (thanks!!! I was looking for it) I got:
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1,BAD:!!!!! .fields = (VMStateField[]) {
I suspect that the parser does not consider the possibility of a cast in this position. At the moment, I see no way around it. I can look into how to add the possibility of a cast.
julia
Quoted 53 lines
bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Appreciate your involvement,
MarcelQuoted 26 lines
julia
Quoted 23 lines
cocci:
@@
identifier I;
expression E,
@@
structmy_structI = {
...,
- .fld2 = E,
...
};The above compiles fine but does not remove the field. I think it should work, any idea why is not working?
Thank you,
MarcelQuoted 2 lines
julia
Quoted 75 lines · Julia Lawall
Quoted 62 lines · Marcel Apfelbaum
Quoted 52 lines · Julia Lawall
Quoted 42 lines · Marcel Apfelbaum
Quoted 24 lines · Julia Lawall
Quoted 14 lines · Marcel Apfelbaum
Hi,
I tried to use thecoccinellery/doubleinit/doubleinit.cocciscript using the latest spatch version (1.0.0-rc20, I tried prev versions too).I received the following error:
init_defs_builtins:/usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error:
= File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22, charpos = 400around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};")
Am I missing something, am I doing something wrong?
Quoted 7 lines
I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};Quoted 2 lines
Sorry, coccinellery versions may be out of date. You need to put a comma after the first ...
Hi Julia,
Thank you for your fast response.I could compile after adding a comma(thanks!), but it still doesn't work. For example, I am not able to delete a field which is not the first one in the initialization list.
Ex:
c file:
structmy_struct{
int fld1;
int fld2;
int fld3;
};Quoted 5 lines
static const
my_structm1 = {
.fld1 = 1,
.fld2 = 2,
.fld3 = 3,
}Quoted 5 lines
Is this your exact program? Because I think there should be the word "struct" somewhere? If code doesn't compile, Coccinelle just ignores it silently, unless you use the --verbose-parsing option.
I'll double check whether that is the only problem.
Hi Julia,
No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)Quoted 8 lines
However, using your verbose flag (thanks!!! I was looking for it) I got:
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1,BAD:!!!!! .fields = (VMStateField[]) {
Quoted 3 lines
I suspect that the parser does not consider the possibility of a cast in this position. At the moment, I see no way around it. I can look into how to add the possibility of a cast.
Understood,
Thanks Julia!
Marcel
Quoted 56 lines
julia
Quoted 53 lines
bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Appreciate your involvement,
MarcelQuoted 26 lines
julia
Quoted 23 lines
cocci:
@@
identifier I;
expression E,
@@
structmy_structI = {
...,
- .fld2 = E,
...
};The above compiles fine but does not remove the field. I think it should work, any idea why is not working?
Thank you,
MarcelQuoted 2 lines
julia
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = {
bad: .name = "stellaris_gptm",
bad: .version_id = 1,
bad: .minimum_version_id = 1,
bad: .minimum_version_id_old = 1,
BAD:!!!!! .fields = (VMStateField[]) {
bad: VMSTATE_UINT32(config, gptm_state),
bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
bad: VMSTATE_UINT32(control, gptm_state),
bad: VMSTATE_UINT32(state, gptm_state),
bad: VMSTATE_UINT32(mask, gptm_state),
bad: VMSTATE_UNUSED(8),
bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
bad: VMSTATE_UINT32(rtc, gptm_state),
bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
bad: VMSTATE_END_OF_LIST()
bad: }
bad: };Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Unfortunately, I'm not sure how to do this without introducing conflicts in the grammar. Currently the grammar is roughly of the following form (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
initializer
: assignment_expression
| '{' initializer_list '}'
| '{' initializer_list ',' '}'
;A cast on an ordinary expression is a bit deep in assignment_expression. So the parser is not happy to have the possibility of a cast on { ... } as well.
The cast seems to be allowed in C99, but I don't know what the grammar looks like to allow that.
Any suggestions are welcome.
julia
Quoted 36 lines · Julia Lawall
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1, BAD:!!!!! .fields = (VMStateField[]) { bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Unfortunately, I'm not sure how to do this without introducing conflicts in the grammar. Currently the grammar is roughly of the following form (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
initializer
: assignment_expression | '{' initializer_list '}' | '{' initializer_list ',' '}' ;
Quoted 6 lines
A cast on an ordinary expression is a bit deep in
assignment_expression. So the parser is not happy to have the possibility of a cast on { ... } as well.The cast seems to be allowed in C99, but I don't know what the grammar looks like to allow that.
That's actually not a cast but a compound literal
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
bye
micheal
Quoted 37 lines · Michael Stefaniuc
Quoted 36 lines · Julia Lawall
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1, BAD:!!!!! .fields = (VMStateField[]) { bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Unfortunately, I'm not sure how to do this without introducing conflicts in the grammar. Currently the grammar is roughly of the following form (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
initializer
: assignment_expression | '{' initializer_list '}' | '{' initializer_list ',' '}' ;
Quoted 8 lines
Quoted 6 lines
A cast on an ordinary expression is a bit deep in
assignment_expression. So the parser is not happy to have the possibility of a cast on { ... } as well.The cast seems to be allowed in C99, but I don't know what the grammar looks like to allow that.
That's actually not a cast but a compound literal
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
Thanks for the pointer. I'm still not sure to see how to solve the ambiguity problem.
julia
[Cocci] Handling of compound literals?
Quoted 4 lines
Quoted 2 lines
That's actually not a cast but a compound literal
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html[...] I'm still not sure to see how to solve the ambiguity problem.
How do you think about to ask any other parser and compiler developers?
Regards,
Markus
Quoted 45 lines · Julia Lawall
Quoted 41 lines · Michael Stefaniuc
Quoted 40 lines · Julia Lawall
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1, BAD:!!!!! .fields = (VMStateField[]) { bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
Unfortunately, I'm not sure how to do this without introducing conflicts in the grammar. Currently the grammar is roughly of the following form (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
initializer
: assignment_expression | '{' initializer_list '}' | '{' initializer_list ',' '}' ;A cast on an ordinary expression is a bit deep in
assignment_expression. So the parser is not happy to have the possibility of a cast on { ... } as well.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The cast seems to be allowed in C99, but I don't know what the grammar looks like to allow that.
That's actually not a cast but a compound literal
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.htmlThanks for the pointer. I'm still not sure to see how to solve the ambiguity problem.
Not being an expert on grammar, there is a chance this will work ?
initializer
: assignment_expression
| '{' initializer_list '}'
| '{' initializer_list ',' '}'
| ( type-name ) { initializer-list }
| ( type-name ) { initializer-list , }If you can point me to the code dealing with it, I can try to play with it a little bit.
Thanks,
Marcel
Quoted 2 lines
julia
Quoted 11 lines
Not being an expert on grammar, there is a chance this will work ?
initializer
: assignment_expression | '{' initializer_list '}' | '{' initializer_list ',' '}' | ( type-name ) { initializer-list } | ( type-name ) { initializer-list , }If you can point me to the code dealing with it, I can try to play with it a little bit.
I think I already tried the same thing. The problem is that ( type-name ) is already buried deep within assignment_expression, for an ordinary cast, so the parser doesn't know which rule to choose.
julia
Quoted 29 lines · Marcel Apfelbaum
Quoted 28 lines · Julia Lawall
Quoted 24 lines · Michael Stefaniuc
Quoted 23 lines · Julia Lawall
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1, BAD:!!!!! .fields = (VMStateField[]) { bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
In the end, the problem turned out to be not all what I thought. Actually, the Coccinelle C parser already accepts constructor expressions. The problem is that VMStateField is not recognized as a type. One approach is to find the header file that defines this type and then give Coccinelle enough information to find it. There are various options for that:
--all-includes: include all header files that are mentioned in the C file --recursive-includes: include also header files that are included from other header files
--relax-include-path: include a header file that has a unique name, no matter where it is defined in the source tree
-I path: give the name of a directory in which to search for header files. It is possilble to have more than one -I argument.
If none of this works, then you can also cause it to consider VMStateField to be a macro by adding eg #define VMStateField int to the macro file standard.h.
julia
Quoted 51 lines · Julia Lawall
Quoted 29 lines · Marcel Apfelbaum
Quoted 28 lines · Julia Lawall
Quoted 24 lines · Michael Stefaniuc
Quoted 23 lines · Julia Lawall
Quoted 23 lines
bad: static const VMStateDescription vmstate_stellaris_gptm = { bad: .name = "stellaris_gptm", bad: .version_id = 1, bad: .minimum_version_id = 1, bad: .minimum_version_id_old = 1, BAD:!!!!! .fields = (VMStateField[]) { bad: VMSTATE_UINT32(config, gptm_state), bad: VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), bad: VMSTATE_UINT32(control, gptm_state), bad: VMSTATE_UINT32(state, gptm_state), bad: VMSTATE_UINT32(mask, gptm_state), bad: VMSTATE_UNUSED(8), bad: VMSTATE_UINT32_ARRAY(load, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), bad: VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), bad: VMSTATE_UINT32(rtc, gptm_state), bad: VMSTATE_INT64_ARRAY(tick, gptm_state, 2), bad: VMSTATE_TIMER_ARRAY(timer, gptm_state, 2), bad: VMSTATE_END_OF_LIST() bad: } bad: };Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Judging by the capital "BAD", the ".fields" field is making the problem. Any way around it?
In the end, the problem turned out to be not all what I thought. Actually, the Coccinelle C parser already accepts constructor expressions. The problem is that VMStateField is not recognized as a type. One approach is to find the header file that defines this type and then give Coccinelle enough information to find it. There are various options for that:
--all-includes: include all header files that are mentioned in the C file --recursive-includes: include also header files that are included from other header files
--relax-include-path: include a header file that has a unique name, no matter where it is defined in the source tree
-I path: give the name of a directory in which to search for header files. It is possilble to have more than one -I argument.
Quoted 3 lines
If none of this works, then you can also cause it to consider VMStateField to be a macro by adding eg #define VMStateField int to the macro file
standard.h.
Hi Julia,
Thanks again for the detailed analysis. I will try the options you mentioned. Marcel
Quoted 2 lines
julia