(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
Wduplicated-cond-2.c
       1  /* PR c/64249 */
       2  /* { dg-do compile } */
       3  /* { dg-options "-Wall" } */
       4  /* { dg-skip-if "PR67819" { *-*-* } } */
       5  
       6  #ifndef __cplusplus
       7  # define bool _Bool
       8  # define true 1
       9  # define false 0
      10  #endif
      11  
      12  extern int foo (void);
      13  
      14  int
      15  fn1 (int n)
      16  {
      17    if (n == 1) /* { dg-message "previously used here" } */
      18      return -1;
      19    else if (n == 2)
      20      return 0;
      21    else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
      22      return 1;
      23    return 0;
      24  }
      25  
      26  int
      27  fn2 (void)
      28  {
      29    if (4)
      30      return 1;
      31    else if (4)
      32      return 2;
      33  
      34  #define N 10
      35    if (N)
      36      return 3;
      37    else if (N)
      38      return 4;
      39  }
      40  
      41  int
      42  fn3 (int n)
      43  {
      44    if (n == 42)
      45      return 1;
      46    if (n == 42)
      47      return 2;
      48  
      49    if (n)
      50      if (n)
      51        if (n)
      52  	if (n)
      53  	  return 42;
      54  
      55    if (!n)
      56      return 10;
      57    else
      58      return 11;
      59  }
      60  
      61  int
      62  fn4 (int n)
      63  {
      64    if (n > 0)
      65      {
      66        if (n == 1) /* { dg-message "previously used here" } */
      67  	return 1;
      68        else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
      69  	return 2;
      70      }
      71    else if (n < 0)
      72      {
      73        if (n < -1)
      74  	return 6;
      75        else if (n < -2)
      76  	{
      77  	  if (n == -10) /* { dg-message "previously used here" } */
      78  	    return 3;
      79  	  else if (n == -10) /* { dg-warning "duplicated .if. condition" } */
      80  	    return 4;
      81  	}
      82      }
      83    else
      84      return 7;
      85    return 0;
      86  }
      87  
      88  struct S { long p, q; };
      89  
      90  int
      91  fn5 (struct S *s)
      92  {
      93    if (!s->p) /* { dg-message "previously used here" } */
      94      return 12345;
      95    else if (!s->p) /* { dg-warning "duplicated .if. condition" } */
      96      return 1234;
      97    return 0;
      98  }
      99  
     100  int
     101  fn6 (int n)
     102  {
     103    if (n) /* { dg-message "previously used here" } */
     104      return n;
     105    else if (n) /* { dg-warning "duplicated .if. condition" } */
     106      return n;
     107    else if (n) /* { dg-warning "duplicated .if. condition" } */
     108      return n;
     109    else if (n) /* { dg-warning "duplicated .if. condition" } */
     110      return n;
     111    else if (n) /* { dg-warning "duplicated .if. condition" } */
     112      return n;
     113    else if (n) /* { dg-warning "duplicated .if. condition" } */
     114      return n;
     115    else if (n) /* { dg-warning "duplicated .if. condition" } */
     116      return n;
     117    else if (n) /* { dg-warning "duplicated .if. condition" } */
     118      return n;
     119    return 0;
     120  }
     121  
     122  int
     123  fn7 (int n)
     124  {
     125    if (n == 0) /* { dg-message "previously used here" } */
     126      return 10;
     127    else if (n == 1) /* { dg-message "previously used here" } */
     128      return 11;
     129    else if (n == 2) /* { dg-message "previously used here" } */
     130      return 12;
     131    else if (n == 3) /* { dg-message "previously used here" } */
     132      return 13;
     133    else if (n == 4) /* { dg-message "previously used here" } */
     134      return 14;
     135    else if (n == 5) /* { dg-message "previously used here" } */
     136      return 15;
     137    else if (n == 6) /* { dg-message "previously used here" } */
     138      return 16;
     139    else if (n == 7) /* { dg-message "previously used here" } */
     140      return 17;
     141    else if (n == 0) /* { dg-warning "duplicated .if. condition" } */
     142      return 100;
     143    else if (n == 1) /* { dg-warning "duplicated .if. condition" } */
     144      return 101;
     145    else if (n == 2) /* { dg-warning "duplicated .if. condition" } */
     146      return 102;
     147    else if (n == 3) /* { dg-warning "duplicated .if. condition" } */
     148      return 103;
     149    else if (n == 4) /* { dg-warning "duplicated .if. condition" } */
     150      return 104;
     151    else if (n == 5) /* { dg-warning "duplicated .if. condition" } */
     152      return 105;
     153    else if (n == 6) /* { dg-warning "duplicated .if. condition" } */
     154      return 106;
     155    else if (n == 7) /* { dg-warning "duplicated .if. condition" } */
     156      return 107;
     157    return 0;
     158  }
     159  
     160  int
     161  fn8 (bool b)
     162  {
     163    if (!b) /* { dg-message "previously used here" } */
     164      return 16;
     165    else if (!b) /* { dg-warning "duplicated .if. condition" } */
     166      return 27;
     167    else
     168      return 64;
     169  }
     170  
     171  int
     172  fn9 (int i, int j, int k)
     173  {
     174    if (i > 0 && j > 0 && k > 0) /* { dg-message "previously used here" } */
     175      return -999;
     176    else
     177    if (i > 0 && j > 0 && k > 0) /* { dg-warning "duplicated .if. condition" } */
     178      return 999;
     179    else
     180      return 0;
     181  }
     182  
     183  int
     184  fn10 (void)
     185  {
     186    if (foo ())
     187      return 1732984;
     188    else if (foo ())
     189      return 18409;
     190    return 0;
     191  }
     192  
     193  int
     194  fn11 (int n)
     195  {
     196    if (++n == 10)
     197      return 666;
     198    else if (++n == 10)
     199      return 9;
     200    return 0;
     201  }