File: trapv.c

package info (click to toggle)
llvm-toolchain-3.4 1%3A3.4.2-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 253,236 kB
  • ctags: 276,203
  • sloc: cpp: 1,665,580; ansic: 298,647; asm: 206,157; objc: 84,350; python: 73,119; sh: 23,466; perl: 5,679; makefile: 5,542; ml: 5,250; pascal: 2,467; lisp: 1,420; xml: 679; cs: 236; csh: 117
file content (61 lines) | stat: -rw-r--r-- 2,034 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -ftrapv %s -emit-llvm -o - | FileCheck %s

unsigned int ui, uj, uk;
int i, j, k;

// CHECK-LABEL: define void @test0()
void test0() {
  // -ftrapv doesn't affect unsigned arithmetic.
  // CHECK:      [[T1:%.*]] = load i32* @uj
  // CHECK-NEXT: [[T2:%.*]] = load i32* @uk
  // CHECK-NEXT: [[T3:%.*]] = add i32 [[T1]], [[T2]]
  // CHECK-NEXT: store i32 [[T3]], i32* @ui
  ui = uj + uk;

  // CHECK:      [[T1:%.*]] = load i32* @j
  // CHECK-NEXT: [[T2:%.*]] = load i32* @k
  // CHECK-NEXT: [[T3:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 [[T2]])
  // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T3]], 0
  // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T3]], 1
  // CHECK-NEXT: [[T6:%.*]] = xor i1 [[T5]], true
  // CHECK-NEXT: br i1 [[T6]]
  // CHECK:      call void @llvm.trap()
  i = j + k;
}

// CHECK-LABEL: define void @test1()
void test1() {
  extern void opaque(int);
  opaque(i++);

  // CHECK:      [[T1:%.*]] = load i32* @i
  // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
  // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
  // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
  // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
  // CHECK-NEXT: br i1 [[T5]]
  // CHECK:      call void @llvm.trap()
}

// CHECK-LABEL: define void @test2()
void test2() {
  extern void opaque(int);
  opaque(++i);

  // CHECK:      [[T1:%.*]] = load i32* @i
  // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T1]], i32 1)
  // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
  // CHECK-NEXT: [[T4:%.*]] = extractvalue { i32, i1 } [[T2]], 1
  // CHECK-NEXT: [[T5:%.*]] = xor i1 [[T4]], true
  // CHECK-NEXT: br i1 [[T5]]
  // CHECK:      call void @llvm.trap()
}

// CHECK-LABEL: define void @test3(
void test3(int a, int b, float c, float d) {
  // CHECK-NOT:  @llvm.trap
  (void)(a / b);
  (void)(a % b);
  (void)(c / d);
  // CHECK: }
}