Skip to content

Commit 8bfd6f0

Browse files
committed
kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups()
Kconfig simplifies expressions, but redundant '&&' and '||' operators involving constant symbols 'y' and 'n' are sometimes trimmed and sometimes not. [Test Code] config DEP def_bool y config A bool "A" depends on DEP && y config B bool "B" depends on DEP && y && y [Result] $ make helpnewconfig [ snip ] ----- There is no help available for this option. Symbol: A [=n] Type : bool Defined at Kconfig:4 Prompt: A Depends on: DEP [=y] && y [=y] Location: -> A (A [=n]) ----- ----- There is no help available for this option. Symbol: B [=n] Type : bool Defined at Kconfig:8 Prompt: B Depends on: DEP [=y] Location: -> B (B [=n]) ----- The dependency for A, 'DEP && y', remains as-is, while that for B, 'DEP && y && y', has been reduced to 'DEP'. Currently, expr_eliminate_dups() calls expr_eliminate_yn() only when trans_count != 0, in other words, only when expr_eliminate_dups1() has trimmed at least one leaf. It fails to trim a single '&& y', etc. To fix this inconsistent behavior, expr_eliminate_yn() should be called at least once even if no leaf has been trimmed. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d67015e commit 8bfd6f0

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

scripts/kconfig/expr.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,19 +637,16 @@ struct expr *expr_eliminate_dups(struct expr *e)
637637
return e;
638638

639639
oldcount = trans_count;
640-
while (1) {
640+
do {
641641
trans_count = 0;
642642
switch (e->type) {
643643
case E_OR: case E_AND:
644644
expr_eliminate_dups1(e->type, &e, &e);
645645
default:
646646
;
647647
}
648-
if (!trans_count)
649-
/* No simplifications done in this pass. We're done */
650-
break;
651648
e = expr_eliminate_yn(e);
652-
}
649+
} while (trans_count); /* repeat until we get no more simplifications */
653650
trans_count = oldcount;
654651
return e;
655652
}

0 commit comments

Comments
 (0)