[Cocci] =~ runtime improvements?

Julia Lawall julia.lawall at lip6.fr
Thu Sep 27 23:09:26 CEST 2018



On Thu, 27 Sep 2018, Kees Cook wrote:

> Hi,
>
> This .cocci takes a VERY long time to run against the kernel, and I'd
> love to know what I could do to improve it. I assume it's related to
> the use of the "=~" operand:
>
> // Replace multi-factor out-of-line products with array_size() usage.
> @@
> identifier alloc =~ ".*alloc.*";
> constant C1, C2, C3;
> identifier ISTRIDE, ISIZE, ICOUNT;
> expression ESTRIDE, ESIZE, ECOUNT;
> expression PRODUCT, OTHER;
> @@
>
> (
>   PRODUCT = ((C1)) * ((C2)) * ((C3))
> |
>   PRODUCT = ((C1)) * ((C2))
> |
> - PRODUCT = ((ICOUNT)) * ((ISTRIDE)) * ((ISIZE))
> + PRODUCT = array3_size(ICOUNT, ISTRIDE, ISIZE)
> |
> - PRODUCT = ((ICOUNT)) * ((ISTRIDE)) * ((ESIZE))
> + PRODUCT = array3_size(ICOUNT, ISTRIDE, ESIZE)
> |
> - PRODUCT = ((ICOUNT)) * ((ESTRIDE)) * ((ESIZE))
> + PRODUCT = array3_size(ICOUNT, ESTRIDE, ESIZE)
> |
> - PRODUCT = ((ECOUNT)) * ((ESTRIDE)) * ((ESIZE))
> + PRODUCT = array3_size(ECOUNT, ESTRIDE, ESIZE)
> |
> - PRODUCT = ((ICOUNT)) * ((ISIZE))
> + PRODUCT = array_size(ICOUNT, ISTRIDE, ISIZE)
> |
> - PRODUCT = ((ICOUNT)) * ((ESIZE))
> + PRODUCT = array_size(ICOUNT, ESIZE)
> |
> - PRODUCT = ((ECOUNT)) * ((ESIZE))
> + PRODUCT = array_size(ECOUNT, ESIZE)
> )
>   ... when != PRODUCT = OTHER
>   alloc(..., PRODUCT, ...)

The rule contains ... and it doesn't contain anything much concrete.
Regular expressions aren't used to select files, so you consider all
files.  Big disjunctions are also costly.  You could consider making a
series of 9 rules.  Do you need the double parentheses?  That adds more
disjunctions.

julia


>
> Thanks!
>
> -Kees
>
> --
> Kees Cook
> Pixel Security
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>


More information about the Cocci mailing list