1  #include <stdlib.h>
       2  #include "analyzer-decls.h"
       3  
       4  /* Verify that ordering of writes doesn't matter when merging states.  */
       5  
       6  /* Test with locals.  */
       7  
       8  void test_1 (int flag)
       9  {
      10    int a, b;
      11    if (flag)
      12      {
      13        a = 3;
      14        b = 4;
      15      }
      16    else
      17      {
      18        b = 4;
      19        a = 3;
      20      }
      21  
      22    __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
      23    __analyzer_eval (a == 3); /* { dg-warning "TRUE" } */
      24    __analyzer_eval (b == 4); /* { dg-warning "TRUE" } */
      25  }
      26  
      27  /* Test with globals.  */
      28  
      29  int f, g, h;
      30  void test_2 (int flag)
      31  {
      32    if (flag)
      33      {
      34        f = 3;
      35        g = 4;
      36      }
      37    else
      38      {
      39        g = 4;
      40        f = 3;
      41      }
      42  
      43    __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
      44    __analyzer_eval (f == 3); /* { dg-warning "TRUE" } */
      45    __analyzer_eval (g == 4); /* { dg-warning "TRUE" } */
      46  }
      47  
      48  /* All 6 orderings of writes to 3 globals.  */
      49  
      50  void test_3 (int i)
      51  {
      52    switch (i)
      53      {
      54      default:
      55      case 0:
      56        f = 3;
      57        g = 4;
      58        h = 5;
      59        break;
      60  
      61      case 1:
      62        f = 3;
      63        h = 5;
      64        g = 4;
      65        break;
      66  
      67      case 2:
      68        g = 4;
      69        f = 3;
      70        h = 5;
      71        break;
      72  
      73      case 3:
      74        g = 4;
      75        h = 5;
      76        f = 3;
      77        break;
      78  
      79      case 4:
      80        h = 5;
      81        f = 3;
      82        g = 4;
      83        break;
      84  
      85      case 5:
      86        h = 5;
      87        g = 4;
      88        f = 3;
      89        break;
      90      }
      91  
      92    __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
      93    __analyzer_eval (f == 3); /* { dg-warning "TRUE" } */
      94    __analyzer_eval (g == 4); /* { dg-warning "TRUE" } */
      95    __analyzer_eval (h == 5); /* { dg-warning "TRUE" } */
      96  }
      97  
      98  void test_4 (int flag)
      99  {
     100    void *p, *q;
     101    if (flag)
     102      {
     103        p = malloc (256);
     104        q = malloc (256);
     105      }
     106    else
     107      {
     108        q = malloc (256);
     109        p = malloc (256);
     110      }
     111    __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enode" } */
     112    free (p);
     113    free (q);
     114  }