1 /* Copyright (C) 2004 Free Software Foundation.
2
3 PR other/18665
4 Verify that -ftrapv doesn't produce bogus results
5 on 64-bit platforms.
6
7 Written by Eric Botcazou */
8
9 /* { dg-do run } */
10 /* { dg-options "-ftrapv" } */
11 /* { dg-require-effective-target trapping } */
12
13 extern void abort(void);
14 extern int abs(int);
15 extern long labs(long);
16
17 int __attribute__((noinline))
iabsv(int a)18 iabsv(int a)
19 {
20 return abs(a);
21 }
22
23 int __attribute__((noinline))
iaddv(int a,int b)24 iaddv(int a, int b)
25 {
26 return a + b;
27 }
28
29 int __attribute__((noinline))
isubv(int a,int b)30 isubv(int a, int b)
31 {
32 return a - b;
33 }
34
35 int __attribute__((noinline))
imulv(int a,int b)36 imulv(int a, int b)
37 {
38 return a * b;
39 }
40
41 int __attribute__((noinline))
inegv(int a)42 inegv(int a)
43 {
44 return -a;
45 }
46
47 long __attribute__((noinline))
labsv(long a)48 labsv(long a)
49 {
50 return labs(a);
51 }
52
53 long __attribute__((noinline))
laddv(long a,long b)54 laddv(long a, long b)
55 {
56 return a + b;
57 }
58
59 long __attribute__((noinline))
lsubv(long a,long b)60 lsubv(long a, long b)
61 {
62 return a - b;
63 }
64
65 long __attribute__((noinline))
lmulv(long a,long b)66 lmulv(long a, long b)
67 {
68 return a * b;
69 }
70
71 long __attribute__((noinline))
lnegv(long a)72 lnegv(long a)
73 {
74 return -a;
75 }
76
main(void)77 int main(void)
78 {
79 if (iabsv (-1) != 1)
80 abort ();
81
82 if (iaddv (2,-3) != -1)
83 abort ();
84
85 if (isubv (2,3) != -1)
86 abort ();
87
88 if (imulv (-2,3) != -6)
89 abort ();
90
91 if (inegv (-1) != 1)
92 abort ();
93
94 if (labsv (-1L) != 1L)
95 abort ();
96
97 if (laddv (2L,-3L) != -1L)
98 abort ();
99
100 if (lsubv (2L,3L) != -1L)
101 abort ();
102
103 if (lmulv (-2L,3L) != -6L)
104 abort ();
105
106 if (lnegv (-1L) != 1L)
107 abort ();
108
109 return 0;
110 }
111