Excluding specific assignment combinations with SmPL
Hello,
I am experimenting with another source code search pattern. This approach pointed a place like the following out for further considerations.
?
ice->akm = kcalloc(?); ak = ice->akm;
?
My evolving SmPL script used also two separate metavariables with the type ?expression? so that the value and target should be distinguished for assignment statements. Now I would like to exclude cases where the target is directly used again for the value specification as in the small example above.
How should be checked with the means of the semantic patch language that the same expression is not used in subsequent lines?
Regards,
Markus
Quoted 11 lines · SF Markus Elfring
Hello,
I am experimenting with another source code search pattern. This approach pointed a place like the following out for further considerations.
?
ice->akm = kcalloc(?); ak = ice->akm;?
Quoted 7 lines
My evolving SmPL script used also two separate metavariables with the type ?expression? so that the value and target should be distinguished for assignment statements. Now I would like to exclude cases where the target is directly used again for the value specification as in the small example above.
How should be checked with the means of the semantic patch language that the same expression is not used in subsequent lines?
Normally, if you want to prevent something, the easiest thing is to match it first, and then set up the pattern for what you want so that the latter matches only if the former did not match. For example, if you want to match an identifier other than xxx, you can say:
@@
identifier a;
@@
(
xxx
|
* a
)
Or
@bad@
position p;
symbol xxx;
@@
xxx at p
@@
identifier a;
position p != bad.p;
@@
a at p
julia
Quoted 3 lines
Normally, if you want to prevent something, the easiest thing is to match it first, and then set up the pattern for what you want so that the latter matches only if the former did not match.
Is my use case a bit more special so that other approaches would be needed?
Would another constraint make sense to prevent an unwanted match with the expression in the second statement?
Regards,
Markus
Quoted 5 lines · SF Markus Elfring
Quoted 3 lines
Normally, if you want to prevent something, the easiest thing is to match it first, and then set up the pattern for what you want so that the latter matches only if the former did not match.
Is my use case a bit more special so that other approaches would be needed?
No idea. Why don't you think about it on your own and write back if you don't figure anything out.
julia
Quoted 7 lines
Would another constraint make sense to prevent an unwanted match with the expression in the second statement?
Regards,
Markus
Quoted 2 lines
Why don't you think about it on your own and write back if you don't figure anything out.
I am still looking for ways to make a small SmPL specification like the following a bit safer.
@find_?@
expression ex1, ex2, value;
identifier action =~ ?;
@@
*ex1 = action(...);
ex2 = value;
I am unsure if such a source code search approach should eventually be split into more SmPL processing steps.
Regards,
Markus
Quoted 14 lines · SF Markus Elfring
Quoted 2 lines
Why don't you think about it on your own and write back if you don't figure anything out.
I am still looking for ways to make a small SmPL specification like the following a bit safer.
@find_?@
expression ex1, ex2, value;
identifier action =~ ?;
@@
*ex1 = action(...);
ex2 = value;
Quoted 2 lines
I am unsure if such a source code search approach should eventually be split into more SmPL processing steps.
(
ex1 = action(...);
ex2 = <+...ex1...+>;
|
*ex1 = action(...);
ex2 = value;
)
is perhaps what you are looking for.
julia
Quoted 9 lines
(
ex1 = action(...);
ex2 = <+...ex1...+>;
|
*ex1 = action(...);
ex2 = value;
)is perhaps what you are looking for.
I would prefer an approach where the expressions ?ex1? and ?value? could be compared somehow directly instead of matching an unwanted branch in a SmPL disjunction.
Regards,
Markus
[Cocci] Finding missing return value checks for some function calls with SmPL
In reply to Julia LawallQuoted 19 lines
Quoted 10 lines
@find_?@
expression ex1, ex2, value;
identifier action =~ ?;
@@
*ex1 = action(...);
ex2 = value;I am unsure if such a source code search approach should eventually be split into more SmPL processing steps.
(
ex1 = action(...);
ex2 = <+...ex1...+>;
|
*ex1 = action(...);
ex2 = value;
)
Quoted 1 line
is perhaps what you are looking for.
We discussed further possibilities around advanced usage of SmPL constraints a bit. The software evolution is unclear in this direction and might be too limited at the moment.
But the shown SmPL disjunction could also work with the Coccinelle software for a while. It has got run time characteristics where I got a few concerns.
The asterisk functionality is used there so that source code places can be marked as update candidates. Unfortunately, it seems that the software development challenge can be too big for the specification of a generic change approach.
Is such a small source code search pattern good enough in principle to be integrated into the evolving script collection for checking of various source files (including from Linux)?
Regards,
Markus