All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Error predicate determination with SmPL?
@ 2015-07-13  7:19 SF Markus Elfring
  2015-07-13 10:55 ` SF Markus Elfring
  0 siblings, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13  7:19 UTC (permalink / raw)
  To: cocci

Hello,

The semantic patch language can also be used to find
specific return statements in the source files.
How can this software help to find all of them
within a function implementation?

How are the chances to improve static source code analysis
possibilities for such a purpose?

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13  7:19 [Cocci] Error predicate determination with SmPL? SF Markus Elfring
@ 2015-07-13 10:55 ` SF Markus Elfring
  2015-07-13 11:00   ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 10:55 UTC (permalink / raw)
  To: cocci

> The semantic patch language can also be used to find
> specific return statements in the source files.
> How can this software help to find all of them
> within a function implementation?
> 
> How are the chances to improve static source code analysis
> possibilities for such a purpose?

A simple SmPL filter approach like the following works
already as expected to some degree.

@returns@
expression express;
identifier work;
type return_type;
@@
 return_type work(...)
 {
  ... when any
- return express;
  ... when any
 }


elfring at Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -sp-file show_returns1.cocci API-test1.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
HANDLING: API-test1.c
diff = 
--- API-test1.c
+++ /tmp/cocci-output-6241-92ed9e-API-test1.c
@@ -2,10 +2,8 @@
 
 int my_status(void)
 {
-  return 1;
 }
 
 int main(void)
 {
-  return my_status();
 }


I see further software development challenges here.

1. Do I need to specify a SmPL constraint like "non-void"
   for such a script?

2. The expression which is used for a specific return statement
   can be assigned to a SmPL metavariable in an other script variant.
   I would appreciate if I could process the extracted data
   in a more structured way somehow.

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 10:55 ` SF Markus Elfring
@ 2015-07-13 11:00   ` Julia Lawall
  2015-07-13 11:14     ` SF Markus Elfring
  2015-07-13 16:19     ` [Cocci] Error predicate determination with SmPL? SF Markus Elfring
  0 siblings, 2 replies; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 11:00 UTC (permalink / raw)
  To: cocci

On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > The semantic patch language can also be used to find
> > specific return statements in the source files.
> > How can this software help to find all of them
> > within a function implementation?
> >
> > How are the chances to improve static source code analysis
> > possibilities for such a purpose?
>
> A simple SmPL filter approach like the following works
> already as expected to some degree.
>
> @returns@
> expression express;
> identifier work;
> type return_type;
> @@
>  return_type work(...)
>  {
>   ... when any
> - return express;

The when any's are not needed.  ... follows the control flow, so there is
nothing after a return.

>   ... when any
>  }
>
>
> elfring at Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -sp-file show_returns1.cocci API-test1.c
> init_defs_builtins: /usr/local/lib/coccinelle/standard.h
> HANDLING: API-test1.c
> diff =
> --- API-test1.c
> +++ /tmp/cocci-output-6241-92ed9e-API-test1.c
> @@ -2,10 +2,8 @@
>
>  int my_status(void)
>  {
> -  return 1;
>  }
>
>  int main(void)
>  {
> -  return my_status();
>  }
>
>
> I see further software development challenges here.
>
> 1. Do I need to specify a SmPL constraint like "non-void"
>    for such a script?

It seems pointless.  If the code is returning something and the return
type is void, then the problem is elsewhere.

> 2. The expression which is used for a specific return statement
>    can be assigned to a SmPL metavariable in an other script variant.
>    I would appreciate if I could process the extracted data
>    in a more structured way somehow.

I have no idea what you want to do.  You can get the AST if you write a
script using OCaml:

(stringrep,astrep) << r.express;

julia

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 11:00   ` Julia Lawall
@ 2015-07-13 11:14     ` SF Markus Elfring
  2015-07-13 11:46       ` Julia Lawall
  2015-07-13 16:19     ` [Cocci] Error predicate determination with SmPL? SF Markus Elfring
  1 sibling, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 11:14 UTC (permalink / raw)
  To: cocci

>> 1. Do I need to specify a SmPL constraint like "non-void"
>>    for such a script?
> 
> It seems pointless.  If the code is returning something and the return
> type is void, then the problem is elsewhere.

A C compiler will usually will react with an error display
for this special case.
How should a static source code analysis tool deal with it?

Does the metavariable type "expression" match also to the empty string?


>> 2. The expression which is used for a specific return statement
>>    can be assigned to a SmPL metavariable in an other script variant.
>>    I would appreciate if I could process the extracted data
>>    in a more structured way somehow.
> 
> I have no idea what you want to do.  You can get the AST if you write
> a script using OCaml:
> 
> (stringrep,astrep) << r.express;

I guess that I am going to store elements into another SQL database.

How are the chances that more documentation will become available
for safe processing of corresponding abstract syntax graph instances?

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 11:14     ` SF Markus Elfring
@ 2015-07-13 11:46       ` Julia Lawall
  2015-07-13 12:01         ` SF Markus Elfring
  2015-07-13 13:00         ` [Cocci] Data processing for expression ASTs SF Markus Elfring
  0 siblings, 2 replies; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 11:46 UTC (permalink / raw)
  To: cocci

On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> >> 1. Do I need to specify a SmPL constraint like "non-void"
> >>    for such a script?
> >
> > It seems pointless.  If the code is returning something and the return
> > type is void, then the problem is elsewhere.
>
> A C compiler will usually will react with an error display
> for this special case.
> How should a static source code analysis tool deal with it?

Ignore it.  Unless your goal is to check for this specific error.

> Does the metavariable type "expression" match also to the empty string?

No.

>
> >> 2. The expression which is used for a specific return statement
> >>    can be assigned to a SmPL metavariable in an other script variant.
> >>    I would appreciate if I could process the extracted data
> >>    in a more structured way somehow.
> >
> > I have no idea what you want to do.  You can get the AST if you write
> > a script using OCaml:
> >
> > (stringrep,astrep) << r.express;
>
> I guess that I am going to store elements into another SQL database.
>
> How are the chances that more documentation will become available
> for safe processing of corresponding abstract syntax graph instances?

About the same as the chance that a user who wants the documentation will
write it.  I have no plans to do so.  In general, if you know enough OCaml
to use the abstract syntax tree, you also know enough OCaml to figure out
what it is from the source code.  Everything is defined in
parsing_c/ast_c.ml.

julia

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 11:46       ` Julia Lawall
@ 2015-07-13 12:01         ` SF Markus Elfring
  2015-07-13 13:00         ` [Cocci] Data processing for expression ASTs SF Markus Elfring
  1 sibling, 0 replies; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 12:01 UTC (permalink / raw)
  To: cocci

>> Does the metavariable type "expression" match also to the empty string?
> 
> No.

Thanks for your clarification.

I hope then that the shown specification of the SmPL variable will be
sufficient for a while to search for function implementations with
a non-void return type.


>> How are the chances that more documentation will become available
>> for safe processing of corresponding abstract syntax graph instances?
> 
> About the same as the chance that a user who wants the documentation will
> write it.  I have no plans to do so.  In general, if you know enough OCaml
> to use the abstract syntax tree, you also know enough OCaml to figure out
> what it is from the source code.  Everything is defined in
> parsing_c/ast_c.ml.

I would find it nice if a data structure representation will evolve
which is more independent from specific programming languages.

Regards,
Markus

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

* [Cocci] Data processing for expression ASTs
  2015-07-13 11:46       ` Julia Lawall
  2015-07-13 12:01         ` SF Markus Elfring
@ 2015-07-13 13:00         ` SF Markus Elfring
  1 sibling, 0 replies; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 13:00 UTC (permalink / raw)
  To: cocci

>> How are the chances that more documentation will become available
>> for safe processing of corresponding abstract syntax graph instances?
> 
> About the same as the chance that a user who wants the documentation will
> write it.  I have no plans to do so.  In general, if you know enough OCaml
> to use the abstract syntax tree, you also know enough OCaml to figure out
> what it is from the source code.  Everything is defined in
> parsing_c/ast_c.ml.

Does this "tree" data structure correspond to the complete input from
the source file?

I imagine that a special mapping for expression data should be sufficient
for the discussed SmPL metavariable, shouldn' it?

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 11:00   ` Julia Lawall
  2015-07-13 11:14     ` SF Markus Elfring
@ 2015-07-13 16:19     ` SF Markus Elfring
  2015-07-13 17:02       ` Julia Lawall
  1 sibling, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 16:19 UTC (permalink / raw)
  To: cocci

> You can get the AST if you write a script using OCaml:
> 
> (stringrep,astrep) << r.express;

I try to get another small SmPL experiment like the following running.

@initialize:ocaml@
@@
let show_positions f_name typ name_places ex_string ex_ASG e_places =
(* First loop? *)
Printf.printf "%s|%s\n" f_name typ;
(* Second loop? *)
Printf.printf "%s\n" ex_string

@returns@
expression express;
identifier work;
position e_pos, name_pos;
type return_type;
@@
 return_type work at name_pos(...)
 {
  ...
  return express at e_pos;
  ...
 }

@script:ocaml display depends on returns@
f_name << returns.work;
typ << returns.return_type;
(ex_string,ex_ASG) << returns.express;
e_places << returns.e_pos;
name_places << returns.name_pos;
@@
show_positions f_name typ name_places ex_string ex_ASG e_places


elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -sp-file show_returns2.cocci API-test1.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
Using native version of ocamlc/ocamlopt/ocamldep
ocamlopt.opt -shared -o /tmp/ocaml_cocci_368f40.cmxs -g -I /usr/lib64/ocaml  -I /usr/local/lib/coccinelle/ocaml /tmp/ocaml_cocci_368f40.ml
File "/tmp/ocaml_cocci_368f40.ml", line 15, characters 6-36:
Error: Unbound value Iteration.add_pending_instance
Fatal error: exception Yes_prepare_ocamlcocci.CompileFailure("/tmp/ocaml_cocci_368f40.ml")


Can you better explain the shown error messages than me?

Does my OCaml approach contain mistakes?

How can your software library help with pretty-printing of the syntax graph?

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 16:19     ` [Cocci] Error predicate determination with SmPL? SF Markus Elfring
@ 2015-07-13 17:02       ` Julia Lawall
  2015-07-13 17:10         ` SF Markus Elfring
  2015-07-13 17:20         ` SF Markus Elfring
  0 siblings, 2 replies; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 17:02 UTC (permalink / raw)
  To: cocci



On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > You can get the AST if you write a script using OCaml:
> >
> > (stringrep,astrep) << r.express;
>
> I try to get another small SmPL experiment like the following running.
>
> @initialize:ocaml@
> @@
> let show_positions f_name typ name_places ex_string ex_ASG e_places =
> (* First loop? *)
> Printf.printf "%s|%s\n" f_name typ;
> (* Second loop? *)
> Printf.printf "%s\n" ex_string
>
> @returns@
> expression express;
> identifier work;
> position e_pos, name_pos;
> type return_type;
> @@
>  return_type work at name_pos(...)
>  {
>   ...
>   return express at e_pos;
>   ...
>  }
>
> @script:ocaml display depends on returns@
> f_name << returns.work;
> typ << returns.return_type;
> (ex_string,ex_ASG) << returns.express;
> e_places << returns.e_pos;
> name_places << returns.name_pos;
> @@
> show_positions f_name typ name_places ex_string ex_ASG e_places
>
>
> elfring at Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -sp-file show_returns2.cocci API-test1.c
> init_defs_builtins: /usr/local/lib/coccinelle/standard.h
> Using native version of ocamlc/ocamlopt/ocamldep
> ocamlopt.opt -shared -o /tmp/ocaml_cocci_368f40.cmxs -g -I /usr/lib64/ocaml  -I /usr/local/lib/coccinelle/ocaml /tmp/ocaml_cocci_368f40.ml
> File "/tmp/ocaml_cocci_368f40.ml", line 15, characters 6-36:
> Error: Unbound value Iteration.add_pending_instance
> Fatal error: exception Yes_prepare_ocamlcocci.CompileFailure("/tmp/ocaml_cocci_368f40.ml")
>
>
> Can you better explain the shown error messages than me?
>
> Does my OCaml approach contain mistakes?

It looks like there is a problem with your installation of coccinelle.
Perhaps you have a quite old version of ocaml?

> How can your software library help with pretty-printing of the syntax graph?

All it offers is the string version that is already available in the
metavariable,

julia

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 17:02       ` Julia Lawall
@ 2015-07-13 17:10         ` SF Markus Elfring
  2015-07-13 17:20         ` SF Markus Elfring
  1 sibling, 0 replies; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 17:10 UTC (permalink / raw)
  To: cocci

> It looks like there is a problem with your installation of coccinelle.
> Perhaps you have a quite old version of ocaml?

I hope not ?

elfring at Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -version
spatch version 1.0.1 with Python support and with PCRE support

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 17:02       ` Julia Lawall
  2015-07-13 17:10         ` SF Markus Elfring
@ 2015-07-13 17:20         ` SF Markus Elfring
  2015-07-13 17:24           ` Julia Lawall
  1 sibling, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 17:20 UTC (permalink / raw)
  To: cocci

> Perhaps you have a quite old version of ocaml?

Is the software "OCaml 4.02.1-1.2" recent enough?

Regards,
Markus

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

* [Cocci] Error predicate determination with SmPL?
  2015-07-13 17:20         ` SF Markus Elfring
@ 2015-07-13 17:24           ` Julia Lawall
  2015-07-13 17:39             ` [Cocci] Checking of OCaml functionality SF Markus Elfring
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 17:24 UTC (permalink / raw)
  To: cocci



On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > Perhaps you have a quite old version of ocaml?
>
> Is the software "OCaml 4.02.1-1.2" recent enough?

Yes, the version seems fine.  It seems that you are not getting the proper
dynamic linking with ocaml.  Perhaps send the result of running configure.

julia

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 17:24           ` Julia Lawall
@ 2015-07-13 17:39             ` SF Markus Elfring
  2015-07-13 17:48               ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 17:39 UTC (permalink / raw)
  To: cocci

> It seems that you are not getting the proper dynamic linking
> with ocaml.

Do you know a small test to check this aspect better?


> Perhaps send the result of running configure.

What do you hope to see there?

Regards,
Markus

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 17:39             ` [Cocci] Checking of OCaml functionality SF Markus Elfring
@ 2015-07-13 17:48               ` Julia Lawall
  2015-07-13 18:03                 ` SF Markus Elfring
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 17:48 UTC (permalink / raw)
  To: cocci



On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > It seems that you are not getting the proper dynamic linking
> > with ocaml.
>
> Do you know a small test to check this aspect better?

No.  Your test is already as small as it can be.

> > Perhaps send the result of running configure.
>
> What do you hope to see there?

I would do a diff with my configuration and see if there is anything
different with respect to ocaml.

julia

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 17:48               ` Julia Lawall
@ 2015-07-13 18:03                 ` SF Markus Elfring
  2015-07-13 18:07                   ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 18:03 UTC (permalink / raw)
  To: cocci

> I would do a diff with my configuration and see if there is anything
> different with respect to ocaml.

The software "OCaml 4.02.1-1.2" was provided by a RPM package
from my Linux distribution.
https://build.opensuse.org/package/show?project=openSUSE%3AFactory&package=ocaml


Your tool "spatch 1.0.1" was built on my own here.

Where do you imagine to find interesting differences?

Regards,
Markus

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 18:03                 ` SF Markus Elfring
@ 2015-07-13 18:07                   ` Julia Lawall
  2015-07-13 18:11                     ` SF Markus Elfring
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 18:07 UTC (permalink / raw)
  To: cocci



On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > I would do a diff with my configuration and see if there is anything
> > different with respect to ocaml.
>
> The software "OCaml 4.02.1-1.2" was provided by a RPM package
> from my Linux distribution.
> https://build.opensuse.org/package/show?project=openSUSE%3AFactory&package=ocaml
>
>
> Your tool "spatch 1.0.1" was built on my own here.
>
> Where do you imagine to find interesting differences?

I asked about the output of the configure program.  The software can be
fine, but it will not do the right thing if it is configured properly.

julia

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 18:07                   ` Julia Lawall
@ 2015-07-13 18:11                     ` SF Markus Elfring
  2015-07-13 18:15                       ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: SF Markus Elfring @ 2015-07-13 18:11 UTC (permalink / raw)
  To: cocci

> I asked about the output of the configure program.

Do you refer to the log from Coccinelle's shell
script "configure" here?

Regards,
Markus

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

* [Cocci] Checking of OCaml functionality
  2015-07-13 18:11                     ` SF Markus Elfring
@ 2015-07-13 18:15                       ` Julia Lawall
  0 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-07-13 18:15 UTC (permalink / raw)
  To: cocci



On Mon, 13 Jul 2015, SF Markus Elfring wrote:

> > I asked about the output of the configure program.
>
> Do you refer to the log from Coccinelle's shell
> script "configure" here?

Yes.

julia

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

end of thread, other threads:[~2015-07-13 18:15 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-13  7:19 [Cocci] Error predicate determination with SmPL? SF Markus Elfring
2015-07-13 10:55 ` SF Markus Elfring
2015-07-13 11:00   ` Julia Lawall
2015-07-13 11:14     ` SF Markus Elfring
2015-07-13 11:46       ` Julia Lawall
2015-07-13 12:01         ` SF Markus Elfring
2015-07-13 13:00         ` [Cocci] Data processing for expression ASTs SF Markus Elfring
2015-07-13 16:19     ` [Cocci] Error predicate determination with SmPL? SF Markus Elfring
2015-07-13 17:02       ` Julia Lawall
2015-07-13 17:10         ` SF Markus Elfring
2015-07-13 17:20         ` SF Markus Elfring
2015-07-13 17:24           ` Julia Lawall
2015-07-13 17:39             ` [Cocci] Checking of OCaml functionality SF Markus Elfring
2015-07-13 17:48               ` Julia Lawall
2015-07-13 18:03                 ` SF Markus Elfring
2015-07-13 18:07                   ` Julia Lawall
2015-07-13 18:11                     ` SF Markus Elfring
2015-07-13 18:15                       ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.