Concerns around type safety for usage of expressions
Hello,
The semantic patch language supports source code searches also for uses of specific data types. Such restricted searches can occasionally be nice. But we would like to find more software variations often enough. The consequence is that metavariables of the kind “expression” will usually be applied. But it becomes uncertain then to which data types the found expressions will be resolved finally.
We would like to achieve considerably safe software transformations. Use cases occur then where the correct application of data types is essential. (The introduction of false positives is undesirable here.)
How much can SmPL scripts help for corresponding changes?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 9 lines · Markus Elfring
Hello,
The semantic patch language supports source code searches also for uses of specific data types. Such restricted searches can occasionally be nice. But we would like to find more software variations often enough. The consequence is that metavariables of the kind “expression” will usually be applied. But it becomes uncertain then to which data types the found expressions will be resolved finally.
Quoted 5 lines
We would like to achieve considerably safe software transformations. Use cases occur then where the correct application of data types is essential. (The introduction of false positives is undesirable here.)
How much can SmPL scripts help for corresponding changes?
You can specify the type of an expression rather than just expression.
The ability of Coccinlle to find the types depends on whether header files are needed and whether Coccinelle can find those header files.
If a type is specified and Coccinelle cannot detetermine that an expression has the required type, the match will fail.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 1 line
You can specify the type of an expression rather than just expression.
How is this approach different from the search for “specific data types” (which I know already)?
I came along an use case where a generic source code search can find update candidates. But it would be nice if safety concerns can be handled then by using the determined data types somehow.
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 4 lines · Markus Elfring
Quoted 1 line
You can specify the type of an expression rather than just expression.
How is this approach different from the search for “specific data types” (which I know already)?
I have no idea what you are referring to.
julia
Quoted 8 lines
I came along an use case where a generic source code search can find update candidates. But it would be nice if safety concerns can be handled then by using the determined data types somehow.
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
You can specify the type of an expression rather than just expression.
How is this approach different from the search for “specific data types” (which I know already)?
I have no idea what you are referring to.
Do you find it easier to clarify transformation possibilities around applications of a macro like “COPY_ARRAY”?
https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 10 lines · Markus Elfring
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
You can specify the type of an expression rather than just expression.
How is this approach different from the search for “specific data types” (which I know already)?
I have no idea what you are referring to.
Do you find it easier to clarify transformation possibilities around applications of a macro like “COPY_ARRAY”?
https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889
I still don't understand what you are asking. Maybe it would be more understandable if you would propose a semantic patch.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
Do you find it easier to clarify transformation possibilities around applications of a macro like “COPY_ARRAY”?
https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889I still don't understand what you are asking.
I hope that also this communication difficulty will be resolved.
Quoted 1 line
Maybe it would be more understandable if you would propose a semantic patch.
Some SmPL scripts are still in corresponding review queues.
Another example:
“[PATCH] coccinelle: improve array.cocci” from 2019-11-18
https://public-inbox.org/git/[email protected]/
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 3 lines
Another example:
“[PATCH] coccinelle: improve array.cocci” from 2019-11-18
https://public-inbox.org/git/[email protected]/OK, so you already know how to express type constraints for things.
Where do you see that I did this?
Quoted 1 line
So what are you actually asking?
I hope that another clarification variant can also help.
How can the C data type be determined for an expression metavariable so that it could be used for subsequent source code searches?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 7 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Another example:
“[PATCH] coccinelle: improve array.cocci” from 2019-11-18
https://public-inbox.org/git/[email protected]/OK, so you already know how to express type constraints for things.
Where do you see that I did this?
T *ptr for example.
Quoted 8 lines
Quoted 3 lines
So what are you actually asking?
I hope that another clarification variant can also help.
How can the C data type be determined for an expression metavariable so that it could be used for subsequent source code searches?
@@
type T;
T x;
@@
Now after matching x, you can use both x and T. If Coccinelle cannot figure out the type of an expression, x will not be able to match that expression.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Another example:
“[PATCH] coccinelle: improve array.cocci” from 2019-11-18
https://public-inbox.org/git/[email protected]/OK, so you already know how to express type constraints for things.
Where do you see that I did this?
T *ptr for example.
It seems that you saw a a bit of SmPL code which I proposed to delete.
I suggest to take another look at the corresponding discussion.
https://public-inbox.org/git/[email protected]/
I assume that this feedback might fit also to the clarification request for the topic “Data processing with pointer types/expressions”.
https://lore.kernel.org/cocci/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-November/006609.html
Quoted 9 lines
Quoted 2 lines
How can the C data type be determined for an expression metavariable so that it could be used for subsequent source code searches?
@@
type T;
T x;
@@Now after matching x, you can use both x and T.
Such information can be fine itself.
Quoted 2 lines
If Coccinelle cannot figure out the type of an expression, x will not be able to match that expression.
This aspect can become more interesting.
* Do you suggest here to use such type metavariables together with expression metavariables?
* Can the data type determination become better documented?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 1 line
T *ptr for example.
1. Does this information for a “type constraint” distract from my questions?
2. Can the data type become restricted not only by the detail that it refers to a pointer?
3. Why should such a SmPL specification matter for the handling of expressions?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 6 lines · Markus Elfring
Quoted 1 line
T *ptr for example.
1. Does this information for a “type constraint” distract from my questions?
2. Can the data type become restricted not only by the detail that it refers to a pointer?
You can put any type, such as int x;. You can also put parts of types such as expression * x; or struct x;
Quoted 3 lines
3. Why should such a SmPL specification matter for the handling of expressions?
Only expressions have types.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 2 lines
2. Can the data type become restricted not only by the detail that it refers to a pointer?
You can put any type, such as int x;. You can also put parts of types such as expression * x; or struct x;
This information fits to my wording for restricted searches, doesn't it?
Quoted 4 lines
Quoted 2 lines
3. Why should such a SmPL specification matter for the handling of expressions?
Only expressions have types.
I can agree to this information mostly. (“Types” can become relevant also for other items.)
Does the Coccinelle software know the corresponding data type then?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Checking influence of variability with SmPL
In reply to Julia LawallHello,
Metavariables of the semantic patch language provide common information.
1. A fixed type (or kind)
2. An entity which can be variable.
These properties can be distinguished further.
Another example:
char c;
Such SmPL code looks like the specification of a fixed data type selection for the C programming language.
Do you know anything that could be still variable for such an item?
The situation is different for metavariable kinds like the following.
* identifier
* struct
* expression
We would like to achieve source code transformations which can be compiled (or not). How often will it matter then how these selections will be applied?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Checking influence of variability with SmPL
Quoted 7 lines · Markus Elfring
Hello,
Metavariables of the semantic patch language provide common information.
1. A fixed type (or kind)
2. An entity which can be variable.
Quoted 8 lines
These properties can be distinguished further.
Another example:
char c;Such SmPL code looks like the specification of a fixed data type selection for the C programming language.
Do you know anything that could be still variable for such an item?
What do you mean by still variable? c can match 'a' 'b' 'x', etc. It can also match a variable that has type char or a function call that returns a value of type char, etc. There are a lot of possibilities.
Quoted 6 lines
The situation is different for metavariable kinds like the following.
* identifier
* struct
* expression
An expression metavariable matches an expression of any type. A struct metavariable matches an expression that has struct type (for any struct type). A char metavariable matches an expression that has char type.
identifier doesn't fit in this discussion. It only matches identifiers, not arbitrary expressions.
Quoted 2 lines
We would like to achieve source code transformations which can be compiled (or not).
No idea what you mean by compiled. Compiled by what compiler?
Quoted 1 line
How often will it matter then how these selections will be applied?
What selections?
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Checking influence of variability with SmPL
Quoted 1 line
An expression metavariable matches an expression of any type.
Thanks for such an acknowledgement.
* Can this fact trigger corresponding challenges for safe transformations by the semantic patch language?
* Would you occasionally like to determine the corresponding data type then?
Quoted 2 lines
A struct metavariable matches an expression that has struct type (for any struct type). A char metavariable matches an expression that has char type.
I find this information very interesting for further clarification.
* Is a data type conversion performed by the Coccinelle software?
* Where should the explanation be found in the documentation for such software behaviour?
Quoted 2 lines
identifier doesn't fit in this discussion. It only matches identifiers, not arbitrary expressions.
I find that this metavariable will handle more variations for an item by itself than the specification of a single C data type according to this attempt for a property comparison.
Quoted 4 lines
Quoted 2 lines
We would like to achieve source code transformations which can be compiled (or not).
No idea what you mean by compiled.
I wonder about such a feedback.
Quoted 1 line
Compiled by what compiler?
You can choose an appropriate program, can't you?
Quoted 3 lines
Quoted 1 line
How often will it matter then how these selections will be applied?
What selections?
The source code will be filtered according to the specified metavariables.
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci