summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-20040409-3.c
blob: 123c685c0c6a98d4da2bde07221eeb06593c3ea4 (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
   20040409-3.c from the execute part of the gcc torture suite.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

#include <limits.h>

int ftest1(int x)
{
  return ~(x ^ INT_MIN);
}

unsigned int ftest1u(unsigned int x)
{
  return ~(x ^ (unsigned int)INT_MIN);
}

int ftest2(int x)
{
  return ~(x + INT_MIN);
}

unsigned int ftest2u(unsigned int x)
{
  return ~(x + (unsigned int)INT_MIN);
}

int ftest3(int x)
{
  return ~(x - INT_MIN);
}

unsigned int ftest3u(unsigned int x)
{
  return ~(x - (unsigned int)INT_MIN);
}

int ftest4(int x)
{
  int y = INT_MIN;
  return ~(x ^ y);
}

unsigned int ftest4u(unsigned int x)
{
  unsigned int y = (unsigned int)INT_MIN;
  return ~(x ^ y);
}

int ftest5(int x)
{
  int y = INT_MIN;
  return ~(x + y);
}

unsigned int ftest5u(unsigned int x)
{
  unsigned int y = (unsigned int)INT_MIN;
  return ~(x + y);
}

int ftest6(int x)
{
  int y = INT_MIN;
  return ~(x - y);
}

unsigned int ftest6u(unsigned int x)
{
  unsigned int y = (unsigned int)INT_MIN;
  return ~(x - y);
}



void ftest(int a, int b)
{
  if (ftest1(a) != b)
    ASSERT (0);
  if (ftest2(a) != b)
    ASSERT (0);
#ifndef __aarch64__
  if (ftest3(a) != b)
    ASSERT (0);
#endif
  if (ftest4(a) != b)
    ASSERT (0);
  if (ftest5(a) != b)
    ASSERT (0);
#ifndef __aarch64__
  if (ftest6(a) != b)
    ASSERT (0);
#endif
}

void ftestu(unsigned int a, unsigned int b)
{
  if (ftest1u(a) != b)
    ASSERT (0);
  if (ftest2u(a) != b)
    ASSERT (0);
  if (ftest3u(a) != b)
    ASSERT (0);
  if (ftest4u(a) != b)
    ASSERT (0);
  if (ftest5u(a) != b)
    ASSERT (0);
  if (ftest6u(a) != b)
    ASSERT (0);
}


void
testTortureExecute (void)
{
#if INT_MAX == 2147483647
  ftest(0x00000000,0x7fffffff);
  ftest(0x80000000,0xffffffff);
  ftest(0x12345678,0x6dcba987);
  ftest(0x92345678,0xedcba987);
  ftest(0x7fffffff,0x00000000);
  ftest(0xffffffff,0x80000000);

  ftestu(0x00000000,0x7fffffff);
  ftestu(0x80000000,0xffffffff);
  ftestu(0x12345678,0x6dcba987);
  ftestu(0x92345678,0xedcba987);
  ftestu(0x7fffffff,0x00000000);
  ftestu(0xffffffff,0x80000000);
#endif

#if INT_MAX == 32767
  ftest(0x0000,0x7fff);
  ftest(0x8000,0xffff);
  ftest(0x1234,0x6dcb);
  ftest(0x9234,0xedcb);
  ftest(0x7fff,0x0000);
  ftest(0xffff,0x8000);

  ftestu(0x0000,0x7fff);
  ftestu(0x8000,0xffff);
  ftestu(0x1234,0x6dcb);
  ftestu(0x9234,0xedcb);
  ftestu(0x7fff,0x0000);
  ftestu(0xffff,0x8000);
#endif

  return;
}