Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Cc: cocci@inria.fr
Subject: Re: [cocci] parser error with loops
Date: Thu, 11 May 2023 14:51:23 +0200 (CEST)	[thread overview]
Message-ID: <d054a7bd-913-1672-4c7f-923f6b651dd3@inria.fr> (raw)
In-Reply-To: <20230511143209.23065a5e@nbbrfq>



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

      reply	other threads:[~2023-05-11 12:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 12:32 [cocci] parser error with loops Bernhard Reutner-Fischer
2023-05-11 12:51 ` Julia Lawall [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d054a7bd-913-1672-4c7f-923f6b651dd3@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=cocci@inria.fr \
    --cc=rep.dot.nop@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).