1 | // RUN: %clang_cc1 -fsanitize=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK |
2 | |
3 | // Test plan: |
4 | // * Two types - int and char |
5 | // * Two signs - signed and unsigned |
6 | // * Square that - we have input and output types. |
7 | // Thus, there are total of (2*2)^2 == 16 tests. |
8 | // These are all the possible variations/combinations of casts. |
9 | // However, not all of them should result in the check. |
10 | // So here, we *only* check which should and which should not result in checks. |
11 | |
12 | // CHECK-DAG: @[[LINE_500_UNSIGNED_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, {{.*}}, i8 1 } |
13 | // CHECK-DAG: @[[LINE_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3 } |
14 | // CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3 } |
15 | // CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2 } |
16 | // CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3 } |
17 | // CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3 } |
18 | // CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3 } |
19 | // CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4 } |
20 | // CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2 } |
21 | |
22 | // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int |
23 | unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) { |
24 | #line 100 |
25 | return x; |
26 | } |
27 | |
28 | // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char |
29 | unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) { |
30 | #line 200 |
31 | return x; |
32 | } |
33 | |
34 | // CHECK-LABEL: @convert_signed_int_to_signed_int |
35 | signed int convert_signed_int_to_signed_int(signed int x) { |
36 | #line 300 |
37 | return x; |
38 | } |
39 | |
40 | // CHECK-LABEL: @convert_signed_char_to_signed_char |
41 | signed char convert_signed_char_to_signed_char(signed char x) { |
42 | #line 400 |
43 | return x; |
44 | } |
45 | |
46 | // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char |
47 | unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) { |
48 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_500_UNSIGNED_TRUNCATION]] to i8*) |
49 | #line 500 |
50 | return x; |
51 | } |
52 | |
53 | // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int |
54 | unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) { |
55 | #line 600 |
56 | return x; |
57 | } |
58 | |
59 | // CHECK-LABEL: @convert_unsigned_char_to_signed_int |
60 | signed int convert_unsigned_char_to_signed_int(unsigned char x) { |
61 | #line 700 |
62 | return x; |
63 | } |
64 | |
65 | // CHECK-LABEL: @convert_signed_char_to_signed_int |
66 | signed int convert_signed_char_to_signed_int(signed char x) { |
67 | #line 800 |
68 | return x; |
69 | } |
70 | |
71 | // CHECK-LABEL: @convert_unsigned_int_to_signed_int |
72 | signed int convert_unsigned_int_to_signed_int(unsigned int x) { |
73 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_900_SIGN_CHANGE]] to i8*) |
74 | #line 900 |
75 | return x; |
76 | } |
77 | |
78 | // CHECK-LABEL: @convert_signed_int_to_unsigned_int |
79 | unsigned int convert_signed_int_to_unsigned_int(signed int x) { |
80 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1000_SIGN_CHANGE]] to i8*) |
81 | #line 1000 |
82 | return x; |
83 | } |
84 | |
85 | // CHECK-LABEL: @convert_signed_int_to_unsigned_char |
86 | unsigned char convert_signed_int_to_unsigned_char(signed int x) { |
87 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1100_SIGNED_TRUNCATION]] to i8*) |
88 | #line 1100 |
89 | return x; |
90 | } |
91 | |
92 | // CHECK-LABEL: @convert_signed_char_to_unsigned_char |
93 | unsigned char convert_signed_char_to_unsigned_char(signed char x) { |
94 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1200_SIGN_CHANGE]] to i8*) |
95 | #line 1200 |
96 | return x; |
97 | } |
98 | |
99 | // CHECK-LABEL: @convert_unsigned_char_to_signed_char |
100 | signed char convert_unsigned_char_to_signed_char(unsigned char x) { |
101 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1300_SIGN_CHANGE]] to i8*) |
102 | #line 1300 |
103 | return x; |
104 | } |
105 | |
106 | // CHECK-LABEL: @convert_signed_char_to_unsigned_int |
107 | unsigned int convert_signed_char_to_unsigned_int(signed char x) { |
108 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1400_SIGN_CHANGE]] to i8*) |
109 | #line 1400 |
110 | return x; |
111 | } |
112 | |
113 | // CHECK-LABEL: @convert_unsigned_int_to_signed_char |
114 | signed char convert_unsigned_int_to_signed_char(unsigned int x) { |
115 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE]] to i8*) |
116 | #line 1500 |
117 | return x; |
118 | } |
119 | |
120 | // CHECK-LABEL: @convert_signed_int_to_signed_char |
121 | signed char convert_signed_int_to_signed_char(signed int x) { |
122 | // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1600_SIGNED_TRUNCATION]] to i8*) |
123 | #line 1600 |
124 | return x; |
125 | } |
126 | |