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
12 extern void abort(void);
13 extern long labs(long);
14
15 int __attribute__((noinline))
iabsv(int a)16 iabsv(int a)
17 {
18 return abs(a);
19 }
20
21 int __attribute__((noinline))
iaddv(int a,int b)22 iaddv(int a, int b)
23 {
24 return a + b;
25 }
26
27 int __attribute__((noinline))
isubv(int a,int b)28 isubv(int a, int b)
29 {
30 return a - b;
31 }
32
33 int __attribute__((noinline))
imulv(int a,int b)34 imulv(int a, int b)
35 {
36 return a * b;
37 }
38
39 int __attribute__((noinline))
inegv(int a)40 inegv(int a)
41 {
42 return -a;
43 }
44
45 long __attribute__((noinline))
labsv(long a)46 labsv(long a)
47 {
48 return labs(a);
49 }
50
51 long __attribute__((noinline))
laddv(long a,long b)52 laddv(long a, long b)
53 {
54 return a + b;
55 }
56
57 long __attribute__((noinline))
lsubv(long a,long b)58 lsubv(long a, long b)
59 {
60 return a - b;
61 }
62
63 long __attribute__((noinline))
lmulv(long a,long b)64 lmulv(long a, long b)
65 {
66 return a * b;
67 }
68
69 long __attribute__((noinline))
lnegv(long a)70 lnegv(long a)
71 {
72 return -a;
73 }
74
main(void)75 int main(void)
76 {
77 if (iabsv (-1) != 1)
78 abort ();
79
80 if (iaddv (2,-3) != -1)
81 abort ();
82
83 if (isubv (2,3) != -1)
84 abort ();
85
86 if (imulv (-2,3) != -6)
87 abort ();
88
89 if (inegv (-1) != 1)
90 abort ();
91
92 if (labsv (-1L) != 1L)
93 abort ();
94
95 if (laddv (2L,-3L) != -1L)
96 abort ();
97
98 if (lsubv (2L,3L) != -1L)
99 abort ();
100
101 if (lmulv (-2L,3L) != -6L)
102 abort ();
103
104 if (lnegv (-1L) != 1L)
105 abort ();
106
107 return 0;
108 }
109