cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Problem with improper multi-line string literals
Date: Fri, 12 Oct 2018 23:37:54 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.21.1810122336171.2383@hadrien> (raw)
In-Reply-To: <CAOZdJXWJLLZdttCJmZVbZU9EEjxxHGdvnRCmT+3=8O=Cv4yx-w@mail.gmail.com>



On Fri, 12 Oct 2018, Timur Tabi wrote:

> I've attached a test.c and nv_printf.cocci file that demonstrates the problem.
>
> It appears that Coccinelle sometimes cannot handle multi-line string
> literals that are syntactically correct but still improper.  For
> example:

It does look strange.  Maybe you can avoid removing and reconstructing the
string.  For example, if you rewrite rule1 as:

@rule1@
expression x;
expression list y;
@@
-DBG_PRINTF
+NV_PRINTF
  (
- x,
  y);

then the code generated by rule1 is OK.  I haven't checked whether this
can be done in the whole semantic patch, though.

julia

>
>         DBG_PRINTF((DBG_MODULE_OS, DBG_LEVEL_ERRORS,
>                     "NVRM: %s: this is a test \
>                     of multiline " NvP64_fmt " strings %p\n",
>                     __FUNCTION__,
>                     p1,
>                     p2));
>
> This is valid C, but technically the string literal should have
> quotation marks at the beginning of each line.  When Coccinelle
> attempts to process my script with this, it gets confused and mangles
> the parameters after the string literal:
>
>  void func(void)
>  {
> -        DBG_PRINTF((DBG_MODULE_OS, DBG_LEVEL_ERRORS,
> -                    "NVRM: %s: this is a test \
> -                    of multiline " NvP64_fmt " strings %p\n",
> -                    __FUNCTION__,
> -                    p1,
> -                    p2));
> -}
> +        NV_PRINTF(DBG_LEVEL_ERRORS, "NVRM: %s: this is a test \
> +                    of multiline " NvP64_fmt " strings %p\n", __FUNCTION__,
> +                    of multiline "p1, p2);
> +}"
>
> I added code into my Python script to combine the string into one
> line, but that doesn't really matter because Coccinelle doesn't even
> call my Python code.  In fact, it ignores many of my rules because the
> DBG_LEVEL_ERRORS should have been changed to "LEVEL_ERROR".
>

  reply	other threads:[~2018-10-12 21:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12 21:28 [Cocci] Problem with improper multi-line string literals Timur Tabi
2018-10-12 21:37 ` Julia Lawall [this message]
2018-10-12 21:42   ` Timur Tabi
2018-10-12 22:24     ` Timur Tabi
2018-10-12 23:08       ` Timur Tabi
2018-10-12 23:22         ` Timur Tabi
2018-10-13  3:08           ` Julia Lawall
     [not found]     ` <e4e5dc37-c364-c53d-26f6-52205cfee304@users.sourceforge.net>
2018-10-13 15:56       ` Timur Tabi
2018-10-13 21:19 ` Julia Lawall
2018-10-15 16:37   ` Timur Tabi
2018-10-15 16:39     ` Julia Lawall
2018-10-15 16:50       ` Timur Tabi
2018-10-15 16:55         ` Julia Lawall
2018-10-15 18:35           ` Timur Tabi
2018-10-16 15:10     ` Himanshu Jha
2018-10-16 15:12       ` Julia Lawall
2018-10-16 16:28       ` Timur Tabi
2018-10-16 16:39         ` Julia Lawall
2018-10-16 17:14           ` Timur Tabi
2018-10-16 17:10         ` Himanshu Jha

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=alpine.DEB.2.21.1810122336171.2383@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    /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 NNTP newsgroup(s).