@@ -213,6 +213,67 @@ FixedPointArithmeticTraps.test("Remainder/${IntTy}.min-mod-minus-one") {
213
213
214
214
% end
215
215
216
+ % for (description, operation) in [("RightShift", ">>"), ("LeftShift", "<<")]:
217
+
218
+ //
219
+ // Test ${description} for ${IntTy}
220
+ //
221
+
222
+ % if signedness == 'signed':
223
+
224
+ FixedPointArithmeticTraps.test("${description}/${IntTy}/Negative") {
225
+ var a = get${IntTy}(${IntTy}.max / 3)
226
+
227
+ a = get${IntTy}(a ${operation} get${IntTy}(1))
228
+
229
+ let shiftAmount: ${IntTy} = -1
230
+
231
+ // Overflow in ${description}.
232
+ expectCrashLater()
233
+ a = a ${operation} get${IntTy}(shiftAmount)
234
+ }
235
+
236
+ % end
237
+
238
+ FixedPointArithmeticTraps.test("${description}/${IntTy}/TypeSize") {
239
+ var a = get${IntTy}(${IntTy}.max / 3)
240
+
241
+ a = get${IntTy}(a ${operation} get${IntTy}(0))
242
+ a = get${IntTy}(a ${operation} get${IntTy}(1))
243
+
244
+ let shiftAmount = ${IntTy}(sizeof(${IntTy}.self) * 8)
245
+
246
+ // Overflow in ${description}.
247
+ expectCrashLater()
248
+ a = a ${operation} get${IntTy}(shiftAmount)
249
+ }
250
+
251
+ FixedPointArithmeticTraps.test("${description}/${IntTy}/TypeSizePlusOne") {
252
+ var a = get${IntTy}(${IntTy}.max / 3)
253
+
254
+ a = get${IntTy}(a ${operation} get${IntTy}(0))
255
+
256
+ let shiftAmount = ${IntTy}(sizeof(${IntTy}.self) * 8 + 1)
257
+
258
+ // Overflow in ${description}.
259
+ expectCrashLater()
260
+ a = a ${operation} get${IntTy}(shiftAmount)
261
+ }
262
+
263
+ FixedPointArithmeticTraps.test("${description}/${IntTy}/Max") {
264
+ var a = get${IntTy}(${IntTy}.max / 3)
265
+
266
+ a = get${IntTy}(a ${operation} get${IntTy}(0))
267
+
268
+ let shiftAmount: ${IntTy} = ${IntTy}.max
269
+
270
+ // Overflow in ${description}.
271
+ expectCrashLater()
272
+ a = a ${operation} get${IntTy}(shiftAmount)
273
+ }
274
+
275
+ % end
276
+
216
277
// This comment prevents gyb from miscompiling this file.
217
278
// <rdar://problem/17548877> gyb miscompiles a certain for loop
218
279
0 commit comments