--- gcc/testsuite/c-c++-common/Wduplicated-branches-1.c +++ gcc/testsuite/c-c++-common/Wduplicated-branches-1.c @@ -0,0 +1,187 @@ +/* PR c/64279 */ +/* { dg-do compile } */ +/* { dg-options "-Wduplicated-branches -O2" } */ + +extern void foo (int); +extern int g; +extern int a[10]; + +int +f (int i, int *p) +{ + const int j = 0; + if (j == 0) + { + if (i > 10) /* { dg-warning "this condition has identical branches" } */ + /* Optimizers can figure out that this is 1. */ + *p = j * 2 + 1; + else + *p = 1; + }
I wonder if this test case (perhaps with a slight modification) illustrates the concern Jeff raised. Suppose j is an argument to the function whose value of zero is determined by constant propagation. Such code is not uncommon but will presumably be diagnosed, which in all likelihood will be considered a false positive. I don't have a sense of how pervasive such cases might be. Do you have any data from projects other than GCC? (Since there are no fixes in the patch I assume it didn't find any bugs in GCC itself.) Martin