blob: bc8bc700636c6baffdb00861451e12ce91f32a37 [file] [log] [blame]
John McCall401be6b2010-08-05 17:39:44 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s
2
Mike Stump947b3e22009-04-02 01:14:26 +00003unsigned int ui, uj, uk;
4int i, j, k;
5
John McCall401be6b2010-08-05 17:39:44 +00006// CHECK: define void @test0()
7void test0() {
8 // -ftrapv doesn't affect unsigned arithmetic.
9 // CHECK: [[T1:%.*]] = load i32* @uj
10 // CHECK-NEXT: [[T2:%.*]] = load i32* @uk
11 // CHECK-NEXT: [[T3:%.*]] = add i32 [[T1]], [[T2]]
12 // CHECK-NEXT: store i32 [[T3]], i32* @ui
Mike Stump947b3e22009-04-02 01:14:26 +000013 ui = uj + uk;
John McCall401be6b2010-08-05 17:39:44 +000014
15 // CHECK: [[T1:%.*]] = load i32* @j
16 // CHECK-NEXT: [[T2:%.*]] = load i32* @k
Chris Lattner9cbe4f02011-07-09 17:41:47 +000017 // 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
Richard Smith7ac9ef12012-09-08 02:08:36 +000020 // CHECK-NEXT: [[T6:%.*]] = xor i1 [[T5]], true
21 // CHECK-NEXT: br i1 [[T6]]
Chris Lattner93a00352010-08-07 00:20:46 +000022 // CHECK: call void @llvm.trap()
Mike Stump947b3e22009-04-02 01:14:26 +000023 i = j + k;
24}
John McCall401be6b2010-08-05 17:39:44 +000025
26// CHECK: define void @test1()
27void test1() {
28 extern void opaque(int);
29 opaque(i++);
30
31 // CHECK: [[T1:%.*]] = load i32* @i
Chris Lattner9cbe4f02011-07-09 17:41:47 +000032 // 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
Richard Smith7ac9ef12012-09-08 02:08:36 +000035 // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
36 // CHECK-NEXT: br i1 [[T5]]
Chris Lattner93a00352010-08-07 00:20:46 +000037 // CHECK: call void @llvm.trap()
John McCall401be6b2010-08-05 17:39:44 +000038}
39
40// CHECK: define void @test2()
41void test2() {
42 extern void opaque(int);
43 opaque(++i);
44
45 // CHECK: [[T1:%.*]] = load i32* @i
Chris Lattner9cbe4f02011-07-09 17:41:47 +000046 // 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
Richard Smith7ac9ef12012-09-08 02:08:36 +000049 // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
50 // CHECK-NEXT: br i1 [[T5]]
Chris Lattner93a00352010-08-07 00:20:46 +000051 // CHECK: call void @llvm.trap()
John McCall401be6b2010-08-05 17:39:44 +000052}
Richard Smithbb122432012-11-01 22:13:39 +000053
54// CHECK: define void @test3(
55void 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}