Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Checking exception handling implementations with SmPL
@ 2017-05-14 15:41 SF Markus Elfring
  2017-05-18 13:00 ` [Cocci] Checking source code (including optional parts) " SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-14 15:41 UTC (permalink / raw)
  To: cocci

Hello,

I would like to check the implementation of exception handling in various
source files. The following script for the semantic patch language tries to
express a few possibilities for such a source code search pattern.


@show_special_reactions@
expression error_code, var;
identifier action =~ "^(?:malloc|strdup)$",
           no_return =~ "[Aa]bort",
           label;
statement es;
@@
 var = action(...);
 if (failed(var))
 {
(
*   return error_code;
|
*   goto label;
|
*   no_return();
)
 }
 else
 es


I find this approach too simple and therefore incomplete. Three well-known
reactions are shown. But there can be more source code before these statements
like further function calls and variable assignments.
We do eventually not know the extra code there and it can also be
generally optional.

How can the Coccinelle software help any more in such an use case?

Regards,
Markus

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

* [Cocci] Checking source code (including optional parts) with SmPL
  2017-05-14 15:41 [Cocci] Checking exception handling implementations with SmPL SF Markus Elfring
@ 2017-05-18 13:00 ` SF Markus Elfring
  2017-05-18 15:21 ` [Cocci] Safe determination of function properties for SmPL scripts SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-18 13:00 UTC (permalink / raw)
  To: cocci

I would like to clarify the possibilities for corresponding software extensions
a bit more.
The Coccinelle software provides also the search operator ?question mark? which
denotes code on a specific line as optional.
https://github.com/coccinelle/coccinelle/blob/9b5e00862900b0daadf1819a6894d31544a3ba34/docs/manual/cocci_syntax.tex#L1067

The scope of the special code there is only the marked line so that I see some
software development challenges to pack desired search filters into one line.

* How often do you check the handling for optional parts?

  - Do you find it relevant to check for the assignment of an error code to an
    other variable?

  - Are special constraints needed for additional function calls?


* How are the chances to improve readability and maintainability for SmPL code?

Regards,
Markus

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

* [Cocci] Safe determination of function properties for SmPL scripts
  2017-05-14 15:41 [Cocci] Checking exception handling implementations with SmPL SF Markus Elfring
  2017-05-18 13:00 ` [Cocci] Checking source code (including optional parts) " SF Markus Elfring
@ 2017-05-18 15:21 ` SF Markus Elfring
  2017-05-18 16:00 ` [Cocci] Checking failure predicates with SmPL SF Markus Elfring
  2017-05-23  9:01 ` [Cocci] Easier search for assignment targets " SF Markus Elfring
  3 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-18 15:21 UTC (permalink / raw)
  To: cocci

> How can the Coccinelle software help any more in such an use case?

This small SmPL script example demonstrates two special selections of functions
by their name. They belong to separate categories then.

* The primary actions should usually provide a return value somehow.

* A call of a function which will not return from its final task is one
  possibility for an error reaction.


Have you got any preferences for the determination and integration of name lists
for functions with the desired properties into the semantic patch language
in a safe way?

Would you dare to query a database table (or view) for such a purpose?

Regards,
Markus

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

* [Cocci] Checking failure predicates with SmPL
  2017-05-14 15:41 [Cocci] Checking exception handling implementations with SmPL SF Markus Elfring
  2017-05-18 13:00 ` [Cocci] Checking source code (including optional parts) " SF Markus Elfring
  2017-05-18 15:21 ` [Cocci] Safe determination of function properties for SmPL scripts SF Markus Elfring
@ 2017-05-18 16:00 ` SF Markus Elfring
  2017-05-23  9:01 ` [Cocci] Easier search for assignment targets " SF Markus Elfring
  3 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-18 16:00 UTC (permalink / raw)
  To: cocci

>  var = action(...);
>  if (failed(var))

This SmPL specification contains a few further software development challenges.

1. It could be taken into account that a function call and a corresponding check
   for the return value are not directly next to each other.
   A SmPL ellipsis could be added there. But I guess that special restrictions
   will be needed then for a safe ?when specification?.

2. The check which should appropriately be performed for a return code depends
   on the called function.
   * Each failure predicate could be written as a separate SmPL rule.
     This approach would result into code duplication to some degree.

   * I would prefer to keep the selection and data processing for the desired
     predicate at a single place. But I am unsure so far how good such a variant
     is supported by the current Coccinelle software.

Regards,
Markus

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

* [Cocci] Easier search for assignment targets with SmPL
  2017-05-14 15:41 [Cocci] Checking exception handling implementations with SmPL SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-05-18 16:00 ` [Cocci] Checking failure predicates with SmPL SF Markus Elfring
@ 2017-05-23  9:01 ` SF Markus Elfring
  2017-05-23  9:06   ` Julia Lawall
  3 siblings, 1 reply; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23  9:01 UTC (permalink / raw)
  To: cocci

>  var = action(...);

This specification looks also simple for the semantic patch language
at first glance.
I tried to express that a specific value is assigned to something.
But this ?something? could be a different item depending on the position
in the source code.

1. Variable
2. Expression
3. Element for a designated initialiser

I would appreciate if I do not need to repeat specifications for these cases
in SmPL code. How do you think about the possibility to support the desired
source code search by an additional metavariable type there?
Can it become safer and more convenient to handle assignments here?

Regards,
Markus

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

* [Cocci] Easier search for assignment targets with SmPL
  2017-05-23  9:01 ` [Cocci] Easier search for assignment targets " SF Markus Elfring
@ 2017-05-23  9:06   ` Julia Lawall
  2017-05-23 10:52     ` SF Markus Elfring
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2017-05-23  9:06 UTC (permalink / raw)
  To: cocci



On Tue, 23 May 2017, SF Markus Elfring wrote:

> >  var = action(...);
>
> This specification looks also simple for the semantic patch language
> at first glance.
> I tried to express that a specific value is assigned to something.
> But this ?something? could be a different item depending on the position
> in the source code.
>
> 1. Variable
> 2. Expression
> 3. Element for a designated initialiser
>
> I would appreciate if I do not need to repeat specifications for these cases
> in SmPL code. How do you think about the possibility to support the desired
> source code search by an additional metavariable type there?
> Can it become safer and more convenient to handle assignments here?

I have no idea what you are asking for.  In any case, an expression
metavariable already matches a variable.  I don't know what a designated
initializer is.

julia

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

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

* [Cocci] Easier search for assignment targets with SmPL
  2017-05-23  9:06   ` Julia Lawall
@ 2017-05-23 10:52     ` SF Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 10:52 UTC (permalink / raw)
  To: cocci

>> Can it become safer and more convenient to handle assignments here?
> 
> I have no idea what you are asking for.

I wonder about such a kind of feedback.


> In any case, an expression metavariable already matches a variable.

This information can be appropriate in some source code situations.

Do you care for any more ?special use cases??


> I don't know what a designated initializer is.

I find this aspect strange when it was already discussed several times.
http://en.cppreference.com/w/c/language/struct_initialization

How would you prefer to handle various software development challenges around
specifications for variable definitions?

Regards,
Markus

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

end of thread, other threads:[~2017-05-23 10:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-14 15:41 [Cocci] Checking exception handling implementations with SmPL SF Markus Elfring
2017-05-18 13:00 ` [Cocci] Checking source code (including optional parts) " SF Markus Elfring
2017-05-18 15:21 ` [Cocci] Safe determination of function properties for SmPL scripts SF Markus Elfring
2017-05-18 16:00 ` [Cocci] Checking failure predicates with SmPL SF Markus Elfring
2017-05-23  9:01 ` [Cocci] Easier search for assignment targets " SF Markus Elfring
2017-05-23  9:06   ` Julia Lawall
2017-05-23 10:52     ` SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox