public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 1/4] kconfig: call expr_eliminate_yn() at least once in expr_eliminate_dups()
Date: Mon,  8 Jul 2024 00:38:04 +0900	[thread overview]
Message-ID: <20240707153856.2483047-1-masahiroy@kernel.org> (raw)

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 <masahiroy@kernel.org>
---

 scripts/kconfig/expr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 6d4b5a5a1e62..b2dfd3123a5d 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -637,7 +637,7 @@ struct expr *expr_eliminate_dups(struct expr *e)
 		return e;
 
 	oldcount = trans_count;
-	while (1) {
+	do {
 		trans_count = 0;
 		switch (e->type) {
 		case E_OR: case E_AND:
@@ -645,11 +645,8 @@ struct expr *expr_eliminate_dups(struct expr *e)
 		default:
 			;
 		}
-		if (!trans_count)
-			/* No simplifications done in this pass. We're done */
-			break;
 		e = expr_eliminate_yn(e);
-	}
+	} while (trans_count); /* repeat until we get no more simplifications */
 	trans_count = oldcount;
 	return e;
 }
-- 
2.43.0


             reply	other threads:[~2024-07-07 15:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-07 15:38 Masahiro Yamada [this message]
2024-07-07 15:38 ` [PATCH 2/4] kconfig: add const qualifiers to several function arguments Masahiro Yamada
2024-07-07 15:38 ` [PATCH 3/4] kconfig: remove P_CHOICEVAL property Masahiro Yamada
2024-07-07 15:40   ` Masahiro Yamada
2024-07-07 15:38 ` [PATCH 4/4] kconfig: remove 'e1' and 'e2' macros from expressoin deduplication Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240707153856.2483047-1-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox