On Fri, Jan 23, 2015 at 11:23:32PM +0100, Luc Van Oostenryck wrote: > On Fri, Jan 23, 2015 at 08:40:17AM -0800, Christopher Li wrote: > > I think sparse haven't implement the __COUNTER__ macro. That is why it emit the > > error on duplicate entry. > > The following patch should fix that. [...] > Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro. > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> One issue below. > --- a/pre-process.c > +++ b/pre-process.c > @@ -181,6 +181,10 @@ static int expand_one_symbol(struct token **list) > time(&t); > strftime(buffer, 9, "%T", localtime(&t)); > replace_with_string(token, buffer); > + } else if (token->ident == &__COUNTER___ident) { > + static int counter; > + > + replace_with_integer(token, counter++); This should not use a static counter. GCC and Sparse can run over more than one file in one invocation: $ head test1.c test2.c ==> test1.c <== __COUNTER__ __COUNTER__ ==> test2.c <== __COUNTER__ __COUNTER__ $ gcc -E test1.c test2.c # 1 "test1.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "test1.c" 0 1 # 1 "test2.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "test2.c" 0 1 Notice that the second file starts with __COUNTER__ at 0 again. The counter *should* keep counting through include files, but needs to reset before starting a new top-level compile. - Josh Triplett -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html