[PATCH 18/21] merge(): saner handling of ->noexpand

Al Viro <[email protected]> Mon, 16 Mar 2026 07:04:12 +0000
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
We only care about noexpand for identifiers and solitary #; the latter
can't occur in merge(), the former should just get ->noexpand set
according to ->ident->tainted.  That eliminates the last remaining
possibility of having expand() run into a token that has tainted
identifier - the regular noexpand check in the caller is sufficient now.
Should've done that all way back in 2004...

Signed-off-by: Al Viro <[email protected]>
---
 pre-process.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/pre-process.c b/pre-process.c
index eec0569c..352f02df 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -507,7 +507,7 @@ static int merge(struct token *left, struct token *right)
 	switch (res) {
 	case TOKEN_IDENT:
 		left->ident = built_in_ident(buffer);
-		left->pos.noexpand = 0;
+		left->pos.noexpand = left->ident->tainted;
 		return 1;
 
 	case TOKEN_NUMBER:
@@ -529,13 +529,11 @@ static int merge(struct token *left, struct token *right)
 	case TOKEN_WIDE_CHAR:
 	case TOKEN_WIDE_STRING:
 		token_type(left) = res;
-		left->pos.noexpand = 0;
 		left->string = right->string;
 		return 1;
 
 	case TOKEN_WIDE_CHAR_EMBEDDED_0 ... TOKEN_WIDE_CHAR_EMBEDDED_3:
 		token_type(left) = res;
-		left->pos.noexpand = 0;
 		memcpy(left->embedded, right->embedded, 4);
 		return 1;
 
@@ -812,16 +810,10 @@ static int expand(struct token **list, struct symbol *sym)
 {
 	struct token *last;
 	struct token *token = *list;
-	struct ident *expanding = token->ident;
 	struct token **tail;
 	struct token *expansion = sym->expansion;
 	struct arg args[sym->fixed_args + 1];
 
-	if (expanding->tainted) {
-		token->pos.noexpand = 1;
-		return 1;
-	}
-
 	if (sym->arglist) {
 		if (!match_op(scan_next(&token->next), '('))
 			return 1;
-- 
2.47.3