]> The Tcpdump Group git mirrors - libpcap/commitdiff
optimizer: replacing unknown value with unknown value is not a no-op 613/head
authorMichal Kubecek <[email protected]>
Sun, 17 Sep 2017 17:17:09 +0000 (19:17 +0200)
committerMichal Kubecek <[email protected]>
Sun, 17 Sep 2017 17:17:09 +0000 (19:17 +0200)
Function vstore() checks if new and old value are the same and if they are,
it replaces the instruction with NOP. We must not do this if both old and
new value are 0 which means "unknown" as in this case, the actual values
(at runtime) can differ so that the instruction cannot be omitted.

An example of a program where this leads to incorrect optimization is shown
in issue #581.

optimize.c

index 926761d5d9e7aa00ab7824acdebdec5edee5ffc8..8544f3e19d1e9cb1d914573b4523fcb37d3cef30 100644 (file)
@@ -578,7 +578,7 @@ F(opt_state_t *opt_state, int code, int v0, int v1)
 static inline void
 vstore(struct stmt *s, int *valp, int newval, int alter)
 {
-       if (alter && *valp == newval)
+       if (alter && newval != 0 && *valp == newval)
                s->code = NOP;
        else
                *valp = newval;