This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Implement -Wduplicated-branches (PR c/64279)


--- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]