1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s
2 
3 unsigned int ui, uj, uk;
4 int i, j, k;
5 
6 // CHECK-LABEL: define void @test0()
test0()7 void test0() {
8   // -ftrapv doesn't affect unsigned arithmetic.
9   // CHECK:      [[T1:%.*]] = load i32, i32* @uj
10   // CHECK-NEXT: [[T2:%.*]] = load i32, i32* @uk
11   // CHECK-NEXT: [[T3:%.*]] = add i32 [[T1]], [[T2]]
12   // CHECK-NEXT: store i32 [[T3]], i32* @ui
13   ui = uj + uk;
14 
15   // CHECK:      [[T1:%.*]] = load i32, i32* @j
16   // CHECK-NEXT: [[T2:%.*]] = load i32, i32* @k
17   // CHECK-NEXT: [[T3:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 [[T2]])
18   // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T3]], 0
19   // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T3]], 1
20   // CHECK-NEXT: [[T6:%.*]] = xor i1 [[T5]], true
21   // CHECK-NEXT: br i1 [[T6]]
22   // CHECK:      call void @llvm.trap()
23   i = j + k;
24 }
25 
26 // CHECK-LABEL: define void @test1()
test1()27 void test1() {
28   extern void opaque(int);
29   opaque(i++);
30 
31   // CHECK:      [[T1:%.*]] = load i32, i32* @i
32   // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
33   // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
34   // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
35   // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
36   // CHECK-NEXT: br i1 [[T5]]
37   // CHECK:      call void @llvm.trap()
38 }
39 
40 // CHECK-LABEL: define void @test2()
test2()41 void test2() {
42   extern void opaque(int);
43   opaque(++i);
44 
45   // CHECK:      [[T1:%.*]] = load i32, i32* @i
46   // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
47   // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
48   // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
49   // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
50   // CHECK-NEXT: br i1 [[T5]]
51   // CHECK:      call void @llvm.trap()
52 }
53 
54 // CHECK-LABEL: define void @test3(
test3(int a,int b,float c,float d)55 void test3(int a, int b, float c, float d) {
56   // CHECK-NOT:  @llvm.trap
57   (void)(a / b);
58   (void)(a % b);
59   (void)(c / d);
60   // CHECK: }
61 }
62