[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / trapv.c
blob40df9ecb0cd573bdd6ead440ffd7cd41e375458e
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s
3 unsigned int ui, uj, uk;
4 int i, j, k;
6 // CHECK-LABEL: define{{.*}} void @test0()
7 void test0(void) {
8 // -ftrapv doesn't affect unsigned arithmetic.
9 // CHECK: [[T1:%.*]] = load i32, ptr @uj
10 // CHECK-NEXT: [[T2:%.*]] = load i32, ptr @uk
11 // CHECK-NEXT: [[T3:%.*]] = add i32 [[T1]], [[T2]]
12 // CHECK-NEXT: store i32 [[T3]], ptr @ui
13 ui = uj + uk;
15 // CHECK: [[T1:%.*]] = load i32, ptr @j
16 // CHECK-NEXT: [[T2:%.*]] = load i32, ptr @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.ubsantrap(i8 0)
23 i = j + k;
26 // CHECK-LABEL: define{{.*}} void @test1()
27 void test1(void) {
28 extern void opaque(int);
29 opaque(i++);
31 // CHECK: [[T1:%.*]] = load i32, ptr @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.ubsantrap(i8 0)
40 // CHECK-LABEL: define{{.*}} void @test2()
41 void test2(void) {
42 extern void opaque(int);
43 opaque(++i);
45 // CHECK: [[T1:%.*]] = load i32, ptr @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.ubsantrap(i8 0)
54 // CHECK-LABEL: define{{.*}} void @test3(
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: }