blob: 2af16e80c8ffc910671e303766e44207d184080b [file] [log] [blame]
Roman Lebedev62debd802018-10-30 21:58:56 +00001// 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
Roman Lebedev9cb37a22018-08-17 07:33:25 +00002
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
Roman Lebedevdd403572018-10-11 09:09:50 +000012// CHECK-DAG: @[[LINE_500_UNSIGNED_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, {{.*}}, i8 1 }
Roman Lebedev62debd802018-10-30 21:58:56 +000013// 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 }
Roman Lebedevdd403572018-10-11 09:09:50 +000015// CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2 }
Roman Lebedev62debd802018-10-30 21:58:56 +000016// 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 }
Roman Lebedevdd403572018-10-11 09:09:50 +000020// CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2 }
Roman Lebedev9cb37a22018-08-17 07:33:25 +000021
22// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
23unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000024#line 100
25 return x;
26}
27
28// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
29unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000030#line 200
31 return x;
32}
33
34// CHECK-LABEL: @convert_signed_int_to_signed_int
35signed int convert_signed_int_to_signed_int(signed int x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000036#line 300
37 return x;
38}
39
40// CHECK-LABEL: @convert_signed_char_to_signed_char
41signed char convert_signed_char_to_signed_char(signed char x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000042#line 400
43 return x;
44}
45
46// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
47unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {
Roman Lebedevdd403572018-10-11 09:09:50 +000048 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_500_UNSIGNED_TRUNCATION]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +000049#line 500
50 return x;
51}
52
53// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
54unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000055#line 600
56 return x;
57}
58
59// CHECK-LABEL: @convert_unsigned_char_to_signed_int
60signed int convert_unsigned_char_to_signed_int(unsigned char x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000061#line 700
62 return x;
63}
64
65// CHECK-LABEL: @convert_signed_char_to_signed_int
66signed int convert_signed_char_to_signed_int(signed char x) {
Roman Lebedev9cb37a22018-08-17 07:33:25 +000067#line 800
68 return x;
69}
70
71// CHECK-LABEL: @convert_unsigned_int_to_signed_int
72signed int convert_unsigned_int_to_signed_int(unsigned int x) {
Roman Lebedev62debd802018-10-30 21:58:56 +000073 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_900_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +000074#line 900
75 return x;
76}
77
78// CHECK-LABEL: @convert_signed_int_to_unsigned_int
79unsigned int convert_signed_int_to_unsigned_int(signed int x) {
Roman Lebedev62debd802018-10-30 21:58:56 +000080 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1000_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +000081#line 1000
82 return x;
83}
84
85// CHECK-LABEL: @convert_signed_int_to_unsigned_char
86unsigned char convert_signed_int_to_unsigned_char(signed int x) {
Roman Lebedevdd403572018-10-11 09:09:50 +000087 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1100_SIGNED_TRUNCATION]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +000088#line 1100
89 return x;
90}
91
92// CHECK-LABEL: @convert_signed_char_to_unsigned_char
93unsigned char convert_signed_char_to_unsigned_char(signed char x) {
Roman Lebedev62debd802018-10-30 21:58:56 +000094 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1200_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +000095#line 1200
96 return x;
97}
98
99// CHECK-LABEL: @convert_unsigned_char_to_signed_char
100signed char convert_unsigned_char_to_signed_char(unsigned char x) {
Roman Lebedev62debd802018-10-30 21:58:56 +0000101 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1300_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +0000102#line 1300
103 return x;
104}
105
106// CHECK-LABEL: @convert_signed_char_to_unsigned_int
107unsigned int convert_signed_char_to_unsigned_int(signed char x) {
Roman Lebedev62debd802018-10-30 21:58:56 +0000108 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1400_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +0000109#line 1400
110 return x;
111}
112
113// CHECK-LABEL: @convert_unsigned_int_to_signed_char
114signed char convert_unsigned_int_to_signed_char(unsigned int x) {
Roman Lebedev62debd802018-10-30 21:58:56 +0000115 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +0000116#line 1500
117 return x;
118}
119
120// CHECK-LABEL: @convert_signed_int_to_signed_char
121signed char convert_signed_int_to_signed_char(signed int x) {
Roman Lebedevdd403572018-10-11 09:09:50 +0000122 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1600_SIGNED_TRUNCATION]] to i8*)
Roman Lebedev9cb37a22018-08-17 07:33:25 +0000123#line 1600
124 return x;
125}