blob: f52dad55648586903c4d224bdfdec2f22419e8ba [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
John McCall401be6b2010-08-05 17:39:44 +000020 // CHECK-NEXT: br i1 [[T5]]
Chris Lattner93a00352010-08-07 00:20:46 +000021 // CHECK: call void @llvm.trap()
Mike Stump947b3e22009-04-02 01:14:26 +000022 i = j + k;
23}
John McCall401be6b2010-08-05 17:39:44 +000024
25// CHECK: define void @test1()
26void test1() {
27 extern void opaque(int);
28 opaque(i++);
29
30 // CHECK: [[T1:%.*]] = load i32* @i
Chris Lattner9cbe4f02011-07-09 17:41:47 +000031 // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
32 // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
33 // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
John McCall401be6b2010-08-05 17:39:44 +000034 // CHECK-NEXT: br i1 [[T4]]
Chris Lattner93a00352010-08-07 00:20:46 +000035 // CHECK: call void @llvm.trap()
John McCall401be6b2010-08-05 17:39:44 +000036}
37
38// CHECK: define void @test2()
39void test2() {
40 extern void opaque(int);
41 opaque(++i);
42
43 // CHECK: [[T1:%.*]] = load i32* @i
Chris Lattner9cbe4f02011-07-09 17:41:47 +000044 // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
45 // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
46 // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
John McCall401be6b2010-08-05 17:39:44 +000047 // CHECK-NEXT: br i1 [[T4]]
Chris Lattner93a00352010-08-07 00:20:46 +000048 // CHECK: call void @llvm.trap()
John McCall401be6b2010-08-05 17:39:44 +000049}