cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] "already tagged token" error?
@ 2019-11-20  7:03 Ondřej Surý
  2019-11-21 20:06 ` Julia Lawall
  2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Ondřej Surý @ 2019-11-20  7:03 UTC (permalink / raw)
  To: cocci

Hi,

this is the error we started getting with upgrade to 1.0.7 (from 1.0.6).

EXN: Failure("rule starting on line 1: already tagged token:\nC code context\nFile \"./lib/dns/client.c\", line 1342, column 1, charpos = 33224\n  around = 'if',\n  whole content = \tif (rctx == NULL)“)

EXN: Failure("rule starting on line 1: already tagged token:\nC code context\nFile \"./lib/ns/tests/nstest.c\", line 704, column 1, charpos = 15998\n  around = 'if',\n  whole content = \tif (qctx != NULL) {")

The minimal reproducer is:

@@
statement S1, S2;
expression V;
@@

V = isc_mem_get(...);
- if (V == NULL) S1 else { S2 }
+ S2

--

On related note, what would be the correct way to write a rule for:

foo = isc_mem_get(…);
bar = isc_mem_get(…);

if (foo == NULL || bar == NULL) { … };

my naive approach:

@@
statement S;
expression V, E;
@@

V = isc_mem_get(...);
...
- if (V == NULL || E) S
+ if (E) S

doesn’t really work (it matches only a simple case, but not when there’s more than two memory allocations).

I thought something like this might work:

@@
statement S;
expression V, E;
@@

V = isc_mem_get(...);
...
if (...
-|| V == NULL
...) S

@@
statement S;
expression V, E;
@@

V = isc_mem_get(...);
...
if (...
- V == NULL ||
...) S

would work, but it says:

minus: parse error:
  File "x", line 10, column 0, charpos = 86
  around = '...',
  whole content = ...) S

--

And one last question:

Is there a simple way how to merge these these rules together?  It seems like it should be possible, but I wasn’t able to decipher the syntax for making parts of the match to be remove to be optional (but if you point me to an example in the base files or coccinellery, I would try harder).

@@
statement S1, S2;
expression V;
@@

V = isc_mem_get(...);
- if (V == NULL) S1 else { S2 }
+ S2

@@
statement S;
expression V;
@@

V = isc_mem_get(...);
- if (V == NULL) S

@@
type T;
statement S;
expression V;
@@

V = (T *)isc_mem_get(...);
- if (V == NULL) S

@@
statement S;
expression V;
@@

if (V == NULL) V = isc_mem_get(...);
- if (V == NULL) S

@@
type T;
expression V, E1, E2;
@@

- V = (T)isc_mem_get(E1, E2);
+ V = isc_mem_get(E1, E2);


Thank you,
--
Ondřej Surý
ondrej@sury.org



_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] "already tagged token" error?
  2019-11-20  7:03 [Cocci] "already tagged token" error? Ondřej Surý
@ 2019-11-21 20:06 ` Julia Lawall
  2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2019-11-21 20:06 UTC (permalink / raw)
  To: Ondřej Surý; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 3430 bytes --]



On Wed, 20 Nov 2019, Ondřej Surý wrote:

> Hi,
>
> this is the error we started getting with upgrade to 1.0.7 (from 1.0.6).
>
> EXN: Failure("rule starting on line 1: already tagged token:\nC code context\nFile \"./lib/dns/client.c\", line 1342, column 1, charpos = 33224\n  around = 'if',\n  whole content = \tif (rctx == NULL)“)
>
> EXN: Failure("rule starting on line 1: already tagged token:\nC code context\nFile \"./lib/ns/tests/nstest.c\", line 704, column 1, charpos = 15998\n  around = 'if',\n  whole content = \tif (qctx != NULL) {")
>
> The minimal reproducer is:
>
> @@
> statement S1, S2;
> expression V;
> @@
>
> V = isc_mem_get(...);
> - if (V == NULL) S1 else { S2 }
> + S2

I would need the C code as well.  Maybe it would help to write:

- if (V == NULL) S1 else {
  S2
- }

>
> --
>
> On related note, what would be the correct way to write a rule for:
>
> foo = isc_mem_get(…);
> bar = isc_mem_get(…);
>
> if (foo == NULL || bar == NULL) { … };
>
> my naive approach:
>
> @@
> statement S;
> expression V, E;
> @@
>
> V = isc_mem_get(...);
> ...
> - if (V == NULL || E) S
> + if (E) S
>
> doesn’t really work (it matches only a simple case, but not when there’s more than two memory allocations).

Try replacing E by ...

Then reorganize the pattern so that there is only - code, not + code.
I'm not sure this will actually work for transformation though.  You may
have to be resigned to just searching for the problem, ie

V = isc_mem_get(...);
...
* if (V == NULL || E) S

and not actually doing the update.


> I thought something like this might work:
>
> @@
> statement S;
> expression V, E;
> @@
>
> V = isc_mem_get(...);
> ...
> if (...
> -|| V == NULL
> ...) S

The ... right after NULL doesn't work.  It could be || ...

> @@
> statement S;
> expression V, E;
> @@
>
> V = isc_mem_get(...);
> ...
> if (...
> - V == NULL ||
> ...) S
>
> would work, but it says:
>
> minus: parse error:
>   File "x", line 10, column 0, charpos = 86
>   around = '...',
>   whole content = ...) S

Likewise, you would need ... ||

>
> --
>
> And one last question:
>
> Is there a simple way how to merge these these rules together?  It seems
> like it should be possible, but I wasn’t able to decipher the syntax for
> making parts of the match to be remove to be optional (but if you point
> me to an example in the base files or coccinellery, I would try harder).
>
> @@
> statement S1, S2;
> expression V;
> @@
>
> V = isc_mem_get(...);
> - if (V == NULL) S1 else { S2 }
> + S2
>
> @@
> statement S;
> expression V;
> @@
>
> V = isc_mem_get(...);
> - if (V == NULL) S
>
> @@
> type T;
> statement S;
> expression V;
> @@
>
> V = (T *)isc_mem_get(...);
> - if (V == NULL) S

If you had just (T) rather than (T*), then this rule would also cover
everything covered by the previous rule.  But if you want to specify that
it has to be a pointer type then a specific rule is needed.

>
> @@
> statement S;
> expression V;
> @@
>
> if (V == NULL) V = isc_mem_get(...);
> - if (V == NULL) S
>
> @@
> type T;
> expression V, E1, E2;
> @@
>
> - V = (T)isc_mem_get(E1, E2);
> + V = isc_mem_get(E1, E2);

If you put this rule first, then the other rules would not have to
consider the type case.

julia

>
> Thank you,
> --
> Ondřej Surý
> ondrej@sury.org
>
>
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Merging SmPL rules
  2019-11-20  7:03 [Cocci] "already tagged token" error? Ondřej Surý
  2019-11-21 20:06 ` Julia Lawall
@ 2019-11-21 20:42 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-11-21 20:42 UTC (permalink / raw)
  To: Ondřej Surý; +Cc: cocci

> Is there a simple way how to merge these these rules together?

The answer will depend on your expectations for simplicity.


> It seems like it should be possible,

* Can you identify useful merge criteria already?

* Are you aware of software design possibilities from
  the application of SmPL disjunctions?


> but I wasn’t able to decipher the syntax for making parts
> of the match to be remove to be optional

Did you try out to specify the minus character at the beginning
of several lines instead of trying to express a change
only in a single text line?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2019-11-21 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  7:03 [Cocci] "already tagged token" error? Ondřej Surý
2019-11-21 20:06 ` Julia Lawall
2019-11-21 20:42 ` [Cocci] Merging SmPL rules Markus Elfring

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).