Re: [Cocci] Using a macro for variable attributes

2020-04-28 Thread Paul Chaignon
On Tue, Apr 28, 2020 at 08:41:08PM +0200, Julia Lawall wrote:
> 
> 
> On Tue, 28 Apr 2020, Paul Chaignon wrote:
> 
> > Thanks for the quick answer!
> >
> > On Tue, Apr 28, 2020 at 07:44:15PM +0200, Julia Lawall wrote:
> > >
> > >
> > > On Tue, 28 Apr 2020, Paul Chaignon wrote:
> > >
> > > > Hi all,
> > > >
> > > > I am working on a small semantic patch to annotate specific variables in
> > > > our codebase with __attribute__((aligned(8))). The following program 
> > > > works
> > > > fine.
> > > >
> > > >   @r@
> > > >   expression e1, e2;
> > > >   identifier x;
> > > >   @@
> > > >   (
> > > > struct \(icmphdr\|icmp6hdr\) x
> > > >   + __attribute__((aligned(8)))
> > > > ;
> > > >   |
> > > > struct \(icmphdr\|icmp6hdr\) x
> > > >   + __attribute__((aligned(8)))
> > > > = ...;
> > > >   )
> > > > ... when exists
> > > > ctx_load_bytes(e1, e2, , ...)
> > > >
> > > > However, when I replace __attribute__((aligned(8))) with our internal
> > > > macro __align_stack_8, it fails with the following error:
> > > >
> > > >   plus: parse error:
> > > > File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, 
> > > > column 2, charpos = 77
> > > > around = '__align_stack_8',
> > > > whole content = + __align_stack_8
> > > >
> > > > I've tried adding '#define __align_stack_8' in a file passed with
> > > > --macro-file, without success. Is this a known limitation for macros or
> > > > am I missing something?
> > >
> > > Try adding the "metavariable" declaration:
> > >
> > > attribute name __align_stack_8;
> >
> > Awesome, that worked. And I think I understand: undeclared identifiers are 
> > by
> > default considered symbols, leading to the parse error.
> >
> > Unfortunately, my semantic patch now leads to the following changes:
> >
> >   - struct icmphdr icmphdr __align_stack_8;
> >   + struct icmphdr icmphdr __align_stack_8 __align_stack_8;
> >
> > I would normally add a first case to my conjunction to match on
> > already-present attributes, but Coccinelle can't match on attributes yet.
> > Any workaround?
> 
> Jaskaran is working on it.

Great! I'll keep a watch on new releases :-)

> A hackish solution would be to put a position variable on the variable
> name and put a position variable on the ; and then use python to see if
> they are not adjacent to each other...
> 
> Do you get a lot of occurrences of the problem?  In the short term it
> could be simpler to just clean it up by hand.  It should be easy to search
> for at least.

We don't have a lot of variables that need this annotation overall, but
I'm hoping to run the semantic patch as part of our CI pipeline.

In the medium term, I think I can just keep my current version (as above
but extended with positions and a Python error message). Because it
doesn't try to add missing attributes, it doesn't need the attribute name
and doesn't have the double annotation problem.

Thanks a lot for your help!

Cheers,
Paul

> 
> julia
> 
> 
> >
> > Paul
> >
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Using a macro for variable attributes

2020-04-28 Thread Julia Lawall



On Tue, 28 Apr 2020, Paul Chaignon wrote:

> Thanks for the quick answer!
>
> On Tue, Apr 28, 2020 at 07:44:15PM +0200, Julia Lawall wrote:
> >
> >
> > On Tue, 28 Apr 2020, Paul Chaignon wrote:
> >
> > > Hi all,
> > >
> > > I am working on a small semantic patch to annotate specific variables in
> > > our codebase with __attribute__((aligned(8))). The following program works
> > > fine.
> > >
> > >   @r@
> > >   expression e1, e2;
> > >   identifier x;
> > >   @@
> > >   (
> > > struct \(icmphdr\|icmp6hdr\) x
> > >   + __attribute__((aligned(8)))
> > > ;
> > >   |
> > > struct \(icmphdr\|icmp6hdr\) x
> > >   + __attribute__((aligned(8)))
> > > = ...;
> > >   )
> > > ... when exists
> > > ctx_load_bytes(e1, e2, , ...)
> > >
> > > However, when I replace __attribute__((aligned(8))) with our internal
> > > macro __align_stack_8, it fails with the following error:
> > >
> > >   plus: parse error:
> > > File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, 
> > > column 2, charpos = 77
> > > around = '__align_stack_8',
> > > whole content = + __align_stack_8
> > >
> > > I've tried adding '#define __align_stack_8' in a file passed with
> > > --macro-file, without success. Is this a known limitation for macros or
> > > am I missing something?
> >
> > Try adding the "metavariable" declaration:
> >
> > attribute name __align_stack_8;
>
> Awesome, that worked. And I think I understand: undeclared identifiers are by
> default considered symbols, leading to the parse error.
>
> Unfortunately, my semantic patch now leads to the following changes:
>
>   -   struct icmphdr icmphdr __align_stack_8;
>   +   struct icmphdr icmphdr __align_stack_8 __align_stack_8;
>
> I would normally add a first case to my conjunction to match on
> already-present attributes, but Coccinelle can't match on attributes yet.
> Any workaround?

Jaskaran is working on it.

A hackish solution would be to put a position variable on the variable
name and put a position variable on the ; and then use python to see if
they are not adjacent to each other...

Do you get a lot of occurrences of the problem?  In the short term it
could be simpler to just clean it up by hand.  It should be easy to search
for at least.

julia


>
> Paul
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Using a macro for variable attributes

2020-04-28 Thread Paul Chaignon
Thanks for the quick answer!

On Tue, Apr 28, 2020 at 07:44:15PM +0200, Julia Lawall wrote:
> 
> 
> On Tue, 28 Apr 2020, Paul Chaignon wrote:
> 
> > Hi all,
> >
> > I am working on a small semantic patch to annotate specific variables in
> > our codebase with __attribute__((aligned(8))). The following program works
> > fine.
> >
> >   @r@
> >   expression e1, e2;
> >   identifier x;
> >   @@
> >   (
> > struct \(icmphdr\|icmp6hdr\) x
> >   + __attribute__((aligned(8)))
> > ;
> >   |
> > struct \(icmphdr\|icmp6hdr\) x
> >   + __attribute__((aligned(8)))
> > = ...;
> >   )
> > ... when exists
> > ctx_load_bytes(e1, e2, , ...)
> >
> > However, when I replace __attribute__((aligned(8))) with our internal
> > macro __align_stack_8, it fails with the following error:
> >
> >   plus: parse error:
> > File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, 
> > column 2, charpos = 77
> > around = '__align_stack_8',
> > whole content = + __align_stack_8
> >
> > I've tried adding '#define __align_stack_8' in a file passed with
> > --macro-file, without success. Is this a known limitation for macros or
> > am I missing something?
> 
> Try adding the "metavariable" declaration:
> 
> attribute name __align_stack_8;

Awesome, that worked. And I think I understand: undeclared identifiers are by
default considered symbols, leading to the parse error.

Unfortunately, my semantic patch now leads to the following changes:

  - struct icmphdr icmphdr __align_stack_8;
  + struct icmphdr icmphdr __align_stack_8 __align_stack_8;

I would normally add a first case to my conjunction to match on
already-present attributes, but Coccinelle can't match on attributes yet.
Any workaround?

Paul
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Using a macro for variable attributes

2020-04-28 Thread Julia Lawall



On Tue, 28 Apr 2020, Paul Chaignon wrote:

> Hi all,
>
> I am working on a small semantic patch to annotate specific variables in
> our codebase with __attribute__((aligned(8))). The following program works
> fine.
>
>   @r@
>   expression e1, e2;
>   identifier x;
>   @@
>   (
> struct \(icmphdr\|icmp6hdr\) x
>   + __attribute__((aligned(8)))
> ;
>   |
> struct \(icmphdr\|icmp6hdr\) x
>   + __attribute__((aligned(8)))
> = ...;
>   )
> ... when exists
> ctx_load_bytes(e1, e2, , ...)
>
> However, when I replace __attribute__((aligned(8))) with our internal
> macro __align_stack_8, it fails with the following error:
>
>   plus: parse error:
> File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, column 
> 2, charpos = 77
> around = '__align_stack_8',
> whole content = + __align_stack_8
>
> I've tried adding '#define __align_stack_8' in a file passed with
> --macro-file, without success. Is this a known limitation for macros or
> am I missing something?

Try adding the "metavariable" declaration:

attribute name __align_stack_8;

julia

>
> Thanks,
> Paul
> ___
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] console: Complete exception handling in newport_probe()

2020-04-28 Thread Dejin Zheng
On Thu, Apr 23, 2020 at 05:23:29PM +0200, Markus Elfring wrote:
> >> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/scripts/coccinelle/free/iounmap.cocci
> >>
> >> How do you think about to extend presented software analysis approaches?
> >>
> > Sorry, I am not familiar with it, I don't know.
> 
> Do you find the comments helpful at the beginning of this SmPL script?
>
Sorry, I do not know how to use the SmPL script. 

> Would you like to let any more source code analysis tools help you
> to find remaining update candidates?
>
yes, but I think the source code analysis tools only can found the simple
repetitive issue. and need spend some time learning to use it. at different
stages, it should have different methods for me. now, I think the best for
me may be that read and check the source code. Thanks!

BR,
Dejin

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


Re: [Cocci] [PATCH v1] console: fix an issue about ioremap leak.

2020-04-28 Thread Dejin Zheng
On Thu, Apr 23, 2020 at 01:10:14PM +0200, Markus Elfring wrote:
> > if do_take_over_console() return an error in the newport_probe(),
> > due to the io virtual address is not released, it will cause a leak.
> 
> How do you think about a wording variant like the following?
> 
>Subject:
>[PATCH v2] console: Complete exception handling in newport_probe()
> 
>Change description:
>A call of the function “do_take_over_console” can fail here.
>The corresponding system resources were not released then.
>Thus add a call of the function “iounmap” together with the check
>of a failure predicate.
>
Thanks!

> 
> I would like to point out that there is a script for the semantic
> patch language which would detect other questionable source code.
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/scripts/coccinelle/free/iounmap.cocci
> 
> How do you think about to extend presented software analysis approaches?
>
Sorry, I am not familiar with it, I don't know.

BR,
Dejin

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


[Cocci] Using a macro for variable attributes

2020-04-28 Thread Paul Chaignon
Hi all,

I am working on a small semantic patch to annotate specific variables in
our codebase with __attribute__((aligned(8))). The following program works
fine.

  @r@
  expression e1, e2;
  identifier x;
  @@
  (
struct \(icmphdr\|icmp6hdr\) x
  + __attribute__((aligned(8)))
;
  |
struct \(icmphdr\|icmp6hdr\) x
  + __attribute__((aligned(8)))
= ...;
  )
... when exists
ctx_load_bytes(e1, e2, , ...)

However, when I replace __attribute__((aligned(8))) with our internal
macro __align_stack_8, it fails with the following error:

  plus: parse error:
File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, column 
2, charpos = 77
around = '__align_stack_8',
whole content = + __align_stack_8

I've tried adding '#define __align_stack_8' in a file passed with
--macro-file, without success. Is this a known limitation for macros or
am I missing something?

Thanks,
Paul
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 02/32] parsing_cocci: ast0_cocci: Add cast attributes

2020-04-28 Thread Jaskaran Singh
Add cast attributes to AST0 of SmPL. This is a list of attributes in the
Cast type of AST0.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0_cocci.ml  | 4 ++--
 parsing_cocci/ast0_cocci.mli | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index a06d99ae..b65400be 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -123,8 +123,8 @@ and base_expression =
  string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast   of string mcode (* ( *) * typeC * string mcode (* ) *) *
-  expression
+  | Cast   of string mcode (* ( *) * typeC * attr list *
+  string mcode (* ) *) * expression
   | SizeOfExpr of string mcode (* sizeof *) * expression
   | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
   typeC * string mcode (* ) *)
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 5c2520be..08a4b33b 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -114,8 +114,8 @@ and base_expression =
  string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast   of string mcode (* ( *) * typeC * string mcode (* ) *) *
-  expression
+  | Cast   of string mcode (* ( *) * typeC * attr list *
+  string mcode (* ) *) * expression
   | SizeOfExpr of string mcode (* sizeof *) * expression
   | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
   typeC * string mcode (* ) *)
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 26/32] engine: check_exhaustive_pattern: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
check_exhaustive_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/check_exhaustive_pattern.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/engine/check_exhaustive_pattern.ml 
b/engine/check_exhaustive_pattern.ml
index 903c32ff..d7785fc7 100644
--- a/engine/check_exhaustive_pattern.ml
+++ b/engine/check_exhaustive_pattern.ml
@@ -123,7 +123,7 @@ let dumb_astcocci_expr = function
  | A.ArrayAccess (ea1, _, ea2, _) -> ()
  | A.RecordAccess (ea, _, ida) -> ()
  | A.RecordPtAccess (ea, _, ida) -> ()
- | A.Cast (_, typa, _, ea) -> ()
+ | A.Cast (_, typa, attra, _, ea) -> ()
  | A.SizeOfExpr (_, ea) -> ()
  | A.SizeOfType (_, _, typa, _) -> ()
  | A.TypeExp (typa) -> ()
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 30/32] tests: Add test case to check cast attribute allminus

2020-04-28 Thread Jaskaran Singh
Add a test case to check allminus for cast attributes. The test case
replaces all the cast types in the C program. Cases covered are for when
the attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

Signed-off-by: Jaskaran Singh 
---
 tests/remove_cast_attr_allminus.c | 10 ++
 tests/remove_cast_attr_allminus.cocci |  9 +
 tests/remove_cast_attr_allminus.res   | 10 ++
 3 files changed, 29 insertions(+)
 create mode 100644 tests/remove_cast_attr_allminus.c
 create mode 100644 tests/remove_cast_attr_allminus.cocci
 create mode 100644 tests/remove_cast_attr_allminus.res

diff --git a/tests/remove_cast_attr_allminus.c 
b/tests/remove_cast_attr_allminus.c
new file mode 100644
index ..4f6da3e4
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   int *a = (int __cast_attr) x;
+   int *a = (__cast_attr int) x;
+   int *a = (int __cast_attr *) x;
+   int *a = (int *__cast_attr) x;
+   int *a = (int) x;
+}
diff --git a/tests/remove_cast_attr_allminus.cocci 
b/tests/remove_cast_attr_allminus.cocci
new file mode 100644
index ..320fee93
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.cocci
@@ -0,0 +1,9 @@
+@r0@
+type T;
+identifier x;
+@@
+
+  (
+-  T
++  int *
+  ) x
diff --git a/tests/remove_cast_attr_allminus.res 
b/tests/remove_cast_attr_allminus.res
new file mode 100644
index ..befec630
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   int *a = (int *) x;
+   int *a = (int *) x;
+   int *a = (int *) x;
+   int *a = (int *) x;
+   int *a = (int *) x;
+}
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 32/32] tests: Add test case to detect cast attributes

2020-04-28 Thread Jaskaran Singh
Add a test case to detect a cast attribute. The following cases are
covered for when a attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

Signed-off-by: Jaskaran Singh 
---
 tests/detect_cast_attr.c | 10 ++
 tests/detect_cast_attr.cocci | 11 +++
 tests/detect_cast_attr.res   | 10 ++
 3 files changed, 31 insertions(+)
 create mode 100644 tests/detect_cast_attr.c
 create mode 100644 tests/detect_cast_attr.cocci
 create mode 100644 tests/detect_cast_attr.res

diff --git a/tests/detect_cast_attr.c b/tests/detect_cast_attr.c
new file mode 100644
index ..2458ef05
--- /dev/null
+++ b/tests/detect_cast_attr.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   char *a = (int __cast_attr) x;
+   char *a = (__cast_attr int) x;
+   char *a = (int __cast_attr *) x;
+   char *a = (int *__cast_attr) x;
+   char *a = (int) x;
+}
diff --git a/tests/detect_cast_attr.cocci b/tests/detect_cast_attr.cocci
new file mode 100644
index ..d626048f
--- /dev/null
+++ b/tests/detect_cast_attr.cocci
@@ -0,0 +1,11 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+-  T
++  char *
+   __cast_attr
+  ) x
diff --git a/tests/detect_cast_attr.res b/tests/detect_cast_attr.res
new file mode 100644
index ..2a273316
--- /dev/null
+++ b/tests/detect_cast_attr.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   char *a = (char *__cast_attr) x;
+   char *a = (__cast_attr char *) x;
+   char *a = (char *__cast_attr) x;
+   char *a = (char *__cast_attr) x;
+   char *a = (int) x;
+}
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 31/32] tests: Add test case to remove cast attributes

2020-04-28 Thread Jaskaran Singh
Add a test case to remove a cast attribute. The following cases are
covered for when a attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

Signed-off-by: Jaskaran Singh 
---
 tests/remove_cast_attr.c | 10 ++
 tests/remove_cast_attr.cocci | 10 ++
 tests/remove_cast_attr.res   | 10 ++
 3 files changed, 30 insertions(+)
 create mode 100644 tests/remove_cast_attr.c
 create mode 100644 tests/remove_cast_attr.cocci
 create mode 100644 tests/remove_cast_attr.res

diff --git a/tests/remove_cast_attr.c b/tests/remove_cast_attr.c
new file mode 100644
index ..4f6da3e4
--- /dev/null
+++ b/tests/remove_cast_attr.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   int *a = (int __cast_attr) x;
+   int *a = (__cast_attr int) x;
+   int *a = (int __cast_attr *) x;
+   int *a = (int *__cast_attr) x;
+   int *a = (int) x;
+}
diff --git a/tests/remove_cast_attr.cocci b/tests/remove_cast_attr.cocci
new file mode 100644
index ..f171d44d
--- /dev/null
+++ b/tests/remove_cast_attr.cocci
@@ -0,0 +1,10 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+   T
+-  __cast_attr
+  ) x
diff --git a/tests/remove_cast_attr.res b/tests/remove_cast_attr.res
new file mode 100644
index ..fb5001b9
--- /dev/null
+++ b/tests/remove_cast_attr.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+   int *a = (int) x;
+   int *a = (int) x;
+   int *a = (int *) x;
+   int *a = (int *) x;
+   int *a = (int) x;
+}
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 28/32] ocaml: coccilib: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the C and SmPL ASTs. Reflect these changes
in coccilib.mli.

Signed-off-by: Jaskaran Singh 
---
 ocaml/coccilib.mli | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index a305d616..0c379547 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -146,7 +146,7 @@ module Ast_c :
   | RecordPtAccess of expression * name
   | SizeOfExpr of expression
   | SizeOfType of fullType
-  | Cast of fullType * expression
+  | Cast of fullType * expression * attribute list
   | StatementExpr of compound wrap
   | Constructor of fullType * initialiser
   | ParenExpr of expression
@@ -2569,7 +2569,7 @@ module Ast_cocci :
   | ArrayAccess of expression * string mcode * expression * string mcode
   | RecordAccess of expression * string mcode * ident
   | RecordPtAccess of expression * string mcode * ident
-  | Cast of string mcode * fullType * string mcode * expression
+  | Cast of string mcode * fullType * attr list * string mcode * expression
   | SizeOfExpr of string mcode * expression
   | SizeOfType of string mcode * string mcode * fullType * string mcode
   | TypeExp of fullType
@@ -3305,7 +3305,7 @@ module Ast0_cocci :
   | ArrayAccess of expression * string mcode * expression * string mcode
   | RecordAccess of expression * string mcode * ident
   | RecordPtAccess of expression * string mcode * ident
-  | Cast of string mcode * typeC * string mcode * expression
+  | Cast of string mcode * typeC * attr list * string mcode * expression
   | SizeOfExpr of string mcode * expression
   | SizeOfType of string mcode * string mcode * typeC * string mcode
   | TypeExp of typeC
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 05/32] parsing_cocci: unparse_ast0: Reflect cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
unparse_ast0.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unparse_ast0.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index fdaf6cfa..7f554b37 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -221,8 +221,10 @@ let rec expression e =
  expression exp; mcode print_string pt; ident field
   | Ast0.RecordPtAccess(exp,ar,field) ->
  expression exp; mcode print_string ar; ident field
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
  mcode print_string_box lp; typeC ty; close_box();
+ (if not (attr = []) then print_string " ");
+ print_between (fun _ -> print_string " ") (mcode print_string) attr;
  mcode print_string rp; expression exp
   | Ast0.SizeOfExpr(szf,exp) ->
  mcode print_string szf; expression exp
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 27/32] engine: cocci_vs_c: Match Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the C and SmPL ASTs. Match these attributes
in cocci_vs_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/cocci_vs_c.ml | 24 +---
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 317fa71e..0001ec2a 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -1121,7 +1121,7 @@ let rec (expression: (A.expression, Ast_c.expression) 
matcher) =
* differentiate between different cases *)
   let rec matches_id = function
  B.Ident(name) -> true
-   | B.Cast(ty,e) -> matches_id (B.unwrap_expr e)
+   | B.Cast(ty,e,a) -> matches_id (B.unwrap_expr e)
| _ -> false in
   let form_ok =
match (form,expr) with
@@ -1137,7 +1137,7 @@ let rec (expression: (A.expression, Ast_c.expression) 
matcher) =
true
   end
   else false
- | B.Cast(ty,e) -> matches (B.unwrap_expr e)
+ | B.Cast(ty,e,a) -> matches (B.unwrap_expr e)
  | B.Unary(e,B.UnMinus) -> matches (B.unwrap_expr e)
  | B.SizeOfExpr(exp) -> true
  | B.SizeOfType(ty) -> true
@@ -1525,16 +1525,26 @@ let rec (expression: (A.expression, Ast_c.expression) 
matcher) =
*by trying | ea, B.Case (typb, eb) -> match_e_e ea eb ?
*)
 
-  | A.Cast (ia1, typa, ia2, ea), ((B.Cast (typb, eb), typ),ii) ->
+  | A.Cast (ia1, typa, attrsa, ia2, ea),
+((B.Cast (typb, eb, attrsb), typ),ii) ->
+
+  let attr_allminus =
+let mcode_is_not_context = function
+  | (_,_,A.CONTEXT(_,_),_) -> false
+  | _ -> true in
+check_allminus.Visitor_ast.combiner_fullType typa &&
+List.for_all mcode_is_not_context attrsa in
+
   let (ib1, ib2) = tuple_of_list2 ii in
   fullType typa typb >>= (fun typa typb ->
+  attribute_list attr_allminus attrsa attrsb >>= (fun attrsa attrsb ->
   expression ea eb >>= (fun ea eb ->
   tokenf ia1 ib1 >>= (fun ia1 ib1 ->
   tokenf ia2 ib2 >>= (fun ia2 ib2 ->
 return (
-  ((A.Cast (ia1, typa, ia2, ea))) +> wa,
-  ((B.Cast (typb, eb),typ),[ib1;ib2])
-)
+  ((A.Cast (ia1, typa, attrsa, ia2, ea))) +> wa,
+  ((B.Cast (typb, eb, attrsb),typ),[ib1;ib2])
+))
 
   | A.SizeOfExpr (ia1, ea), ((B.SizeOfExpr (eb), typ),ii) ->
   let ib1 = tuple_of_list1 ii in
@@ -1641,7 +1651,7 @@ let rec (expression: (A.expression, Ast_c.expression) 
matcher) =
 
 
   | _,
- (((B.Cast (_, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _|
+ (((B.Cast (_, _, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _|
  B.Constructor (_, _)|
  B.RecordPtAccess (_, _)|
  B.RecordAccess (_, _)|B.ArrayAccess (_, _)|
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 24/32] parsing_c: unparse_cocci: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
unparse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_cocci.ml | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 395b3a3c..081bcdd9 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -455,7 +455,7 @@ let rec expression e =
 | Ast_c.RecordPtAccess (e, name) -> postfix
 | Ast_c.SizeOfExpr (e) -> unary
 | Ast_c.SizeOfType (t) -> unary
-| Ast_c.Cast (t, e) -> cast
+| Ast_c.Cast (t, e, a) -> cast
 | Ast_c.StatementExpr (statxs, _) -> top
 | Ast_c.Constructor (t, init) -> unary
 | Ast_c.ParenExpr (e) -> primary
@@ -503,8 +503,10 @@ let rec expression e =
   loop exp postfix; mcode print_string pt; ident field
   | Ast.RecordPtAccess(exp,ar,field) ->
   loop exp postfix; mcode print_string ar; ident field
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
   mcode print_string_box lp; fullType ty; close_box();
+  (if not (attr = []) then pr_space());
+  print_between pr_space (mcode print_string) attr;
   mcode print_string rp; loop exp cast
   | Ast.SizeOfExpr(sizeof,exp) ->
   mcode print_string sizeof; loop exp unary
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 25/32] parsing_c: visitor_c: Visit Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the C AST. Visit these attributes in
the C AST visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/visitor_c.ml | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/parsing_c/visitor_c.ml b/parsing_c/visitor_c.ml
index 57b5f32b..1a522413 100644
--- a/parsing_c/visitor_c.ml
+++ b/parsing_c/visitor_c.ml
@@ -324,7 +324,9 @@ let rec vk_expr = fun bigf expr ->
 
 | SizeOfExpr  (e) -> exprf e
 | SizeOfType  (t) -> vk_type bigf t
-| Cast(t, e) -> vk_type bigf t; exprf e
+| Cast(t, e, a) ->
+vk_type bigf t; exprf e;
+a +> List.iter (vk_attribute bigf)
 
 (* old: | StatementExpr (((declxs, statxs), is)), is2 ->
  *  List.iter (vk_decl bigf) declxs;
@@ -1188,7 +1190,11 @@ let rec vk_expr_s = fun bigf expr ->
 
   | SizeOfExpr  (e) -> SizeOfExpr (exprf e)
   | SizeOfType  (t) -> SizeOfType (vk_type_s bigf t)
-  | Cast(t, e)  -> Cast (vk_type_s bigf t, exprf e)
+  | Cast(t, e, a)  ->
+  Cast
+(vk_type_s bigf t,
+ exprf e,
+ a +> List.map (vk_attribute_s bigf))
 
   | StatementExpr (statxs, is) ->
   StatementExpr (
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 29/32] tools: spgen: Reflect Cast attrs

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
position_generator.ml.

Signed-off-by: Jaskaran Singh 
---
 tools/spgen/source/position_generator.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/spgen/source/position_generator.ml 
b/tools/spgen/source/position_generator.ml
index 757faf5f..9143a474 100644
--- a/tools/spgen/source/position_generator.ml
+++ b/tools/spgen/source/position_generator.ml
@@ -359,9 +359,9 @@ let rec expression_pos exp snp
   let c ~exp ~id = Ast0.RecordPtAccess(exp, arrow, id) in
   let alt() = id_wrap ~id ~constructor:(c ~exp) snp in
   exp_wrap ~exp ~constructor:(c ~id) ~alt snp
-  | Ast0.Cast(lp, typec, rp, exp) ->
+  | Ast0.Cast(lp, typec, attr, rp, exp) ->
   let _ = type_pos typec snp in (* sanity check for disj *)
-  let c ~exp ~mc = Ast0.Cast(lp, typec, mc, exp) in
+  let c ~exp ~mc = Ast0.Cast(lp, typec, attr, mc, exp) in
   let alt() = mcode_wrap ~mc:rp ~constructor:(c ~exp) snp in
   exp_wrap ~exp ~constructor:(c ~mc:rp) ~alt snp
   | Ast0.SizeOfExpr(sizeofmc, exp) ->
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 23/32] parsing_c: type_annoter_c: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
type_annoter_c.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/type_annoter_c.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml
index dfd363b2..c42ac5e9 100644
--- a/parsing_c/type_annoter_c.ml
+++ b/parsing_c/type_annoter_c.ml
@@ -525,7 +525,7 @@ let rec is_simple_expr expr =
   true
   | Binary (e1, op, e2) ->
   true
-  | Cast (t, e) ->
+  | Cast (t, e, a) ->
   true
   | ParenExpr (e) -> is_simple_expr e
 
@@ -961,7 +961,7 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 
 
 (* -- *)
-| Cast (t, e) ->
+| Cast (t, e, a) ->
 k expr;
 (* todo: if infer, can "push" info ? add_types_expr [t] e ? *)
 make_info_def_fix (Lib.al_type t)
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 14/32] parsing_cocci: ast_cocci: Add cast attributes

2020-04-28 Thread Jaskaran Singh
Add cast attributes to the SmPL AST. This is a list of attributes in the
Cast type of the SmPL AST.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast_cocci.ml  | 4 ++--
 parsing_cocci/ast_cocci.mli | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 9b147e5c..b0190fa1 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -194,8 +194,8 @@ and base_expression =
  string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast   of string mcode (* ( *) * fullType * string mcode (* ) *) *
-  expression
+  | Cast   of string mcode (* ( *) * fullType * attr list *
+  string mcode (* ) *) * expression
   | SizeOfExpr of string mcode (* sizeof *) * expression
   | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
   fullType * string mcode (* ) *)
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index c56bba88..ff81692c 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -178,8 +178,8 @@ and base_expression =
  string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast   of string mcode (* ( *) * fullType * string mcode (* ) *) *
-  expression
+  | Cast   of string mcode (* ( *) * fullType * attr list *
+  string mcode (* ) *) * expression
 
   | SizeOfExpr of string mcode (* sizeof *) * expression
   | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 15/32] parsing_cocci: visitor_ast: Visit cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to AST0 of SmPL. Visit these attributes in the
SmPL AST visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast.ml | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 8e530114..644bcd5d 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -198,12 +198,13 @@ let combiner bind option_default
  let lar = string_mcode ar in
  let lfield = ident field in
  multibind [lexp; lar; lfield]
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
  let llp = string_mcode lp in
  let lty = fullType ty in
+ let lattr = multibind (List.map string_mcode attr) in
  let lrp = string_mcode rp in
  let lexp = expression exp in
- multibind [llp; lty; lrp; lexp]
+  multibind [llp; lty; lattr; lrp; lexp]
   | Ast.SizeOfExpr(szf,exp) ->
  let lszf = string_mcode szf in
  let lexp = expression exp in
@@ -1184,12 +1185,13 @@ let rebuilder
let lar = string_mcode ar in
let lfield = ident field in
Ast.RecordPtAccess(lexp, lar, lfield)
-   | Ast.Cast(lp,ty,rp,exp) ->
+   | Ast.Cast(lp,ty,attr,rp,exp) ->
let llp = string_mcode lp in
let lty = fullType ty in
+   let lattr = List.map string_mcode attr in
let lrp = string_mcode rp in
let lexp = expression exp in
-   Ast.Cast(llp, lty, lrp, lexp)
+   Ast.Cast(llp, lty, lattr, lrp, lexp)
| Ast.SizeOfExpr(szf,exp) ->
let lszf = string_mcode szf in
let lexp = expression exp in
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 18/32] parsing_cocci: disjdistr: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
disjdistr.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/disjdistr.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index 6724bb25..e171e6ea 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -219,9 +219,10 @@ and disjexp e =
   | Ast.RecordPtAccess(exp,ar,field) ->
   disjmult2 (disjexp exp) (disjident field)
(fun exp field -> Ast.rewrap e (Ast.RecordPtAccess(exp,ar,field)))
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
   disjmult2 (disjty ty) (disjexp exp)
-   (function ty -> function exp -> Ast.rewrap e (Ast.Cast(lp,ty,rp,exp)))
+   (function ty -> function exp ->
+  Ast.rewrap e (Ast.Cast(lp,ty,attr,rp,exp)))
   | Ast.SizeOfExpr(szf,exp) ->
   let exp = disjexp exp in
   List.map (function exp -> Ast.rewrap e (Ast.SizeOfExpr(szf,exp))) exp
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 13/32] parsing_cocci: single_statement: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
single_statement.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/single_statement.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/single_statement.ml 
b/parsing_cocci/single_statement.ml
index 4ad1c4e4..73554e9c 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -138,7 +138,7 @@ let rec left_expression e =
   | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> left_expression exp1
   | Ast0.RecordAccess(exp,pt,field) -> left_expression exp
   | Ast0.RecordPtAccess(exp,ar,field) -> left_expression exp
-  | Ast0.Cast(lp,ty,rp,exp) -> modif_before_mcode lp
+  | Ast0.Cast(lp,ty,attr,rp,exp) -> modif_before_mcode lp
   | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf
   | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf
   | Ast0.TypeExp(ty) -> left_typeC ty
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 22/32] parsing_c: pretty_print_c: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Print these attributes in
pretty_print_c.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/pretty_print_c.ml | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
index 99a7e0ed..96a11d72 100644
--- a/parsing_c/pretty_print_c.ml
+++ b/parsing_c/pretty_print_c.ml
@@ -146,8 +146,9 @@ let mk_pretty_printers
pp_expression e
 | SizeOfType  (t), [i1;i2;i3] ->
 pr_elem i1; pr_elem i2; pp_type t; pr_elem i3
-| Cast(t, e),  [i1;i2] ->
-pr_elem i1; pp_type t; pr_elem i2; pp_expression e
+| Cast(t, e, a),  [i1;i2] ->
+pr_elem i1; pp_type t; pr_elem i2; pp_expression e;
+a +> pp_attributes pr_elem pr_space
 
 | StatementExpr (statxs, [ii1;ii2]),  [i1;i2] ->
 pr_elem i1;
@@ -184,7 +185,7 @@ let mk_pretty_printers
 | CondExpr (_,_,_) | Sequence (_,_) | Assignment (_,_,_)
 | Postfix (_,_) | Infix (_,_) | Unary (_,_) | Binary (_,_,_)
 | ArrayAccess (_,_) | RecordAccess (_,_) | RecordPtAccess (_,_)
-| SizeOfExpr (_) | SizeOfType (_) | Cast (_,_)
+| SizeOfExpr (_) | SizeOfType (_) | Cast (_,_,_)
 | StatementExpr (_) | Constructor _
 | ParenExpr (_) | New (_) | Delete (_,_)
 | Defined (_)),_ -> raise (Impossible 95)
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 19/32] parsing_cocci: unify_ast: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
unify_ast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unify_ast.ml | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index 68cb6613..25287503 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -220,8 +220,10 @@ and unify_expression e1 e2 =
   unify_expression e1 e2 && unify_ident fld1 fld2
   | (Ast.RecordPtAccess(e1,pt1,fld1),Ast.RecordPtAccess(e2,pt2,fld2)) ->
   unify_expression e1 e2 && unify_ident fld1 fld2
-  | (Ast.Cast(lp1,ty1,rp1,e1),Ast.Cast(lp2,ty2,rp2,e2)) ->
-  unify_fullType ty1 ty2 && unify_expression e1 e2
+  | (Ast.Cast(lp1,ty1,attr1,rp1,e1),Ast.Cast(lp2,ty2,attr2,rp2,e2)) ->
+  if List.for_all2 unify_mcode attr1 attr2
+  then unify_fullType ty1 ty2 && unify_expression e1 e2
+  else false
   | (Ast.SizeOfExpr(szf1,e1),Ast.SizeOfExpr(szf2,e2)) ->
   unify_expression e1 e2
   | (Ast.SizeOfType(szf1,lp1,ty1,rp1),Ast.SizeOfType(szf2,lp2,ty2,rp2)) ->
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 16/32] parsing_cocci: pretty_print_cocci: Print cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
pretty_print_cocci.ml by printing these attributes.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/pretty_print_cocci.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/pretty_print_cocci.ml 
b/parsing_cocci/pretty_print_cocci.ml
index 7628882b..2ace0b44 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -249,8 +249,10 @@ let rec expression e =
   expression exp; mcode print_string pt; ident field
   | Ast.RecordPtAccess(exp,ar,field) ->
   expression exp; mcode print_string ar; ident field
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
   mcode print_string_box lp; fullType ty; close_box();
+  (if not (attr = []) then print_string " ");
+  print_between print_space (mcode print_string) attr;
   mcode print_string rp; expression exp
   | Ast.SizeOfExpr(sizeof,exp) ->
   mcode print_string sizeof; expression exp
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 21/32] parsing_c: parser: Parse Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the C AST. Parse cast attributes in the C
parser and place them in the C AST. The attributes are taken from the
type_name rule of the C parser.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/parser_c.mly | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index 0abcc9b0..9e640ba5 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -818,7 +818,8 @@ arith_expr:
 
 cast_expr:
  | unary_expr{ $1 }
- | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] }
+ | topar2 type_name tcpar2 cast_expr
+   { mk_e(Cast (snd $2, $4, fst $2)) [$1;$3] }
 /*
 It could be useful to have the following, but there is no place for the
 attribute in the AST.
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 20/32] parsing_c: ast_c: Add Cast attributes

2020-04-28 Thread Jaskaran Singh
Add cast attributes to the C AST. This is a list of attributes in the
Cast type of the C AST.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/ast_c.ml  | 2 +-
 parsing_c/ast_c.mli | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml
index f25f9b55..6a828943 100644
--- a/parsing_c/ast_c.ml
+++ b/parsing_c/ast_c.ml
@@ -343,7 +343,7 @@ and expression = (expressionbis * exp_info ref (* semantic: 
*)) wrap3
 
   | SizeOfExpr of expression
   | SizeOfType of fullType
-  | Cast   of fullType * expression
+  | Cast   of fullType * expression * attribute list
 
   (* gccext: *)
   | StatementExpr of compound wrap (* ( ) new scope *)
diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli
index 8923a335..8a9a6f66 100644
--- a/parsing_c/ast_c.mli
+++ b/parsing_c/ast_c.mli
@@ -104,7 +104,7 @@ and expressionbis =
   | RecordPtAccess of expression * name
   | SizeOfExpr of expression
   | SizeOfType of fullType
-  | Cast of fullType * expression
+  | Cast of fullType * expression * attribute list
   | StatementExpr of compound wrap
   | Constructor of fullType * initialiser
   | ParenExpr of expression
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 17/32] parsing_cocci: ast0toast: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
ast0toast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0toast.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index 09c28c06..56f684ee 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -439,9 +439,10 @@ and expression e =
Ast.RecordAccess(expression exp,mcode pt,ident field)
 | Ast0.RecordPtAccess(exp,ar,field) ->
Ast.RecordPtAccess(expression exp,mcode ar,ident field)
-| Ast0.Cast(lp,ty,rp,exp) ->
+| Ast0.Cast(lp,ty,attr,rp,exp) ->
let allminus = check_allminus.VT0.combiner_rec_expression e in
-   Ast.Cast(mcode lp,typeC allminus ty,mcode rp,expression exp)
+   let attr = List.map mcode attr in
+   Ast.Cast(mcode lp,typeC allminus ty,attr,mcode rp,expression exp)
 | Ast0.SizeOfExpr(szf,exp) ->
Ast.SizeOfExpr(mcode szf,expression exp)
 | Ast0.SizeOfType(szf,lp,ty,rp) ->
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 06/32] parsing_cocci: index: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
index.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/index.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index f7ae48b4..a3b92c12 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -61,7 +61,7 @@ let expression e =
   | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> [27]
   | Ast0.RecordAccess(exp,pt,field) -> [28]
   | Ast0.RecordPtAccess(exp,ar,field) -> [29]
-  | Ast0.Cast(lp,ty,rp,exp) -> [30]
+  | Ast0.Cast(lp,ty,attr,rp,exp) -> [30]
   | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *)
   | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *)
   | Ast0.TypeExp(ty) -> [123] (* added after *)
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs

2020-04-28 Thread Jaskaran Singh
This patch series aims to add cast attributes to the C and SmPL ASTs, and
match them in C source code. This is a continuation of the series "cocci:
Improve C parsing of attributes"[1].

Three test cases are included:

- detect_cast_attr: Test case to detect a parameter attribute.

- remove_cast_attr: Test case to remove a parameter attribute as per the
  given SmPL.

- remove_cast_attr_allminus: Test case to replace a type in a cast and
  checking if the attribute is removed as well.

[1]https://www.mail-archive.com/cocci@systeme.lip6.fr/msg07133.html

Jaskaran Singh (32):
  parsing_c: parser: Pass attribute list from type_name
  parsing_cocci: ast0_cocci: Add cast attributes
  parsing_cocci: parser: Parse cast attributes
  parsing_cocci: visitor_ast0: Visit cast attributes
  parsing_cocci: unparse_ast0: Reflect cast attributes
  parsing_cocci: index: Reflect Cast attributes
  parsing_cocci: iso_pattern: Reflect Cast attributes
  parsing_cocci: type_infer: Reflect Cast attributes
  parsing_cocci: arity: Reflect Cast attributes
  parsing_cocci: check_meta: Reflect Cast attributes
  parsing_cocci: compute_lines: Reflect Cast attributes
  parsing_cocci: context_neg: Reflect Cast attributes
  parsing_cocci: single_statement: Reflect Cast attributes
  parsing_cocci: ast_cocci: Add cast attributes
  parsing_cocci: visitor_ast: Visit cast attributes
  parsing_cocci: pretty_print_cocci: Print cast attributes
  parsing_cocci: ast0toast: Reflect Cast attributes
  parsing_cocci: disjdistr: Reflect Cast attributes
  parsing_cocci: unify_ast: Reflect Cast attributes
  parsing_c: ast_c: Add Cast attributes
  parsing_c: parser: Parse Cast attributes
  parsing_c: pretty_print_c: Reflect Cast attributes
  parsing_c: type_annoter_c: Reflect Cast attributes
  parsing_c: unparse_cocci: Reflect Cast attributes
  parsing_c: visitor_c: Visit Cast attributes
  engine: check_exhaustive_pattern: Reflect Cast attributes
  engine: cocci_vs_c: Match Cast attributes
  ocaml: coccilib: Reflect Cast attributes
  tools: spgen: Reflect Cast attrs
  tests: Add test case to check cast attribute allminus
  tests: Add test case to remove cast attributes
  tests: Add test case to detect cast attributes

 engine/check_exhaustive_pattern.ml   |2 +-
 engine/cocci_vs_c.ml |   24 +---
 ocaml/coccilib.mli   |9 +
 parsing_c/ast_c.ml   |2 +-
 parsing_c/ast_c.mli  |2 +-
 parsing_c/parse_c.ml |4 +++-
 parsing_c/parser_c.mly   |   19 ++-
 parsing_c/pretty_print_c.ml  |7 ---
 parsing_c/type_annoter_c.ml  |4 ++--
 parsing_c/unparse_cocci.ml   |6 --
 parsing_c/visitor_c.ml   |   10 --
 parsing_cocci/arity.ml   |5 +++--
 parsing_cocci/ast0_cocci.ml  |4 ++--
 parsing_cocci/ast0_cocci.mli |4 ++--
 parsing_cocci/ast0toast.ml   |5 +++--
 parsing_cocci/ast_cocci.ml   |4 ++--
 parsing_cocci/ast_cocci.mli  |4 ++--
 parsing_cocci/check_meta.ml  |3 ++-
 parsing_cocci/compute_lines.ml   |5 +++--
 parsing_cocci/context_neg.ml |2 +-
 parsing_cocci/disjdistr.ml   |5 +++--
 parsing_cocci/index.ml   |2 +-
 parsing_cocci/iso_pattern.ml |   12 +---
 parsing_cocci/parser_cocci_menhir.mly|9 +
 parsing_cocci/pretty_print_cocci.ml  |4 +++-
 parsing_cocci/single_statement.ml|2 +-
 parsing_cocci/type_infer.ml  |2 +-
 parsing_cocci/unify_ast.ml   |6 --
 parsing_cocci/unparse_ast0.ml|4 +++-
 parsing_cocci/visitor_ast.ml |   10 ++
 parsing_cocci/visitor_ast0.ml|6 --
 tests/detect_cast_attr.c |   10 ++
 tests/detect_cast_attr.cocci |   11 +++
 tests/detect_cast_attr.res   |   10 ++
 tests/remove_cast_attr.c |   10 ++
 tests/remove_cast_attr.cocci |   10 ++
 tests/remove_cast_attr.res   |   10 ++
 tests/remove_cast_attr_allminus.c|   10 ++
 tests/remove_cast_attr_allminus.cocci|9 +
 tests/remove_cast_attr_allminus.res  |   10 ++
 tools/spgen/source/position_generator.ml |4 ++--
 41 files changed, 208 insertions(+), 73 deletions(-)


___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 09/32] parsing_cocci: arity: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
arity.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/arity.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 8ee6d33f..880cd7a3 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -254,13 +254,14 @@ let rec top_expression opt_allowed tgt expr =
   let ar = mcode ar in
   let field = ident false arity field in
   make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field))
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
   let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in
   let lp = mcode lp in
   let ty = typeC arity ty in
+  let attr = List.map mcode attr in
   let rp = mcode rp in
   let exp = expression arity exp in
-  make_exp expr tgt arity (Ast0.Cast(lp,ty,rp,exp))
+  make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
   | Ast0.SizeOfExpr(szf,exp) ->
   let arity = exp_same (mcode2line szf) [mcode2arity szf] in
   let szf = mcode szf in
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

2020-04-28 Thread Jaskaran Singh
To add Cast attributes to the C AST, pass attributes from the type_name
rule of the C parser.

Signed-off-by: Jaskaran Singh 
---
 ocaml/coccilib.mli |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 0e807c9a..a305d616 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -791,7 +791,8 @@ module Parser_c :
   (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement
 val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.expression
 val type_name :
-  (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType
+  (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
+  Ast_c.attribute list * Ast_c.fullType
   end
 module Lexer_c :
   sig
diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
index 0d3a189a..5f8d5e2d 100644
--- a/parsing_c/parse_c.ml
+++ b/parsing_c/parse_c.ml
@@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
   result
 
 (* Please DO NOT remove this code, even though most of it is not used *)
-let type_of_string   = parse_gen ~cpp:false ~tos:true Parser_c.type_name
+let type_of_string s =
+  let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name s in
+  Common.snd typname
 let statement_of_string  = parse_gen ~cpp:false ~tos:false Parser_c.statement
 let expression_of_string = parse_gen ~cpp:false ~tos:false Parser_c.expr
 let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false Parser_c.expr
diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index aedde179..0abcc9b0 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -665,7 +665,7 @@ let postfakeInfo pii  =
 
 %type  statement
 %type  expr
-%type  type_name
+%type  type_name
 
 %%
 /*(*)*/
@@ -818,7 +818,7 @@ arith_expr:
 
 cast_expr:
  | unary_expr{ $1 }
- | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3] }
+ | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] }
 /*
 It could be useful to have the following, but there is no place for the
 attribute in the AST.
@@ -831,7 +831,7 @@ unary_expr:
  | TDec unary_expr { mk_e(Infix ($2, Dec))[$1] }
  | unary_op cast_expr  { mk_e(Unary ($2, fst $1)) [snd $1] }
  | Tsizeof unary_expr  { mk_e(SizeOfExpr ($2))[$1] }
- | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType ($3))[$1;$2;$4] }
+ | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd $3))[$1;$2;$4] }
  | Tnew new_argument   { mk_e(New (None, $2)) [$1] }
  | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5))
 [$1; $2; $4] }
  | Tdelete cast_expr   { mk_e(Delete(false, $2))  [$1] }
@@ -897,9 +897,9 @@ postfix_expr:
 
  /*(* gccext: also called compound literals *)*/
  | topar2 type_name tcpar2 TOBrace TCBrace
- { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] }
+ { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3] }
  | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct TCBrace
- { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] }
+ { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) 
[$1;$3] }
 
 
 primary_expr:
@@ -1298,7 +1298,7 @@ type_spec2:
Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
 
  | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)), [$1;$2;$4] }
- | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)), [$1;$2;$4] }
+ | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd $3)), [$1;$2;$4] }
 
 /*(**)*/
 /*(* workarounds *)*/
@@ -1531,12 +1531,12 @@ type_qualif_list:
 type_name:
  | spec_qualif_list
  { let (attrs, ds) = $1 in
-   let (returnType, _) = fixDeclSpecForDecl ds in returnType }
+   let (returnType, _) = fixDeclSpecForDecl ds in (attrs, returnType) }
  | spec_qualif_list abstract_declaratort
  { let (attrs1, ds) = $1 in
let (attrs2, fn) = $2 in
let (returnType, _) = fixDeclSpecForDecl ds in
-   fn returnType }
+   (attrs1@attrs2, fn returnType) }
 
 
 
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 03/32] parsing_cocci: parser: Parse cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL ASTs. Parse these attributes in
the SmPL parser and place them in the SmPL AST. The added production
only supports attributes after the type and before the expression.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/parser_cocci_menhir.mly | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/parser_cocci_menhir.mly 
b/parsing_cocci/parser_cocci_menhir.mly
index db5661bd..38b0e039 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -2176,11 +2176,12 @@ arith_expr_bis:
 
 cast_expr(r,pe):
 unary_expr(r,pe)  { $1 }
-  | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
-  { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
+  | lp=TOPar t=ctype ar=attr_list rp=TCPar e=cast_expr(r,pe)
+  { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, ar,
  P.clt2mcode ")" rp, e)) }
-  | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar e=cast_expr(r,pe)
-  { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t,
+  | lp=TOPar t=ctype d=direct_abstract_d ar=attr_list rp=TCPar
+e=cast_expr(r,pe)
+  { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, ar,
 P.clt2mcode ")" rp, e)) }
 
 unary_expr(r,pe):
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 10/32] parsing_cocci: check_meta: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
check_meta.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/check_meta.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 5a348ba3..4f7db813 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -172,7 +172,8 @@ let rec expression context old_metas table minus e =
   | Ast0.RecordPtAccess(exp,ar,field) ->
   expression ID old_metas table minus exp;
   ident FIELD old_metas table minus field
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
+  (* No meta attribute yet *)
   typeC old_metas table minus ty; expression ID old_metas table minus exp
   | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp
   | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 12/32] parsing_cocci: context_neg: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
context_neg.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/context_neg.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index dd768a61..b6378512 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -628,7 +628,7 @@ let rec equal_expression e1 e2 =
   equal_mcode pt1 pt2
   | (Ast0.RecordPtAccess(_,ar1,_),Ast0.RecordPtAccess(_,ar2,_)) ->
   equal_mcode ar1 ar2
-  | (Ast0.Cast(lp1,_,rp1,_),Ast0.Cast(lp2,_,rp2,_)) ->
+  | (Ast0.Cast(lp1,_,_,rp1,_),Ast0.Cast(lp2,_,_,rp2,_)) ->
   equal_mcode lp1 lp2 && equal_mcode rp1 rp2
   | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) ->
   equal_mcode szf1 szf2
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 11/32] parsing_cocci: compute_lines: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
compute_lines.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/compute_lines.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index 1361d842..e945914b 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -425,11 +425,12 @@ let rec expression e =
   let ar = normal_mcode ar in
   let field = ident field in
   mkres e (Ast0.RecordPtAccess(exp,ar,field)) exp field
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
   let lp = normal_mcode lp in
   let exp = expression exp in
+  let attr = List.map normal_mcode attr in
   let rp = normal_mcode rp in
-  mkres e (Ast0.Cast(lp,typeC ty,rp,exp)) (promote_mcode lp) exp
+  mkres e (Ast0.Cast(lp,typeC ty,attr,rp,exp)) (promote_mcode lp) exp
   | Ast0.SizeOfExpr(szf,exp) ->
   let szf = normal_mcode szf in
   let exp = expression exp in
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 04/32] parsing_cocci: visitor_ast0: Visit cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to AST0 of SmPL. Visit these attributes in the
AST0 visitor of SmPL.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast0.ml | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index d9e340ed..2ccdb0bb 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -184,12 +184,14 @@ let visitor mode bind option_default
let (ar_n,ar) = string_mcode ar in
let (field_n,field) = ident field in
(multibind [exp_n;ar_n;field_n], Ast0.RecordPtAccess(exp,ar,field))
-   | Ast0.Cast(lp,ty,rp,exp) ->
+   | Ast0.Cast(lp,ty,attr,rp,exp) ->
let (lp_n,lp) = string_mcode lp in
let (ty_n,ty) = typeC ty in
+   let (attr_n,attr) = map_split_bind string_mcode attr in
let (rp_n,rp) = string_mcode rp in
let (exp_n,exp) = expression exp in
-   (multibind [lp_n;ty_n;rp_n;exp_n], Ast0.Cast(lp,ty,rp,exp))
+(multibind [lp_n;ty_n;attr_n;rp_n;exp_n],
+ Ast0.Cast(lp,ty,attr,rp,exp))
| Ast0.SizeOfExpr(szf,exp) ->
let (szf_n,szf) = string_mcode szf in
let (exp_n,exp) = expression exp in
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 07/32] parsing_cocci: iso_pattern: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
iso_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_pattern.ml | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 9df21fb9..b57e293e 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -575,7 +575,7 @@ let match_maker checks_needed context_required 
whencode_allowed =
(* all caps is a const *)
Str.string_match all_caps nm 0
| _ -> false)
-   | Ast0.Cast(lp,ty,rp,e) -> matches e
+   | Ast0.Cast(lp,ty,attr,rp,e) -> matches e
| Ast0.SizeOfExpr(se,exp) -> true
| Ast0.SizeOfType(se,lp,ty,rp) -> true
| Ast0.MetaExpr(nm,_,_,Ast.CONST,p,_bitfield) ->
@@ -586,7 +586,7 @@ let match_maker checks_needed context_required 
whencode_allowed =
  let rec matches e =
match Ast0.unwrap e with
  Ast0.Ident(c) -> true
-   | Ast0.Cast(lp,ty,rp,e) -> matches e
+   | Ast0.Cast(lp,ty,attr,rp,e) -> matches e
| Ast0.MetaExpr(nm,_,_,Ast.ID,p,_bitfield) ->
(Ast0.lub_pure p pure) = pure
| _ -> false in
@@ -757,10 +757,16 @@ let match_maker checks_needed context_required 
whencode_allowed =
   conjunct_many_bindings
 [check_mcode opa op; match_expr expa expb;
   match_ident fielda fieldb]
- | (Ast0.Cast(lp1,tya,rp1,expa),Ast0.Cast(lp,tyb,rp,expb)) ->
+ | (Ast0.Cast(lp1,tya,attra,rp1,expa),
+ Ast0.Cast(lp,tyb,attrb,rp,expb)) ->
+  if (List.length attra = List.length attrb &&
+  List.fold_left2 (fun p a b -> p && mcode_equal a b) true
+  attra attrb)
+  then
  conjunct_many_bindings
[check_mcode lp1 lp; check_mcode rp1 rp;
  match_typeC tya tyb; match_expr expa expb]
+  else return false
  | (Ast0.SizeOfExpr(szf1,expa),Ast0.SizeOfExpr(szf,expb)) ->
  conjunct_bindings (check_mcode szf1 szf) (match_expr expa expb)
  | (Ast0.SizeOfType(szf1,lp1,tya,rp1),
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 08/32] parsing_cocci: type_infer: Reflect Cast attributes

2020-04-28 Thread Jaskaran Singh
Cast attributes are added to the SmPL AST. Reflect these changes in
type_infer.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/type_infer.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml
index e8aad810..2c1cc73b 100644
--- a/parsing_cocci/type_infer.ml
+++ b/parsing_cocci/type_infer.ml
@@ -291,7 +291,7 @@ let rec propagate_types env =
| Some x ->
let ty = Ast0.wrap x in
err exp ty "non-structure pointer type in field ref")
-   | Ast0.Cast(lp,ty,rp,exp) -> Some ty
+   | Ast0.Cast(lp,ty,attr,rp,exp) -> Some ty
| Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type)
| Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type)
| Ast0.TypeExp(ty) -> None
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH 22/23] tests: Add test case for removing parameter attributes

2020-04-28 Thread Jaskaran Singh
On Mon, 2020-04-27 at 19:31 +0200, Julia Lawall wrote:
> 
> On Mon, 27 Apr 2020, Jaskaran Singh wrote:
> 
> > Add a test case for removing Parameter attributes. The test case
> > checks
> > correct removal of the attribute when it is:
> > 
> > - before the parameter type.
> > - after the parameter type and before the parameter identifier.
> > - after the parameter identifier.
> > 
> > Signed-off-by: Jaskaran Singh 
> > ---
> >  tests/remove_param_attrs.c | 11 +++
> >  tests/remove_param_attrs.cocci | 13 +
> >  tests/remove_param_attrs.res   | 11 +++
> >  3 files changed, 35 insertions(+)
> >  create mode 100644 tests/remove_param_attrs.c
> >  create mode 100644 tests/remove_param_attrs.cocci
> >  create mode 100644 tests/remove_param_attrs.res
> > 
> > diff --git a/tests/remove_param_attrs.c
> > b/tests/remove_param_attrs.c
> > new file mode 100644
> > index ..8ec1ffde
> > --- /dev/null
> > +++ b/tests/remove_param_attrs.c
> > @@ -0,0 +1,11 @@
> > +int func1(int x, __nocast int y) {
> > +   return 0;
> > +}
> > +
> > +int func2(int x, int __nocast y) {
> > +   return 0;
> > +}
> > +
> > +int func3(int x, int y __nocast) {
> > +   return 0;
> > +}
> > diff --git a/tests/remove_param_attrs.cocci
> > b/tests/remove_param_attrs.cocci
> > new file mode 100644
> > index ..43f5a204
> > --- /dev/null
> > +++ b/tests/remove_param_attrs.cocci
> > @@ -0,0 +1,13 @@
> > +@@
> > +type T,U;
> > +attribute name __nocast;
> > +identifier x,y;
> > +@@
> > +
> > +T x(
> > +...,
> > +U y
> > +-  __nocast
> 
> So the idea is that the attribute is removed no matter where it
> occurs?
> 

Yes, if the attribute occurs in the parameter.

Cheers,
Jaskaran.

> julia
> 
> > +,
> > +...
> > +  ) {...}
> > diff --git a/tests/remove_param_attrs.res
> > b/tests/remove_param_attrs.res
> > new file mode 100644
> > index ..3705e814
> > --- /dev/null
> > +++ b/tests/remove_param_attrs.res
> > @@ -0,0 +1,11 @@
> > +int func1(int x, int y) {
> > +   return 0;
> > +}
> > +
> > +int func2(int x, int y) {
> > +   return 0;
> > +}
> > +
> > +int func3(int x, int y) {
> > +   return 0;
> > +}
> > --
> > 2.21.1
> > 
> > 

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci