Skip to contentSkip to conversation

macro parameters and expressions?

Cocci Jürgen Groß 3 participants 33 messages Oct 11, 2019 – Oct 17, 2019 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hi,

I have a simple semantic patch:

virtual patch

@@
expression buf, val;
@@
- snprintf(buf, PAGE_SIZE, "%d\n", val)
+ spgprintf_d(buf, val)

This works nearly always as expected, but not in some macros. The cases where it is not working are those when "val" is using a parameter of the macro, e.g.:

  #define MACRO(name)    snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Is that on purpose? If yes, how can this be avoided?

Juergen
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 12 lines · Jürgen Groß

Hi,

I have a simple semantic patch:

virtual patch

@@
expression buf, val;
@@
- snprintf(buf, PAGE_SIZE, "%d\n", val)
+ spgprintf_d(buf, val)

Quoted 7 lines

This works nearly always as expected, but not in some macros. The cases where it is not working are those when "val" is using a parameter of the macro, e.g.:

  #define MACRO(name)    snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Is that on purpose? If yes, how can this be avoided?

I don't think it should be on purpose. Could you send some C code that illustrates the problem?

thanks,
julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 6 lines
Quoted 3 lines
  #define MACRO(name)    snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Is that on purpose? If yes, how can this be avoided?

I don't think it should be on purpose. Could you send some C code that illustrates the problem?

Does the semantic patch language (Coccinelle software) support the adjustment of preprocessor definitions as in the shown source code example?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1910131806400.2565@hadrien

#4 lore raw

Re: [Cocci] Adjusting macros with SmPL?

Quoted 5 lines
Quoted 3 lines

Does the semantic patch language (Coccinelle software) support the adjustment of preprocessor definitions as in the shown source code example?

Can't you find the answer to this question by yourself by trying it?

My test did not show an useful patch result for the shown SmPL transformation variant.

I probably know another answer already if no other news will be contributed. Would you like to take another look at your commit from 2011-01-10?
https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#5 lore raw

Re: [Cocci] Adjusting macros with SmPL?

Quoted 4 lines · Markus Elfring
Quoted 4 lines
Quoted 3 lines

Does the semantic patch language (Coccinelle software) support the adjustment of preprocessor definitions as in the shown source code example?

Quoted 8 lines
Quoted 1 line

Can't you find the answer to this question by yourself by trying it?

My test did not show an useful patch result for the shown SmPL transformation variant.

I probably know another answer already if no other news will be contributed. Would you like to take another look at your commit from 2011-01-10?
https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1

This seems completely irrelevant. The question was about #define, not about #ifdef. Changes within #define code should be supported if Coccinelle is able to parse the code independently of its usage context.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#6 lore raw

Re: [Cocci] Adjusting macros with SmPL?

Quoted 3 lines
Quoted 1 line

https://github.com/coccinelle/coccinelle/commit/5e3f73c732075f7afadf383d088f3b6d0e1345b1

This seems completely irrelevant.

I got an other view also for this software area.
How many items can be assumed behind the word “etc.” in the section “upcoming/planned/todo”?

Quoted 1 line

The question was about #define, not about #ifdef.

Can we clarify the corresponding details better then?

Quoted 2 lines

Changes within #define code should be supported if Coccinelle is able to parse the code independently of its usage context.

Would you like to say that the desired software support is complete here?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#7 lore raw

Re: [Cocci] Adjusting macros with SmPL?

In reply to Julia Lawall
Quoted 2 lines

Changes within #define code should be supported if Coccinelle is able to parse the code independently of its usage context.

I suggest to take a closer look at the current software situation.

@replacement@
expression x;
identifier macro;
@@
#define macro(name)
-snprintf
+spgprintf_d
(...,
-PAGE_SIZE, "%d\n",
(x)->name)

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci use_spgprintf2.cocci …
minus: parse error:
File "use_spgprintf2.cocci", line 11, column 0, charpos = 132
around = '',
whole content =

Can such an error message be explained better?

I imagine that context-dependent data processing will be needed here to distinguish if preprocessor code should be adjusted (or not). How much will this technical aspect matter?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#8 lore raw

Re: [Cocci] Adjusting macros with SmPL?

Quoted 25 lines · Markus Elfring
Quoted 2 lines

Changes within #define code should be supported if Coccinelle is able to parse the code independently of its usage context.

I suggest to take a closer look at the current software situation.

@replacement@
expression x;
identifier macro;
@@
#define macro(name)

(quoted diff) +1 -2
-snprintf
+spgprintf_d
 (...,
-PAGE_SIZE, "%d\n",
 (x)->name)

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci use_spgprintf2.cocci …
minus: parse error:
File "use_spgprintf2.cocci", line 11, column 0, charpos = 132
around = '',
whole content =

Quoted 6 lines

Can such an error message be explained better?

I imagine that context-dependent data processing will be needed here to distinguish if preprocessor code should be adjusted (or not). How much will this technical aspect matter?

Macros are supposed to be written on one line.

Anyway, to my understanding the goal was not to modify the #define part, but rather only the code part.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#9 lore raw

Re: [Cocci] Adjusting macros with SmPL?

Quoted 5 lines
Quoted 3 lines

I imagine that context-dependent data processing will be needed here to distinguish if preprocessor code should be adjusted (or not). How much will this technical aspect matter?

Macros are supposed to be written on one line.

I suggest to reconsider also this view.
Would you like to take line continuations (or the escaping of line breaks) into account?

Quoted 2 lines

Anyway, to my understanding the goal was not to modify the #define part, but rather only the code part.

The shown transformation approach can probably be interpreted in two ways.

1. A source code modification should be performed behind a macro which can be empty.

2. Something should be generally adjusted. It would not matter then if the change is relevant (only) for preprocessor code (or not).

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#10 lore raw

Re: [Cocci] Adjusting macros with SmPL?

In reply to Julia Lawall
Quoted 1 line

Macros are supposed to be written on one line.

I guess that you refer to a logical source line.
https://en.cppreference.com/w/c/language/translation_phases#Phase_2

I am looking for better support around changing contents from physical text lines also by the means of the semantic patch language.

Quoted 2 lines

Anyway, to my understanding the goal was not to modify the #define part, but rather only the code part.

The following transformation approach can produce an usable result together with another small source file example.

@replacement@
expression buffer, x;
identifier macro;
@@
-#define macro(name) snprintf(buffer, PAGE_SIZE, "%u\n", (x)->name) +#define macro(name) spgprintf_d(buffer, (x)->name)

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#11 lore raw

Re: [Cocci] Adjustments with SmPL after macros?

In reply to Julia Lawall
Quoted 2 lines

Anyway, to my understanding the goal was not to modify the #define part, but rather only the code part.

Will it become supported by the semantic patch language to change source code directly after the occurrence of an empty macro?

@replacement@
identifier M;
@@
#define M
-snprintf
+spgprintf_d
(...)

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci use_spgprintf5.cocci …
minus: parse error:
File "use_spgprintf5.cocci", line 8, column 0, charpos = 72
around = '',
whole content =

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#12 lore raw

Re: [Cocci] Adjustments with SmPL after macros?

Review

Quoted 13 lines · Markus Elfring
Quoted 2 lines

Anyway, to my understanding the goal was not to modify the #define part, but rather only the code part.

Will it become supported by the semantic patch language to change source code directly after the occurrence of an empty macro?

@replacement@
identifier M;
@@
#define M

(quoted diff) +1 -1
-snprintf
+spgprintf_d
(...)

I think you could put \ in your semantic patch, like in C, but I don't know.

julia

Quoted 10 lines

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci use_spgprintf5.cocci …
minus: parse error:
File "use_spgprintf5.cocci", line 8, column 0, charpos = 72
around = '',
whole content =

Quoted 3 lines

Regards,
Markus

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#13 lore raw

Re: [Cocci] Adjustments with SmPL after macros?

Quoted 9 lines

Review

Quoted 7 lines

@replacement@
identifier M;
@@
#define M

(quoted diff) +1 -1
-snprintf
+spgprintf_d
(...)

I think you could put \ in your semantic patch, like in C,

I am interested also in the support for escaping of line breaks according to the desired handling of logical source lines. But how will the corresponding parsing become better for the shown tiny SmPL test script?

Quoted 1 line

but I don't know.

How will the knowledge evolve further for affected areas?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1910161850250.3539@hadrien

#16 lore raw

Re: [Cocci] Adjustments with SmPL after macros?

In reply to Julia Lawall
Quoted 9 lines

Review

Quoted 7 lines

@replacement@
identifier M;
@@
#define M

(quoted diff) +1 -1
-snprintf
+spgprintf_d
(...)

I think you could put \ in your semantic patch, like in C,

The escaping of line breaks would be required for the complete handling of logical source lines.
Such functionality does not help with the shown test script for the semantic patch language at the moment.

Quoted 1 line

but I don't know.

Can we change this aspect together?

Quoted 6 lines
Quoted 6 lines

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci use_spgprintf5.cocci …
minus: parse error:
File "use_spgprintf5.cocci", line 8, column 0, charpos = 72
around = '',
whole content =

Such an error message points some work in progress out.

* The data processing needs to be reconsidered for the safe support of object- and function-like macros.

* The explanation of the error reasons should become more helpful.

Thus I hope that more collateral evolution can happen for affected open issues. I assume that software development efforts will evolve then in
an other way than a “quick fix”.

The current parsing approach is using the tools “ocamlyacc” and “Menhir”. They support only the parsing technologies “LALR(1)” and “LR(1)” (context-free grammars).

I imagine that context-dependent data processing will be needed. I guess also that other development tools will be needed according to the Chomsky–Schützenberger hierarchy.
https://en.wikipedia.org/wiki/Context-sensitive_grammar

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw
Quoted 28 lines · Jürgen Groß
Quoted 20 lines · Julia Lawall
Quoted 16 lines · Jürgen Groß

Hi,

I have a simple semantic patch:

   virtual patch

   @@
   expression buf, val;
   @@
   - snprintf(buf, PAGE_SIZE, "%d\n", val)
   + spgprintf_d(buf, val)

This works nearly always as expected, but not in some macros. The cases where it is not working are those when "val" is using a parameter of the macro, e.g.:

Quoted 6 lines
Quoted 3 lines
   #define MACRO(name)    snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Is that on purpose? If yes, how can this be avoided?

I don't think it should be on purpose. Could you send some C code that illustrates the problem?

Quoted 8 lines

I have attached a little C file and a semantic patch, which I had located in a local directory.

I invoke spatch via: "spatch --cocci-file patch.cocci --patch . --dir ."

The result shows that the problem is a little bit different from my first analysis: whether a pattern is recognized or not seems to depend on macro parameter usage, which is not limited to the pattern itself.

Thanks for the examples. The problem in these examples actually has nothing to with parameter usage, but with the ability to parse the macro definition. I get:

#define macro1a(par) \
- func(buf, 1, par)
+ func2(buf, par)

Tha above mentions a parameter but the code gets changed. This case is no problem because the body of the macro is an expression.

 #define macro1b(par)            \
         func(buf, 1, par)       \
         func(buf, 1, par)

Nothing happens here. It is not possible in C to have one function call after another like this.

 #define macro2a(par)            \
         par++;                  \
         func(buf, 1, 17)

Nothing happens here either. Because the final ; is omitted the body of the macro is not valid C. But it doesn't work if you add a semicolon at the end either. It seems that a sequence of statements is not supported either. OOn the other hand, if you transform it into a do while(0), even with no trailing semicolon after the while (0) all is fine.

#define macro2b(par) \
- func(buf, 1, 17)
+ func2(buf, 17)

No problem again here.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#19 lore raw
Quoted 5 lines
 #define macro2a(par)            \
         par++;                  \
         func(buf, 1, 17)

Nothing happens here either.

May I see also the complete source code examples?

Quoted 1 line

Because the final ; is omitted the body of the macro is not valid C.

I suggest to reconsider also this view.

Quoted 2 lines

But it doesn't work if you add a semicolon at the end either. It seems that a sequence of statements is not supported either.

Do such software limitations become more interesting?

Quoted 2 lines

On the other hand, if you transform it into a do while(0), even with no trailing semicolon after the while (0) all is fine.

Such a coding style can also help.
How will the affected software components be improved further?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#20 lore raw
In reply to Julia Lawall
Quoted 53 lines · Julia Lawall
Quoted 28 lines · Jürgen Groß
Quoted 20 lines · Julia Lawall
Quoted 16 lines · Jürgen Groß

Hi,

I have a simple semantic patch:

    virtual patch

    @@
    expression buf, val;
    @@
    - snprintf(buf, PAGE_SIZE, "%d\n", val)
    + spgprintf_d(buf, val)

This works nearly always as expected, but not in some macros. The cases where it is not working are those when "val" is using a parameter of the macro, e.g.:

Quoted 6 lines
Quoted 3 lines
    #define MACRO(name)    snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Is that on purpose? If yes, how can this be avoided?

I don't think it should be on purpose. Could you send some C code that illustrates the problem?

Quoted 8 lines

I have attached a little C file and a semantic patch, which I had located in a local directory.

I invoke spatch via: "spatch --cocci-file patch.cocci --patch . --dir ."

The result shows that the problem is a little bit different from my first analysis: whether a pattern is recognized or not seems to depend on macro parameter usage, which is not limited to the pattern itself.

Thanks for the examples. The problem in these examples actually has nothing to with parameter usage, but with the ability to parse the macro definition. I get:

  #define macro1a(par)            \
(quoted diff) +1 -1
-        func(buf, 1, par)
+        func2(buf, par)

Tha above mentions a parameter but the code gets changed. This case is no problem because the body of the macro is an expression.

Quoted 6 lines
  #define macro1b(par)            \
          func(buf, 1, par)       \
          func(buf, 1, par)

Nothing happens here. It is not possible in C to have one function call after another like this.

Oh sorry, typo by me.

Quoted 11 lines

  #define macro2a(par)            \
          par++;                  \
          func(buf, 1, 17)

Nothing happens here either. Because the final ; is omitted the body of the macro is not valid C. But it doesn't work if you add a semicolon at the end either. It seems that a sequence of statements is not supported either. OOn the other hand, if you transform it into a do while(0), even with no trailing semicolon after the while (0) all is fine.

This is not always possible. See the new example as attached.

This is more like the original problem (stripped down a lot).

Juergen

#include <stdio.h>

#define macro1(prefix, name)                              \
static int func##prefix##_##name##_show(char *page)       \
{                                                         \
        return snprintf(page, 1, "%d\n", name);           \

}

#define macro2(name)                                      \
static int func##name##_show(char *page)                  \
{                                                         \
        int rb;                                           \
                                                          \
        rb = snprintf(page, 1, "%d\n", name);             \
                                                          \
        return rb;                                        \
}                                                         \
                                                          \

macro1(pre, name)

@@
expression buf, val;
@@
- snprintf(buf, 1, "%d\n", val)
+ spgprintf(buf, val)

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#21 lore raw
Quoted 8 lines
Quoted 4 lines

the macro is not valid C. But it doesn't work if you add a semicolon at the end either. It seems that a sequence of statements is not supported either. On the other hand, if you transform it into a do while(0), even with no trailing semicolon after the while (0) all is fine.

This is not always possible. See the new example as attached.

This is more like the original problem (stripped down a lot).

At the moment, a complete function definition is not possible. But I know that this is a common case. I'll see if it can be added without adding parsing conflicts. A sequence of statements did not work for this reason.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#22 lore raw
In reply to Jürgen Groß
Quoted 1 line

virtual patch

This variable should be omitted if it will not be used in subsequent SmPL rules.

Quoted 7 lines
   @@
   expression buf, val;
   @@
   - snprintf(buf, PAGE_SIZE, "%d\n", val)
   + spgprintf_d(buf, val)

This works nearly always as expected, but not in some macros.

Do you get any more interesting test results for the following transformation approach?

@replacement@
@@
-snprintf
+spgprintf_d
(...,
-PAGE_SIZE, "%d\n",
...)

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#23 lore raw
Quoted 3 lines · Markus Elfring
Quoted 1 line

virtual patch

This variable should be omitted if it will not be used in subsequent SmPL rules.

There is no harm to have it.

julia

Quoted 21 lines
Quoted 9 lines

   @@
   expression buf, val;
   @@
   - snprintf(buf, PAGE_SIZE, "%d\n", val)
   + spgprintf_d(buf, val)

This works nearly always as expected, but not in some macros.

Do you get any more interesting test results for the following transformation approach?

@replacement@
@@

(quoted diff) +1 -2
-snprintf
+spgprintf_d
 (...,
-PAGE_SIZE, "%d\n",
 ...)
Quoted 7 lines

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#24 lore raw

Re: [Cocci] Checking the influence of “virtual” SmPL variables

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

virtual patch

This variable should be omitted if it will not be used in subsequent SmPL rules.

There is no harm to have it.

Can you get additional software development concerns if you would look at a bug report on a topic like “Metavariables with the type "virtual" prevent proper initialisation for Python scripts.” once more?
https://github.com/coccinelle/coccinelle/issues/35

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#25 lore raw

Re: [Cocci] Checking the influence of “virtual” SmPL variables

Quoted 10 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

virtual patch

This variable should be omitted if it will not be used in subsequent SmPL rules.

There is no harm to have it.

Can you get additional software development concerns if you would look at a bug report on a topic like “Metavariables with the type "virtual" prevent proper initialisation for Python scripts.” once more?
https://github.com/coccinelle/coccinelle/issues/35

This comment is completely irrelevant. There is a difference between a virtual rule, that one can declare as being matched or not from the command line, and a virtual metavariable in a script, that has to be bound for the script to be executed.

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#26 lore raw

Re: [Cocci] Checking the influence of “virtual” SmPL variables

Quoted 3 lines
Quoted 1 line

https://github.com/coccinelle/coccinelle/issues/35

This comment is completely irrelevant.

I have got an other view.

Quoted 3 lines

There is a difference between a virtual rule, that one can declare as being matched or not from the command line, and a virtual metavariable in a script, that has to be bound for the script to be executed.

There are different uses to consider for this kind of SmPL variable, aren't there?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#27 lore raw
In reply to Jürgen Groß
Quoted 1 line

This works nearly always as expected, but not in some macros.

Do you find any information from previous bug reports also helpful for the clarification of your use case?

Examples:
* Fix search for parameterised macros with SmPL
https://github.com/coccinelle/coccinelle/issues/94

* Complete support for construction of #define directives
https://github.com/coccinelle/coccinelle/issues/139

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1910141740580.2330@hadrien

#29 lore raw
Quoted 1 line

There are no #defines in his semantic patch.

I noticed this implementation detail already from his clarification request.

Quoted 1 line

When will you notice that?

Can the shown transformation approaches be applied then also to replacement lists (or would you prefer to refer to macro bodies)?

Example:
#define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#30 lore raw
In reply to a message not in the archive
Quoted 2 lines
Quoted 2 lines

* Fix search for parameterised macros with SmPL
https://github.com/coccinelle/coccinelle/issues/94

…

Quoted 1 line

There are no #defines in his semantic patch.

This design detail can probably be taken also better into account if other software development challenges will finally be solved.

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c Jürgen_Groß-Beispiel1.c …
(ONCE) LEXER:unrecognised symbol, in token rule:\
LEXER: WIERD end of file in string
PB: not found closing paren in fuzzy parsing
…
BAD:!!!!! #define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)
…

https://wiki.sei.cmu.edu/confluence/display/c/PRE11-C.+Do+not+conclude+macro+definitions+with+a+semicolon
https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html

How will the software situation be improved further?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#32 lore raw
In reply to Markus Elfring
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

* Fix search for parameterised macros with SmPL
https://github.com/coccinelle/coccinelle/issues/94

There are further software development challenges to consider around preprocessor code.

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c Jürgen_Groß-Beispiel2.c …
ERROR-RECOV: found sync end of #define, line 1
…
parse error
= File "Jürgen_Groß-Beispiel2.c", line 1, column 65, charpos = 65
around = '(',
whole content = #define MACRO(name) snprintf(buffer, PAGE_SIZE, "%u\n", pointer->(name));
badcount: 0
BAD:!!!!! #define MACRO(name) snprintf(buffer, PAGE_SIZE, "%u\n", pointer->(name)); …

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#33 lore raw
In reply to Markus Elfring
Quoted 8 lines · Markus Elfring
Quoted 2 lines
Quoted 2 lines

* Fix search for parameterised macros with SmPL
https://github.com/coccinelle/coccinelle/issues/94

…

Quoted 1 line

There are no #defines in his semantic patch.

This design detail can probably be taken also better into account if other software development challenges will finally be solved.

Quoted 7 lines

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-c Jürgen_Groß-Beispiel1.c …
(ONCE) LEXER:unrecognised symbol, in token rule:\
LEXER: WIERD end of file in string
PB: not found closing paren in fuzzy parsing
…
BAD:!!!!! #define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

If a " is missing then the code can't be parsed and Coccinelle won't do anything. But I don't know if this was a bug in the original code or something you have modified; you sent another message that did not have this problem.

Quoted 4 lines

https://wiki.sei.cmu.edu/confluence/display/c/PRE11-C.+Do+not+conclude+macro+definitions+with+a+semicolon
https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html

How will the software situation be improved further?

What software situation?

julia

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#34 lore raw
Quoted 3 lines
Quoted 1 line

BAD:!!!!! #define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

If a " is missing then the code can't be parsed and Coccinelle won't do anything.

I would appreciate if the error reporting will become nicer.

Quoted 1 line

But I don't know if this was a bug in the original code

You should probably know also this detail from the initial clarification request.
https://systeme.lip6.fr/pipermail/cocci/2019-October/006413.html

Quoted 1 line

or something you have modified;

I copied a bit of questionable source code also for my test approaches.

Quoted 1 line

you sent another message that did not have this problem.

I needed also further moments to notice related glitches.

Quoted 1 line

What software situation?

There are various open issues to consider around safe transformations also around preprocessor code (replacement lists), aren't there?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#35 lore raw
In reply to Julia Lawall
Quoted 3 lines
Quoted 1 line

BAD:!!!!! #define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

If a " is missing then the code can't be parsed and Coccinelle won't do anything.

I suggest to take additional software improvement opportunities into account.

Should a semantic patch language script become able to fix such questionable source code?

See also:
Add a metavariable for the handling of source code
https://github.com/coccinelle/coccinelle/issues/140

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#36 lore raw
Quoted 7 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line

BAD:!!!!! #define MACRO(name) snprintf(pg, PAGE_SIZE, %u\n", ptr->name)

If a " is missing then the code can't be parsed and Coccinelle won't do anything.

I suggest to take additional software improvement opportunities into account.

Should a semantic patch language script become able to fix such questionable source code?

No.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci