https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82963
Bug ID: 82963 Summary: -Waddress too trigger happy Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mhocko at kernel dot org Target Milestone: --- Hi, in the kernel we have a uggly^Wmacro to help printing numa mask defined as follows #define nodemask_pr_args(maskp) MAX_NUMNODES : (maskp)->bits I have updated it to allow NULL maskp as follows #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL but this has triggered warnings on usage where it is clear that maskp is never NULL. E.g. In file included from include/linux/mmzone.h:17:0, from include/linux/mempolicy.h:10, from mm/mempolicy.c:70: mm/mempolicy.c: In function 'mpol_to_str': include/linux/nodemask.h:107:41: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); ^ include/linux/nodemask.h:107:69: warning: the address of 'nodes' will always evaluate as 'true' [-Waddress] #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL ^ mm/mempolicy.c:2817:11: note: in expansion of macro 'nodemask_pr_args' nodemask_pr_args(&nodes)); While the warning is correct and the given mask will always resolve to the success path of the ternary operator I really fail to see why we should warn about this fact. I really do not see any potential problem which could be caused by this fact. Moreover the warning itself is quite inconsistent. E.g. the following warns about the explicit &m but not for n. So I believe this is more of a suboptimal warning implementation than real intention. #include <stdio.h> #define MAX_NUMNODES 10 struct mask { void *bits; }; #define nodemask_pr_args(maskp) (maskp) ? MAX_NUMNODES : 0, (maskp) ? (maskp)->bits : NULL int foo(void) { struct mask m; struct mask *n = &m; printf("%*p\n", nodemask_pr_args(&m)); printf("%*p\n", nodemask_pr_args(n)); return 0; }