[PATCH v4 2/6] treewide: use prandom_u32_max() when possible
Julia Lawall
julia.lawall at inria.fr
Sat Oct 8 07:33:08 UTC 2022
> >> @minus_one@
> >> expression FULL;
> >> @@
> >>
> >> - (get_random_int() & ((FULL) - 1)
> >> + prandom_u32_max(FULL)
> >
> >Ahh, well, okay, this is the example I mentioned above. Only works if
> >FULL is saturated. Any clever way to get coccinelle to prove that? Can
> >it look at the value of constants?
>
> I'm not sure if Cocci will do that without a lot of work. The literals trick I used below would need a lot of fanciness. :)
If FULL is an arbitrary expression, it would not be easy to automate. If
it is a constant then you can use python/ocaml to analyze its value. But
if it's a #define constant then you would need a previous rule to match the
#define and find that value.
For LITERAL, I think you could just do constant int LITERAL; for the
metavariable declaration.
julia
More information about the dri-devel
mailing list