[PATCH 08/21] preparing to change argument number encoding for TOKEN_..._ARGUMENT

Al Viro <[email protected]> Mon, 16 Mar 2026 07:04:02 +0000
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
We want to steal some bits from TOKEN_..._ARGUMENT; it's not a problem,
seeing that payload is a 32bit number and we are *not* going to support
many millions of arguments in macros.  For now, wrap the accesses into
an inline helper (argnum(token)), to reduce the amount of noise in
subsequent patches.

Signed-off-by: Al Viro <[email protected]>
---
 pre-process.c | 23 ++++++++++++++---------
 token.h       |  4 ++++
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/pre-process.c b/pre-process.c
index 85662365..efb208e7 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -624,11 +624,16 @@ static struct token **copy(struct token **where, struct token *list)
 	return where;
 }
 
+static inline int argnum(const struct token *arg)
+{
+	return arg->argnum >> ARGNUM_BITS_STOLEN;
+}
+
 static int handle_kludge(const struct token **p, struct arg *args)
 {
 	const struct token *t = (*p)->next->next;
 	while (1) {
-		struct arg *v = &args[t->argnum];
+		struct arg *v = &args[argnum(t)];
 		if (token_type(t->next) != TOKEN_CONCAT) {
 			if (v->arg) {
 				/* ignore the first ## */
@@ -681,13 +686,13 @@ static struct token **substitute(struct token **list, const struct token *body,
 			break;
 
 		case TOKEN_STR_ARGUMENT:
-			arg = args[body->argnum].str;
-			count = &args[body->argnum].n_str;
+			arg = args[argnum(body)].str;
+			count = &args[argnum(body)].n_str;
 			goto copy_arg;
 
 		case TOKEN_QUOTED_ARGUMENT:
-			arg = args[body->argnum].arg;
-			count = &args[body->argnum].n_quoted;
+			arg = args[argnum(body)].arg;
+			count = &args[argnum(body)].n_quoted;
 			if (!arg || eof_token(arg)) {
 				if (state == Concat)
 					state = Normal;
@@ -698,8 +703,8 @@ static struct token **substitute(struct token **list, const struct token *body,
 			goto copy_arg;
 
 		case TOKEN_MACRO_ARGUMENT:
-			arg = args[body->argnum].expanded;
-			count = &args[body->argnum].n_normal;
+			arg = args[argnum(body)].expanded;
+			count = &args[argnum(body)].n_normal;
 			if (eof_token(arg)) {
 				state = Normal;
 				continue;
@@ -1219,7 +1224,7 @@ static int try_arg(struct token *token, enum token_type type, struct token *argl
 	for (int i = 0; i < nr; i++)
 		arglist = arglist->next->next;
 
-	token->argnum = nr;
+	token->argnum = nr << ARGNUM_BITS_STOLEN;
 	token_type(token) = type;
 	switch (type) {
 	case TOKEN_MACRO_ARGUMENT:
@@ -2356,7 +2361,7 @@ static void dump_macro(struct symbol *sym)
 			/* fall-through */
 		case TOKEN_QUOTED_ARGUMENT:
 		case TOKEN_MACRO_ARGUMENT:
-			printf("%s", show_ident(args[token->argnum]));
+			printf("%s", show_ident(args[argnum(token)]));
 			break;
 		default:
 			printf("%s", show_token(token));
diff --git a/token.h b/token.h
index 5dcd8594..fe7c7fe9 100644
--- a/token.h
+++ b/token.h
@@ -177,6 +177,10 @@ struct argcount {
 	unsigned str:10;
 };
 
+enum {
+	ARGNUM_BITS_STOLEN
+};
+
 /*
  * This is a very common data structure, it should be kept
  * as small as humanly possible. Big (rare) types go as
-- 
2.47.3