On Mon, Jan 09, 2017 at 12:18:01PM +0100, Jakub Jelinek wrote: > On Mon, Jan 09, 2017 at 10:21:47AM +0100, Marek Polacek wrote: > > +/* Callback function to determine whether an expression TP or one of its > > + subexpressions comes from macro expansion. Used to suppress bogus > > + warnings. */ > > + > > +static tree > > +expr_from_macro_expansion_r (tree *tp, int *, void *) > > +{ > > + if (CAN_HAVE_LOCATION_P (*tp) > > + && from_macro_expansion_at (EXPR_LOCATION (*tp))) > > + return integer_zero_node; > > + > > + return NULL_TREE; > > +} > > I know this is hard issue, but won't it disable the warning way too often? > > Perhaps it is good enough for the initial version (GCC 7), but doesn't it stop > whenever one uses NULL in the branches, or some other trivial macros like > that? Perhaps we want to do the analysis if there is anything from macro > expansion side-by-side on both the expressions and if you find something > from a macro expansion, then still warn if both corresponding expressions > are from the same macro expansion (either only non-function like one, or > perhaps also function-like one with the same arguments, if it is possible > to figure out those somehow)? And perhaps it would be nice to choose > warning level, whether you want to warn only under these rules (no macros > or something smarter if implemented) vs. some certainly non-default more > aggressive mode that will just warn no matter what macros there are.
I agree that not warning for if (foo) return NULL; else return NULL; is bad. But how can I compare those expressions side-by-side? I'm not finding anything. :( As for the idea of multiple levels, sure, I could do that, although I'd prefer to get the initial version in first. Marek