Implement -Wduplicated-branches (PR c/64279) (v3)
Marek Polacek
polacek@redhat.com
Thu Jan 19 16:53:00 GMT 2017
On Mon, Jan 09, 2017 at 02:39:30PM +0100, Marek Polacek wrote:
> 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. :(
Seems like ENOTIME to address this; will you be ok with the patch as-is
(modulo Jeff comments), if I open a PR about the above test case?
Thanks,
Marek
More information about the Gcc-patches
mailing list