aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/symbolic-2.c
blob: 70c00ce386751d930735eba35b13f8a6f1d9ff78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "analyzer-decls.h"

struct foo
{
  int ival;
  int iarr[10];
};

void test_1 (int i, int j)
{
  struct foo fooarr[4];
  fooarr[1].ival = 42;
  fooarr[1].iarr[3] = 27;
  fooarr[2].iarr[1] = 17;
  __analyzer_eval (fooarr[1].ival == 42); /* { dg-warning "TRUE" } */
  __analyzer_eval (fooarr[1].iarr[3] == 27); /* { dg-warning "TRUE" } */
  __analyzer_eval (fooarr[2].iarr[1] == 17); /* { dg-warning "TRUE" } */

  /* Symbolic binding.  */
  fooarr[2].iarr[i] = j;
  __analyzer_eval (fooarr[2].iarr[i] == j); /* { dg-warning "TRUE" } */

  /* We should have lost our knowledge about fooarr[2].
     It's not clear to me if we should also lose our knowledge about
     fooarr[1] (for the case where i is negative).  For now, we do.  */
  __analyzer_eval (fooarr[1].ival == 42); /* { dg-warning "UNKNOWN" } */
  __analyzer_eval (fooarr[1].iarr[3] == 27); /* { dg-warning "UNKNOWN" } */
  __analyzer_eval (fooarr[2].iarr[1] == 17); /* { dg-warning "UNKNOWN" } */
  /* Should also be safe to read from fooarr[2];
     it isn't known to be uninit anymore.  */
  __analyzer_eval (fooarr[2].iarr[10] == 17); /* { dg-warning "UNKNOWN" } */
}