2 /* { dg-options "-Wno-psabi -fsanitize=signed-integer-overflow -Wno-unused-variable -fsanitize-recover=signed-integer-overflow" } */
4 #define SCHAR_MAX __SCHAR_MAX__
5 #define SCHAR_MIN (-__SCHAR_MAX__ - 1)
6 #define SHRT_MAX __SHRT_MAX__
7 #define SHRT_MIN (-__SHRT_MAX__ - 1)
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-__INT_MAX__ - 1)
11 typedef signed char VC
__attribute__((vector_size (16)));
12 typedef short VS
__attribute__((vector_size (8 * sizeof (short))));
13 typedef int VI
__attribute__((vector_size (4 * sizeof (int))));
14 typedef int VI2
__attribute__((vector_size (16 * sizeof (int))));
16 void __attribute__((noinline
,noclone
))
19 if (__builtin_memcmp (&i
, &j
, sizeof (VC
)))
23 void __attribute__((noinline
,noclone
))
26 if (__builtin_memcmp (&i
, &j
, sizeof (VS
)))
30 void __attribute__((noinline
,noclone
))
33 if (__builtin_memcmp (&i
, &j
, sizeof (VI
)))
37 void __attribute__((noinline
,noclone
))
38 checkvi2 (VI2 i
, VI2 j
)
40 if (__builtin_memcmp (&i
, &j
, sizeof (VI2
)))
44 VI
__attribute__((noinline
,noclone
))
50 VS
__attribute__((noinline
,noclone
))
59 /* Check that for a vector operation, only the first element with UB is reported. */
60 volatile VC a
= (VC
) { 0, SCHAR_MAX
- 2, SCHAR_MAX
- 2, 3, 2, 3, 4, 5, 0, 7, 1, 2, 3, 4, SCHAR_MAX
- 13, SCHAR_MAX
};
61 volatile VC b
= (VC
) { 5, 2, 3, 5, 0, 1, 2, 7, 8, 9, 10, 11, 6, -2, 13, 1 };
62 volatile VC k
= b
+ a
;
63 checkvc (k
, (VC
) { 5, SCHAR_MAX
, SCHAR_MIN
, 8, 2, 4, 6, 12, 8, 16, 11, 13, 9, 2, SCHAR_MAX
, SCHAR_MIN
});
65 checkvc (k
, (VC
) { 5, SCHAR_MAX
, SCHAR_MIN
, 8, 2, 4, 6, 12, 8, 16, 11, 13, 9, 2, SCHAR_MAX
, SCHAR_MIN
});
67 volatile VS c
= (VS
) { 0, SHRT_MAX
- 2, SHRT_MAX
- 2, 3, 3, 4, SHRT_MAX
- 13, SHRT_MAX
};
68 volatile VS d
= (VS
) { 5, 2, 3, 5, 6, -2, 13, 1 };
69 volatile VS l
= d
+ c
;
70 checkvs (l
, (VS
) { 5, SHRT_MAX
, SHRT_MIN
, 8, 9, 2, SHRT_MAX
, SHRT_MIN
});
72 checkvs (l
, (VS
) { 5, SHRT_MAX
, SHRT_MIN
, 8, 9, 2, SHRT_MAX
, SHRT_MIN
});
74 volatile VI e
= (VI
) { INT_MAX
- 4, INT_MAX
- 5, INT_MAX
- 13, INT_MAX
};
75 volatile VI f
= (VI
) { 4, 6, 13, 1 };
76 volatile VI m
= f
+ e
;
77 checkvi (m
, (VI
) { INT_MAX
, INT_MIN
, INT_MAX
, INT_MIN
});
79 checkvi (m
, (VI
) { INT_MAX
, INT_MIN
, INT_MAX
, INT_MIN
});
81 volatile VI2 g
= (VI2
) { 0, INT_MAX
- 2, INT_MAX
- 2, 3, 3, 4, INT_MAX
- 13, INT_MAX
};
82 volatile VI2 h
= (VI2
) { 5, 2, 3, 5, 6, -2, 13, 1 };
83 volatile VI2 n
= h
+ g
;
84 checkvi2 (n
, (VI2
) { 5, INT_MAX
, INT_MIN
, 8, 9, 2, INT_MAX
, INT_MIN
});
86 checkvi2 (n
, (VI2
) { 5, INT_MAX
, INT_MIN
, 8, 9, 2, INT_MAX
, INT_MIN
});
88 volatile VC a2
= k
- b
;
90 volatile VC b2
= k
- a
;
93 volatile VS c2
= l
- d
;
95 volatile VS d2
= l
- c
;
98 volatile VI e2
= m
- f
;
100 volatile VI f2
= m
- e
;
103 volatile VI2 g2
= n
- h
;
105 volatile VI2 h2
= n
- g
;
108 a
= (VC
) { 0, SCHAR_MAX
/ 4, SCHAR_MAX
/ 4, 3, 2, 3, 4, 5, 0, 7, 1, 2, 3, 4, SCHAR_MAX
- 13, SCHAR_MAX
};
109 b
= (VC
) { SCHAR_MAX
, 4, 5, 2, 3, 4, 5, 2, 9, 2, 9, 1, 0, 8, 1, 2 };
111 checkvc (k
, (VC
) { 0, 124, -101, 6, 6,12,20,10, 0,14, 9, 2, 0,32, SCHAR_MAX
- 13, -2 });
113 c
= (VS
) { 0, SHRT_MAX
/ 8, SHRT_MAX
/ 7, 5, 8, 9, SHRT_MAX
- 10, SHRT_MAX
};
114 d
= (VS
) { SHRT_MAX
, 8, 17, 2, 3, 4, 1, 3 };
116 checkvs (l
, (VS
) { 0, 32760, 14041, 10,24,36, SHRT_MAX
- 10, 32765 });
118 e
= (VI
) { INT_MAX
, INT_MAX
/ 5, INT_MAX
/ 6, INT_MAX
};
119 f
= (VI
) { 0, 5, 7, 2 };
121 checkvi (m
, (VI
) { 0, 2147483645, -1789569709, -2 });
123 g
= (VI2
) { INT_MAX
, INT_MAX
/ 9, INT_MAX
/ 8, 5, 6, 7, 8, INT_MAX
};
124 h
= (VI2
) { 0, 10, 8, 2, 3, 4, 5, 1 };
126 checkvi2 (n
,(VI2
) { 0, -1908874356, 2147483640, 10,18,28,40, INT_MAX
});
128 a
= (VC
) { 5, 7, 8, 9, SCHAR_MAX
, SCHAR_MIN
, 24, 32, 0, 1, 2, 3, 4, 5, SCHAR_MAX
, SCHAR_MIN
};
130 checkvc (k
, (VC
) {-5,-7,-8,-9,-SCHAR_MAX
, SCHAR_MIN
,-24,-32, 0,-1,-2,-3,-4,-5,-SCHAR_MAX
, SCHAR_MIN
});
132 c
= (VS
) { 0, 7, 23, SHRT_MIN
, SHRT_MIN
, SHRT_MAX
, 2, 5 };
134 checkvs (l
, (VS
) { 0,-7,-23, SHRT_MIN
, SHRT_MIN
,-SHRT_MAX
,-2,-5 });
136 e
= (VI
) { 5, INT_MAX
, INT_MIN
, INT_MIN
};
138 checkvi (m
, (VI
) {-5,-INT_MAX
, INT_MIN
, INT_MIN
});
140 g
= (VI2
) { 10, 11, 0, INT_MAX
- 2, 1, INT_MIN
+ 1, 5, INT_MIN
};
142 checkvi2 (n
, (VI2
) {-10,-11, 0,-INT_MAX
+ 2,-1, INT_MAX
, -5, INT_MIN
});
146 /* { dg-output "signed integer overflow: 3 \\+ 125 cannot be represented in type 'signed char'\[^\n\r]*(\n|\r\n|\r)" } */
147 /* { dg-output "\[^\n\r]*signed integer overflow: 125 \\+ 3 cannot be represented in type 'signed char'\[^\n\r]*(\n|\r\n|\r)" } */
148 /* { dg-output "\[^\n\r]*signed integer overflow: 3 \\+ 32765 cannot be represented in type 'short int'\[^\n\r]*(\n|\r\n|\r)" } */
149 /* { dg-output "\[^\n\r]*signed integer overflow: 32765 \\+ 3 cannot be represented in type 'short int'\[^\n\r]*(\n|\r\n|\r)" } */
150 /* { dg-output "\[^\n\r]*signed integer overflow: 6 \\+ 2147483642 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
151 /* { dg-output "\[^\n\r]*signed integer overflow: 2147483642 \\+ 6 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
152 /* { dg-output "\[^\n\r]*signed integer overflow: 3 \\+ 2147483645 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
153 /* { dg-output "\[^\n\r]*signed integer overflow: 2147483645 \\+ 3 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
154 /* { dg-output "\[^\n\r]*signed integer overflow: -128 - 3 cannot be represented in type 'signed char'\[^\n\r]*(\n|\r\n|\r)" } */
155 /* { dg-output "\[^\n\r]*signed integer overflow: -128 - 125 cannot be represented in type 'signed char'\[^\n\r]*(\n|\r\n|\r)" } */
156 /* { dg-output "\[^\n\r]*signed integer overflow: -32768 - 3 cannot be represented in type 'short int'\[^\n\r]*(\n|\r\n|\r)" } */
157 /* { dg-output "\[^\n\r]*signed integer overflow: -32768 - 32765 cannot be represented in type 'short int'\[^\n\r]*(\n|\r\n|\r)" } */
158 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 6 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
159 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 2147483642 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
160 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 3 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
161 /* { dg-output "\[^\n\r]*signed integer overflow: -2147483648 - 2147483645 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
162 /* { dg-output "\[^\n\r]*signed integer overflow: 31 \\* 5 cannot be represented in type 'signed char'\[^\n\r]*(\n|\r\n|\r)" } */
163 /* { dg-output "\[^\n\r]*signed integer overflow: 4681 \\* 17 cannot be represented in type 'short int'\[^\n\r]*(\n|\r\n|\r)" } */
164 /* { dg-output "\[^\n\r]*signed integer overflow: 357913941 \\* 7 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
165 /* { dg-output "\[^\n\r]*signed integer overflow: 238609294 \\* 10 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */
166 /* { dg-output "\[^\n\r]*negation of -128 cannot be represented in type 'signed char'; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
167 /* { dg-output "\[^\n\r]*negation of -32768 cannot be represented in type 'short int'; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
168 /* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself\[^\n\r]*(\n|\r\n|\r)" } */
169 /* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself" } */