summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/branches.c
blob: df3b7c052beaea6d273e006d278fc95c736d34c5 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Tests for single stepping through various branch conditions */

int noscramble(int a)
{
  return a ;
}

int echo(int a)
{ return noscramble(a) ; }

int equaltest(int a,int b)
{ int retval ;
  if (a == b)
    retval = noscramble(1) ;
  else retval = noscramble(0) ;
  return retval ;
}

int neqtest(int a , int b)
{ int retval ;
  if (a != b)
    retval = echo(1) ;
  else retval = echo(2) ;
  return retval ;
}
int zerotest(int a )
{ int retval ;
  a = echo(a) ;
  if (a ==0)
    retval = echo(1) ;
  else
    retval = echo(0) ;
  retval = echo(retval) ;
  return retval ;
}

int zerotest2(int a)
{
  return (a==0) ;
}

int nonzerotest(int a)
{
  int retval ;
  if (a != 0)
    retval = echo(0) ;
  else retval = echo(1) ;
  return retval ;
}

int whiletest(int a)
{
  while (a > 0)
    {
      a-- ;
    }
  return 0 ;
}
int whiletest2(int a)
{
  while (a > 0)
    {
      a = noscramble(a) ;
      a-- ;
    }
  return a ;
}

int decr(int x) { return x - 1  ; }

int while3(int a)
{
  int b = a ;
  while (a == b)
    {
      a = echo(a) ;
      b = decr(b) ;
    }
  return a ;
}

void done (int x) { } 

int main()
{
  int a,b,c,d ;
  done(1) ;
  a = echo(123456) ;
  b = echo(123456) ;
  c = echo(56789) ;
  d = echo(0) ;
#if 1
  equaltest(a,b) ;
  done(7) ;
  equaltest(a,c) ;
  done(8) ;
  whiletest(3) ;  /* worked */
  done(3) ;
  while3(3) ;
  done(6) ;
#endif  
  neqtest(a,b) ; 
  neqtest(a,b) ; 
  neqtest(a,c) ; 
  zerotest(d) ;
  zerotest(a) ;
  done(5) ;
  nonzerotest(d) ;
  done(4) ;
  nonzerotest(a) ;
  done(111) ;
  return 1 ;
}