annotate clang/test/CodeGen/integer-overflow.c @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fwrapv | FileCheck %s --check-prefix=WRAPV
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv | FileCheck %s --check-prefix=TRAPV
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=CATCH_UB
anatofuz
parents:
diff changeset
5 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - -ftrapv -ftrapv-handler foo | FileCheck %s --check-prefix=TRAPV_HANDLER
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 // Tests for signed integer overflow stuff.
anatofuz
parents:
diff changeset
9 // rdar://7432000 rdar://7221421
anatofuz
parents:
diff changeset
10 void test1() {
anatofuz
parents:
diff changeset
11 // DEFAULT-LABEL: define void @test1
anatofuz
parents:
diff changeset
12 // WRAPV-LABEL: define void @test1
anatofuz
parents:
diff changeset
13 // TRAPV-LABEL: define void @test1
anatofuz
parents:
diff changeset
14 extern volatile int f11G, a, b;
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 // DEFAULT: add nsw i32
anatofuz
parents:
diff changeset
17 // WRAPV: add i32
anatofuz
parents:
diff changeset
18 // TRAPV: llvm.sadd.with.overflow.i32
anatofuz
parents:
diff changeset
19 // CATCH_UB: llvm.sadd.with.overflow.i32
anatofuz
parents:
diff changeset
20 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
21 f11G = a + b;
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // DEFAULT: sub nsw i32
anatofuz
parents:
diff changeset
24 // WRAPV: sub i32
anatofuz
parents:
diff changeset
25 // TRAPV: llvm.ssub.with.overflow.i32
anatofuz
parents:
diff changeset
26 // CATCH_UB: llvm.ssub.with.overflow.i32
anatofuz
parents:
diff changeset
27 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
28 f11G = a - b;
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // DEFAULT: mul nsw i32
anatofuz
parents:
diff changeset
31 // WRAPV: mul i32
anatofuz
parents:
diff changeset
32 // TRAPV: llvm.smul.with.overflow.i32
anatofuz
parents:
diff changeset
33 // CATCH_UB: llvm.smul.with.overflow.i32
anatofuz
parents:
diff changeset
34 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
35 f11G = a * b;
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // DEFAULT: sub nsw i32 0,
anatofuz
parents:
diff changeset
38 // WRAPV: sub i32 0,
anatofuz
parents:
diff changeset
39 // TRAPV: llvm.ssub.with.overflow.i32(i32 0
anatofuz
parents:
diff changeset
40 // CATCH_UB: llvm.ssub.with.overflow.i32(i32 0
anatofuz
parents:
diff changeset
41 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
42 f11G = -a;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 // PR7426 - Overflow checking for increments.
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 // DEFAULT: add nsw i32 {{.*}}, 1
anatofuz
parents:
diff changeset
47 // WRAPV: add i32 {{.*}}, 1
anatofuz
parents:
diff changeset
48 // TRAPV: llvm.sadd.with.overflow.i32({{.*}}, i32 1)
anatofuz
parents:
diff changeset
49 // CATCH_UB: llvm.sadd.with.overflow.i32({{.*}}, i32 1)
anatofuz
parents:
diff changeset
50 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
51 ++a;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 // DEFAULT: add nsw i32 {{.*}}, -1
anatofuz
parents:
diff changeset
54 // WRAPV: add i32 {{.*}}, -1
anatofuz
parents:
diff changeset
55 // TRAPV: llvm.ssub.with.overflow.i32({{.*}}, i32 1)
anatofuz
parents:
diff changeset
56 // CATCH_UB: llvm.ssub.with.overflow.i32({{.*}}, i32 1)
anatofuz
parents:
diff changeset
57 // TRAPV_HANDLER: foo(
anatofuz
parents:
diff changeset
58 --a;
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 // -fwrapv should turn off inbounds for GEP's, PR9256
anatofuz
parents:
diff changeset
61 extern int* P;
anatofuz
parents:
diff changeset
62 ++P;
anatofuz
parents:
diff changeset
63 // DEFAULT: getelementptr inbounds i32, i32*
anatofuz
parents:
diff changeset
64 // WRAPV: getelementptr i32, i32*
anatofuz
parents:
diff changeset
65 // TRAPV: getelementptr inbounds i32, i32*
anatofuz
parents:
diff changeset
66 // CATCH_UB: getelementptr inbounds i32, i32*
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 // PR9350: char pre-increment never overflows.
anatofuz
parents:
diff changeset
69 extern volatile signed char PR9350_char_inc;
anatofuz
parents:
diff changeset
70 // DEFAULT: add i8 {{.*}}, 1
anatofuz
parents:
diff changeset
71 // WRAPV: add i8 {{.*}}, 1
anatofuz
parents:
diff changeset
72 // TRAPV: add i8 {{.*}}, 1
anatofuz
parents:
diff changeset
73 // CATCH_UB: add i8 {{.*}}, 1
anatofuz
parents:
diff changeset
74 ++PR9350_char_inc;
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 // PR9350: char pre-decrement never overflows.
anatofuz
parents:
diff changeset
77 extern volatile signed char PR9350_char_dec;
anatofuz
parents:
diff changeset
78 // DEFAULT: add i8 {{.*}}, -1
anatofuz
parents:
diff changeset
79 // WRAPV: add i8 {{.*}}, -1
anatofuz
parents:
diff changeset
80 // TRAPV: add i8 {{.*}}, -1
anatofuz
parents:
diff changeset
81 // CATCH_UB: add i8 {{.*}}, -1
anatofuz
parents:
diff changeset
82 --PR9350_char_dec;
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 // PR9350: short pre-increment never overflows.
anatofuz
parents:
diff changeset
85 extern volatile signed short PR9350_short_inc;
anatofuz
parents:
diff changeset
86 // DEFAULT: add i16 {{.*}}, 1
anatofuz
parents:
diff changeset
87 // WRAPV: add i16 {{.*}}, 1
anatofuz
parents:
diff changeset
88 // TRAPV: add i16 {{.*}}, 1
anatofuz
parents:
diff changeset
89 // CATCH_UB: add i16 {{.*}}, 1
anatofuz
parents:
diff changeset
90 ++PR9350_short_inc;
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // PR9350: short pre-decrement never overflows.
anatofuz
parents:
diff changeset
93 extern volatile signed short PR9350_short_dec;
anatofuz
parents:
diff changeset
94 // DEFAULT: add i16 {{.*}}, -1
anatofuz
parents:
diff changeset
95 // WRAPV: add i16 {{.*}}, -1
anatofuz
parents:
diff changeset
96 // TRAPV: add i16 {{.*}}, -1
anatofuz
parents:
diff changeset
97 // CATCH_UB: add i16 {{.*}}, -1
anatofuz
parents:
diff changeset
98 --PR9350_short_dec;
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 // PR24256: don't instrument __builtin_frame_address.
anatofuz
parents:
diff changeset
101 __builtin_frame_address(0 + 0);
anatofuz
parents:
diff changeset
102 // DEFAULT: call i8* @llvm.frameaddress.p0i8(i32 0)
anatofuz
parents:
diff changeset
103 // WRAPV: call i8* @llvm.frameaddress.p0i8(i32 0)
anatofuz
parents:
diff changeset
104 // TRAPV: call i8* @llvm.frameaddress.p0i8(i32 0)
anatofuz
parents:
diff changeset
105 // CATCH_UB: call i8* @llvm.frameaddress.p0i8(i32 0)
anatofuz
parents:
diff changeset
106 }