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