From b1a999892b9e13181ddd9a7d895f3d1c65fbb449 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 17 Sep 2024 12:18:04 -0400 Subject: opt: Fix an invalid assertion in sink_not_comma() When optimizing -not \( -a , -b \), the child is a comma expression, not the parent. Fixes: 4a36bb9 ("expr: Make expressions variadic") --- src/opt.c | 7 +++---- tests/gnu/not_comma.out | 34 ++++++++++++++++++++++++++++++++++ tests/gnu/not_comma.sh | 2 ++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/gnu/not_comma.out create mode 100644 tests/gnu/not_comma.sh diff --git a/src/opt.c b/src/opt.c index 86ce694..6b51d85 100644 --- a/src/opt.c +++ b/src/opt.c @@ -1402,12 +1402,11 @@ static struct bfs_expr *sink_not_andor(struct bfs_opt *opt, struct bfs_expr *exp /** Sink a negation into a comma expression. */ static struct bfs_expr *sink_not_comma(struct bfs_opt *opt, struct bfs_expr *expr) { - bfs_assert(expr->eval_fn == eval_comma); - - opt_enter(opt, "%pe\n", expr); - char **argv = expr->argv; expr = only_child(expr); + opt_enter(opt, "%pe\n", expr); + + bfs_assert(expr->eval_fn == eval_comma); struct bfs_exprs children; foster_children(expr, &children); diff --git a/tests/gnu/not_comma.out b/tests/gnu/not_comma.out new file mode 100644 index 0000000..b90468e --- /dev/null +++ b/tests/gnu/not_comma.out @@ -0,0 +1,34 @@ +basic +basic +basic/a +basic/a +basic/b +basic/b +basic/c +basic/c +basic/c/d +basic/c/d +basic/e +basic/e +basic/e/f +basic/g +basic/g +basic/g/h +basic/g/h +basic/i +basic/i +basic/j +basic/j +basic/j/foo +basic/k +basic/k +basic/k/foo +basic/k/foo/bar +basic/k/foo/bar +basic/l +basic/l +basic/l/foo +basic/l/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz +basic/l/foo/bar/baz diff --git a/tests/gnu/not_comma.sh b/tests/gnu/not_comma.sh new file mode 100644 index 0000000..04c0195 --- /dev/null +++ b/tests/gnu/not_comma.sh @@ -0,0 +1,2 @@ +# Regression test: assertion failure in sink_not_comma() +bfs_diff basic -not \( -print , -name '*f*' \) -print -- cgit v1.2.3