On 18 November 2014 17:09, Christopher Li <sparse@xxxxxxxxxxx> wrote: > On Tue, Nov 18, 2014 at 12:24 AM, Ard Biesheuvel > <ard.biesheuvel@xxxxxxxxxx> wrote: >> >> No, the test case looks correct now. You may want to add a conflicting >> definition, for completeness, as that is an important case for sparse >> to verify. >> So you could just add >> >> static void *pure1(void); // conflicting declaration > > Just to confirm. If function declare as non pure then second time > declare as pure, that is a conflict error. That is very different from other > C attributes. C allow function declare attribute incrementally. > > If what you said is true, then pure attribute is actually acting like a modifier > which don't fix not other non pure attribute. > Well, that is how sparse currently treats it, and I think that is correct. If an extern declaration in a .h file specifies __pure, then GCC may legally emit fewer calls to that function than appear in the source. So if the actual implementation in the .c file is not __pure, then you have an error. >> at the bottom, and ensure it is flagged by sparse as an error after >> you make your changes. > > I am curios how does GCC behave on this incremental declare of pure > attribute. I just test it. GCC does not warn on the conflicting declare. > > GCC seems warn on some thing shouldn't warn on the test case: > > function "f2_ok" and "f5" shouldn't been warned. Strange. > > validation/pure-function.c:14:1: warning: '__pure__' attribute ignored > [-Wattributes] > static __attribute__((__pure__)) void*(*f2_ok)(void) = pure1; > ^ > validation/pure-function.c:15:1: warning: '__pure__' attribute ignored > [-Wattributes] > static __attribute__((__pure__)) void*(*f3_error)(void) = non_pure1; > ^ > validation/pure-function.c:29:1: warning: '__pure__' attribute ignored > [-Wattributes] > static __attribute__((__pure__)) int(*f5)(void) = pure2; > ^ > validation/pure-function.c:30:1: warning: '__pure__' attribute ignored > [-Wattributes] > static __attribute__((__pure__)) int(*f6_error)(void) = non_pure2; > My apologies. It appears GCC ignores pure attributes on function pointers, so the assignments are all legal. Sorry to have wasted your time on this. So what remains imo is """ static __attribute__((__pure__)) void *pure1(void) { void *i = (void *)0; return i; } static __attribute__((__pure__)) int pure2(void) { int i = 0; return i; } static int pure2(void); // error here """ and all the other stuff can be dropped. Regards, Ard. -- 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