Skip to content

Commit

Permalink
coccinelle: deref_null: improve performance
Browse files Browse the repository at this point in the history
Move rules looking for some special cases of safe dereferences before
the collection of NULL-tested values.  The special cases are fairly
rare, but somewhat costly to find, because isomorphisms create many
variants of the rules.  There is thus no need to search for them over
and over for each NULL tested expression.  Collecting them just once
is sufficient and more efficient.

Signed-off-by: Julia Lawall <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
JuliaLawall authored and masahir0y committed May 22, 2018
1 parent 32d0572 commit 21195f8
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions scripts/coccinelle/null/deref_null.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ virtual context
virtual org
virtual report

@ifm@
expression *E;
statement S1,S2;
position p1;
@@

if@p1 ((E == NULL && ...) || ...) S1 else S2

// The following two rules are separate, because both can match a single
// expression in different ways
@pr1 expression@
expression *ifm.E;
expression E;
identifier f;
position p1;
@@

(E != NULL && ...) ? <+...E->f@p1...+> : ...

@pr2 expression@
expression *ifm.E;
expression E;
identifier f;
position p2;
@@
Expand All @@ -46,6 +38,14 @@ position p2;
sizeof(<+...E->f@p2...+>)
)

@ifm@
expression *E;
statement S1,S2;
position p1;
@@

if@p1 ((E == NULL && ...) || ...) S1 else S2

// For org and report modes

@r depends on !context && (org || report) exists@
Expand Down Expand Up @@ -212,24 +212,16 @@ else S3
// The following three rules are duplicates of ifm, pr1 and pr2 respectively.
// It is need because the previous rule as already made a "change".

@ifm1 depends on context && !org && !report@
expression *E;
statement S1,S2;
position p1;
@@

if@p1 ((E == NULL && ...) || ...) S1 else S2

@pr11 depends on context && !org && !report expression@
expression *ifm1.E;
expression E;
identifier f;
position p1;
@@

(E != NULL && ...) ? <+...E->f@p1...+> : ...

@pr12 depends on context && !org && !report expression@
expression *ifm1.E;
expression E;
identifier f;
position p2;
@@
Expand All @@ -242,6 +234,14 @@ position p2;
sizeof(<+...E->f@p2...+>)
)

@ifm1 depends on context && !org && !report@
expression *E;
statement S1,S2;
position p1;
@@

if@p1 ((E == NULL && ...) || ...) S1 else S2

@depends on context && !org && !report exists@
expression subE <= ifm1.E;
expression *ifm1.E;
Expand Down

0 comments on commit 21195f8

Please sign in to comment.