diff options
-rw-r--r-- | parse.c | 4 | ||||
-rwxr-xr-x | tests.sh | 12 | ||||
-rw-r--r-- | tests/test_and_purity.out | 0 | ||||
-rw-r--r-- | tests/test_or_purity.out | 0 |
4 files changed, 14 insertions, 2 deletions
@@ -2568,7 +2568,7 @@ static struct expr *new_and_expr(const struct parser_state *state, struct expr * debug_opt(state, "-O1: short-circuit: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, lhs); free_expr(rhs); return lhs; - } else if (optlevel >= 2 && rhs->always_false && lhs->pure) { + } else if (optlevel >= 2 && lhs->pure && rhs == &expr_false) { debug_opt(state, "-O2: purity: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, rhs); free_expr(lhs); return rhs; @@ -2664,7 +2664,7 @@ static struct expr *new_or_expr(const struct parser_state *state, struct expr *l } else if (rhs == &expr_false) { debug_opt(state, "-O1: disjunctive syllogism: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, lhs); return lhs; - } else if (optlevel >= 2 && rhs->always_true && lhs->pure) { + } else if (optlevel >= 2 && lhs->pure && rhs == &expr_true) { debug_opt(state, "-O2: purity: (%s %e %e) <==> %e\n", argv[0], lhs, rhs, rhs); free_expr(lhs); return rhs; @@ -346,6 +346,8 @@ gnu_tests=( test_or test_comma test_precedence + test_and_purity + test_or_purity ) bfs_tests=( @@ -1232,6 +1234,16 @@ function test_printx() { bfs_diff weirdnames -printx } +function test_and_purity() { + # Regression test: (-a lhs(pure) rhs(always_false)) <==> rhs is only valid if rhs is pure + bfs_diff basic -name nonexistent \( -print , -false \) +} + +function test_or_purity() { + # Regression test: (-o lhs(pure) rhs(always_true)) <==> rhs is only valid if rhs is pure + bfs_diff basic -name '*' -o -print +} + passed=0 failed=0 diff --git a/tests/test_and_purity.out b/tests/test_and_purity.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_and_purity.out diff --git a/tests/test_or_purity.out b/tests/test_or_purity.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_or_purity.out |