All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] parser error with loops
@ 2023-05-11 12:32 Bernhard Reutner-Fischer
  2023-05-11 12:51 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Bernhard Reutner-Fischer @ 2023-05-11 12:32 UTC (permalink / raw)
  To: cocci; +Cc: Bernhard Reutner-Fischer

Hi!

I'm encountering parser errors with loops.
Is this a known limitation that is maybe fixed already or am i doing
something wrong?

$ for i in /tmp/dummy-1.cocci /tmp/dummy.c ;do echo "# $i";cat $i;echo EOF;done
# /tmp/dummy-1.cocci
@ rule179 @
expression V, IX, INDEX, VAL;
@@
- for (IX = 0; (IX >= vec_safe_length (V)) ? false : (((void) (VAL = (*V)[IX].value)), (INDEX = (*V)[IX].index), true); (IX)++)
+ FOR_EACH_CONSTRUCTOR_ELT (V, IX, INDEX, VAL)

EOF
# /tmp/dummy.c
int i;
EOF
$ spatch --c++=11 --smpl-spacing --in-place --sp-file /tmp/dummy-1.cocci /tmp/dummy.c
init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
minus: parse error: 
  File "/tmp/dummy-1.cocci", line 7, column 0, charpos = 221
  around = '',
  whole content = 

$ spatch --version | sed 1q
spatch version 1.1.0 compiled with OCaml version 4.11.1
# off debian


PS: i get a similar error for other kinds of loops:
@ rule428 @
expression NODE, VAR;
@@
- do { tree var_ = (VAR); SSA_NAME_CHECK (NODE)->ssa_name.var = var_; SSA_NAME_IS_VIRTUAL_OPERAND (NODE) = (var_ && TREE_CODE (var_) == VAR_DECL && VAR_DECL_IS_VIRTUAL_OPERAND (var_)); } while (0)
+ SET_SSA_NAME_VAR_OR_IDENTIFIER (NODE, VAR)


thanks,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [cocci] parser error with loops
  2023-05-11 12:32 [cocci] parser error with loops Bernhard Reutner-Fischer
@ 2023-05-11 12:51 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2023-05-11 12:51 UTC (permalink / raw)
  To: Bernhard Reutner-Fischer; +Cc: cocci



On Thu, 11 May 2023, Bernhard Reutner-Fischer wrote:

> Hi!
>
> I'm encountering parser errors with loops.
> Is this a known limitation that is maybe fixed already or am i doing
> something wrong?
>
> $ for i in /tmp/dummy-1.cocci /tmp/dummy.c ;do echo "# $i";cat $i;echo EOF;done
> # /tmp/dummy-1.cocci
> @ rule179 @
> expression V, IX, INDEX, VAL;
> @@
> - for (IX = 0; (IX >= vec_safe_length (V)) ? false : (((void) (VAL = (*V)[IX].value)), (INDEX = (*V)[IX].index), true); (IX)++)
> + FOR_EACH_CONSTRUCTOR_ELT (V, IX, INDEX, VAL)

Coccinelle only supports complete statements (extrassions, types, etc).
This is not a complete statement.  It is just the header of the for loop.

If you are targeting actual uses of loops, then you should be able to
solve the problem by declaring a statement metavariable S and putting a
single line wit S after your + line.

>
> EOF
> # /tmp/dummy.c
> int i;
> EOF
> $ spatch --c++=11 --smpl-spacing --in-place --sp-file /tmp/dummy-1.cocci /tmp/dummy.c
> init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
> minus: parse error:
>   File "/tmp/dummy-1.cocci", line 7, column 0, charpos = 221
>   around = '',
>   whole content =
>
> $ spatch --version | sed 1q
> spatch version 1.1.0 compiled with OCaml version 4.11.1
> # off debian
>
>
> PS: i get a similar error for other kinds of loops:
> @ rule428 @
> expression NODE, VAR;
> @@
> - do { tree var_ = (VAR); SSA_NAME_CHECK (NODE)->ssa_name.var = var_; SSA_NAME_IS_VIRTUAL_OPERAND (NODE) = (var_ && TREE_CODE (var_) == VAR_DECL && VAR_DECL_IS_VIRTUAL_OPERAND (var_)); } while (0)
> + SET_SSA_NAME_VAR_OR_IDENTIFIER (NODE, VAR)

If you are targeting a use of a do while loop, then just put a ; after
this, and all will be fine (you may need to compile the github version of
Coccinelle though).  If you are targeting the body of a macro definition,
then maybe it will work if you put the #define part first, but I odn't
know.  That is supported in the .c code, but I'm not sure if it is
supported in the semantic patch code.

julia

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11 12:32 [cocci] parser error with loops Bernhard Reutner-Fischer
2023-05-11 12:51 ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.