[PATCH 6/9] pre-process: print variable argument macros correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The dump_macros() function fails to correctly output the definition of
macros that have a variable argument list. For example, the following
macros:

    #define unlocks(...) annotate(unlock_func(__VA_ARGS__))
    #define apply(x,...) x(__VA_ARGS__)

are output like so:

    #define unlocks(__VA_ARGS__) annotate(unlock_func(__VA_ARGS__))
    #define apply(x,__VA_ARGS__) x(__VA_ARGS__)

Add the code necessary to print the ellipsis in the argument list to the
dump_macros() function and add the above macros to the 'dump-macros.c'
test file.

Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
---
 pre-process.c                         | 11 ++++++++++-
 validation/preprocessor/dump-macros.c |  5 +++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/pre-process.c b/pre-process.c
index 7b76c65..418b8ee 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -2167,6 +2167,12 @@ struct token * preprocess(struct token *token)
 	return token;
 }
 
+static int is_VA_ARGS_token(struct token *token)
+{
+	return (token_type(token) == TOKEN_IDENT) &&
+		(token->ident == &__VA_ARGS___ident);
+}
+
 static void dump_macro(struct symbol *sym)
 {
 	int nargs = sym->arglist ? sym->arglist->count.normal : 0;
@@ -2182,7 +2188,10 @@ static void dump_macro(struct symbol *sym)
 		for (; !eof_token(token); token = token->next) {
 			if (token_type(token) == TOKEN_ARG_COUNT)
 				continue;
-			printf("%s%s", sep, show_token(token));
+			if (is_VA_ARGS_token(token))
+				printf("%s...", sep);
+			else
+				printf("%s%s", sep, show_token(token));
 			args[narg++] = token;
 			sep = ",";
 		}
diff --git a/validation/preprocessor/dump-macros.c b/validation/preprocessor/dump-macros.c
index f8983d8..6940a20 100644
--- a/validation/preprocessor/dump-macros.c
+++ b/validation/preprocessor/dump-macros.c
@@ -9,6 +9,9 @@
 
 #define STRING(x) #x
 #define CONCAT(x,y) x ## y
+
+#define unlocks(...) annotate(unlock_func(__VA_ARGS__))
+#define apply(x,...) x(__VA_ARGS__)
 /*
  * check-name: dump-macros
  * check-command: sparse -E -dD -DIJK=ijk -UNDEF -UNYDEF $file
@@ -20,4 +23,6 @@ check-output-contains: #define DEF xyz
 check-output-contains: #define NYDEF ydef
 check-output-contains: #define STRING(x) #x
 check-output-contains: #define CONCAT(x,y) x ## y
+check-output-contains: #define unlocks(...) annotate(unlock_func(__VA_ARGS__))
+check-output-contains: #define apply(x,...) x(__VA_ARGS__)
  */
-- 
2.19.0



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux