summaryrefslogtreecommitdiff
path: root/optimize.c
diff options
context:
space:
mode:
authorMichal Kubecek <mkubecek@suse.cz>2017-09-17 19:17:09 +0200
committerMichal Kubecek <mkubecek@suse.cz>2017-09-17 19:17:09 +0200
commitb056d381ff63ae3421800a07dd263ce32806d15f (patch)
tree581d27244593f065883d5660310e0824c174ae58 /optimize.c
parent181a8055463ca3c7864f0347d809d8125e76d9cd (diff)
downloadlibpcap-b056d381ff63ae3421800a07dd263ce32806d15f.tar.gz
optimizer: replacing unknown value with unknown value is not a no-op
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.
Diffstat (limited to 'optimize.c')
-rw-r--r--optimize.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/optimize.c b/optimize.c
index 926761d5..8544f3e1 100644
--- a/optimize.c
+++ b/optimize.c
@@ -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;