On Wed, 28 Mar 2018, Jakub Jelinek wrote: > Hi! > > With the introduction of DEBUG_BEGIN_STMT/-gstatement-frontiers on by > default, the -Wduplicated-branches warning doesn't work anymore with -g, > because operand_equal_p in OEP_LEXICOGRAPHIC mode doesn't consider > DEBUG_BEGIN_STMTs as equal unless they are pointer equal. For the warning > we either need to ignore them completely (but that would need more changes, > as the hashing doesn't ignore them), or at least what the second hunk does, > consider them equal. The first hunk is just an optimization, if > -Wduplicated-branches is used on extremely deeply nested STATEMENT_LISTs, > then for -fchecking we'd be computing the hashes etc. at the level of every > stmt of every STATEMENT_LIST; we need to do that just once at the toplevel. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK. Thanks, Richard. > 2018-03-28 Jakub Jelinek <ja...@redhat.com> > > PR c/85094 > * fold-const.c (operand_equal_p): Handle DEBUG_BEGIN_STMT. > For STATEMENT_LIST, pass down OEP_LEXICOGRAPHIC and maybe > OEP_NO_HASH_CHECK for recursive call, to avoid exponential > checking. > > * c-c++-common/Wduplicated-branches-14.c: New test. > > --- gcc/fold-const.c.jj 2018-03-27 12:54:43.657242009 +0200 > +++ gcc/fold-const.c 2018-03-28 16:20:40.024574216 +0200 > @@ -3479,7 +3479,8 @@ operand_equal_p (const_tree arg0, const_ > if (tsi_end_p (tsi1) && tsi_end_p (tsi2)) > return 1; > if (!operand_equal_p (tsi_stmt (tsi1), tsi_stmt (tsi2), > - OEP_LEXICOGRAPHIC)) > + flags & (OEP_LEXICOGRAPHIC > + | OEP_NO_HASH_CHECK))) > return 0; > } > } > @@ -3492,6 +3493,10 @@ operand_equal_p (const_tree arg0, const_ > if (flags & OEP_LEXICOGRAPHIC) > return OP_SAME_WITH_NULL (0); > return 0; > + case DEBUG_BEGIN_STMT: > + if (flags & OEP_LEXICOGRAPHIC) > + return 1; > + return 0; > default: > return 0; > } > --- gcc/testsuite/c-c++-common/Wduplicated-branches-14.c.jj 2018-03-28 > 16:20:00.966553266 +0200 > +++ gcc/testsuite/c-c++-common/Wduplicated-branches-14.c 2018-03-28 > 16:19:07.264524448 +0200 > @@ -0,0 +1,16 @@ > +/* PR c/85094 */ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -Wduplicated-branches -g" } */ > + > +extern int g; > + > +void > +foo (int r) > +{ > + if (r < 64) > + g -= 48; > + else if (r < 80) /* { dg-warning "this condition has identical branches" > } */ > + g -= 64 - 45; > + else > + g -= 80 - 61; > +} > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)