1  #include "analyzer-decls.h"
       2  
       3  struct coord
       4  {
       5    int x;
       6    int y;
       7  };
       8  
       9  /* Copying from one on-stack array to another.  */
      10  
      11  void test_1 (void)
      12  {
      13    struct coord arr_a[16];
      14    struct coord arr_b[16];
      15    arr_a[3].x = 5;
      16    arr_a[3].y = 6;
      17  
      18    arr_b[7] = arr_a[3];
      19  
      20    __analyzer_eval (arr_b[7].x == 5); /* { dg-warning "TRUE" } */
      21    __analyzer_eval (arr_b[7].y == 6); /* { dg-warning "TRUE" } */
      22  }
      23  
      24  /* Copying from an on-stack array to a global array.  */
      25  
      26  struct coord glob_arr[16];
      27  
      28  void test_2 (void)
      29  {
      30    struct coord arr[16];
      31    arr[3].x = 5;
      32    arr[3].y = 6;
      33  
      34    glob_arr[7] = arr[3];
      35  
      36    __analyzer_eval (glob_arr[7].x == 5); /* { dg-warning "TRUE" } */
      37    __analyzer_eval (glob_arr[7].y == 6); /* { dg-warning "TRUE" } */
      38  }
      39  
      40  /* Copying from a partially initialized on-stack array to a global array.  */
      41  
      42  struct coord glob_arr[16];
      43  
      44  void test_3 (void)
      45  {
      46    struct coord arr[16];
      47    arr[3].y = 6;
      48  
      49    glob_arr[7] = arr[3]; // or should the uninit warning be here?
      50  
      51    __analyzer_eval (glob_arr[7].x); /* { dg-warning "uninitialized" "uninit" { xfail *-*-* } } */
      52    /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
      53    __analyzer_eval (glob_arr[7].y == 6); /* { dg-warning "TRUE" } */
      54  }
      55  
      56  /* Symbolic bindings: copying from one array to another.  */
      57  
      58  struct coord glob_arr[16];
      59  
      60  void test_4 (int i)
      61  {
      62    struct coord arr_a[16];
      63    struct coord arr_b[16];
      64    arr_a[i].x = 5;
      65    arr_a[i].y = 6;
      66    __analyzer_eval (arr_a[i].x == 5); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
      67    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
      68    __analyzer_eval (arr_a[i].y == 6); /* { dg-warning "TRUE" } */
      69  
      70    arr_b[i] = arr_a[i];
      71  
      72    __analyzer_eval (arr_b[i].x == 5); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
      73    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
      74    __analyzer_eval (arr_b[i].y == 6); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
      75    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
      76  }
      77  
      78  /* Symbolic bindings: copying within an array: symbolic src and dest  */
      79  
      80  struct coord glob_arr[16];
      81  
      82  void test_5a (int i, int j)
      83  {
      84    struct coord arr[16];
      85    arr[i].x = 5;
      86    arr[i].y = 6;
      87  
      88    arr[j] = arr[i];
      89  
      90    __analyzer_eval (arr[j].x == 5); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
      91    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
      92    __analyzer_eval (arr[j].y == 6); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
      93    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
      94  }
      95  
      96  /* Symbolic bindings: copying within an array: symbolic src, concrete dest.  */
      97  
      98  struct coord glob_arr[16];
      99  
     100  void test_5b (int i)
     101  {
     102    struct coord arr[16];
     103    arr[i].x = 5;
     104    arr[i].y = 6;
     105  
     106    arr[3] = arr[i];
     107  
     108    __analyzer_eval (arr[3].x == 5); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
     109    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
     110    __analyzer_eval (arr[3].y == 6); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
     111    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
     112  }
     113  
     114  /* Symbolic bindings: copying within an array: concrete src, symbolic dest.  */
     115  
     116  struct coord glob_arr[16];
     117  
     118  void test_5c (int i)
     119  {
     120    struct coord arr[16];
     121    arr[3].x = 5;
     122    arr[3].y = 6;
     123  
     124    arr[i] = arr[3];
     125  
     126    __analyzer_eval (arr[i].x == 5); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
     127    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
     128    __analyzer_eval (arr[i].y == 6); /* { dg-warning "TRUE" "TRUE" { xfail *-*-* } } */
     129    /* { dg-bogus "UNKNOWN" "UNKNOWN" { xfail *-*-* } .-1 } */
     130  }
     131  
     132  /* No info on the subregion being copied, and hence
     133     binding_cluster2::maybe_get_compound_binding should return NULL.  */
     134  
     135  void test_6 (void)
     136  {
     137    struct coord arr[16];
     138    arr[7] = glob_arr[3];
     139  
     140    __analyzer_eval (arr[7].x == 5); /* { dg-warning "UNKNOWN" } */
     141    __analyzer_eval (arr[7].y == 6); /* { dg-warning "UNKNOWN" } */
     142  }