[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / catch-implicit-integer-arithmetic-value-change-basics.c
blob32ed6b1a7bac9fe0ec4a3ecc4b2feef9d62e2fe6
1 // RUN: %clang_cc1 -fsanitize=implicit-signed-integer-truncation,implicit-integer-sign-change -fsanitize-recover=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
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.
12 // CHECK-DAG: @[[LINE_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3 }
13 // CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3 }
14 // CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2 }
15 // CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3 }
16 // CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3 }
17 // CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3 }
18 // CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4 }
19 // CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2 }
21 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
22 unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
23 #line 100
24 return x;
27 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
28 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
29 #line 200
30 return x;
33 // CHECK-LABEL: @convert_signed_int_to_signed_int
34 signed int convert_signed_int_to_signed_int(signed int x) {
35 #line 300
36 return x;
39 // CHECK-LABEL: @convert_signed_char_to_signed_char
40 signed char convert_signed_char_to_signed_char(signed char x) {
41 #line 400
42 return x;
45 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
46 unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {
47 #line 500
48 return x;
51 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
52 unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
53 #line 600
54 return x;
57 // CHECK-LABEL: @convert_unsigned_char_to_signed_int
58 signed int convert_unsigned_char_to_signed_int(unsigned char x) {
59 #line 700
60 return x;
63 // CHECK-LABEL: @convert_signed_char_to_signed_int
64 signed int convert_signed_char_to_signed_int(signed char x) {
65 #line 800
66 return x;
69 // CHECK-LABEL: @convert_unsigned_int_to_signed_int
70 signed int convert_unsigned_int_to_signed_int(unsigned int x) {
71 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_900_SIGN_CHANGE]]
72 #line 900
73 return x;
76 // CHECK-LABEL: @convert_signed_int_to_unsigned_int
77 unsigned int convert_signed_int_to_unsigned_int(signed int x) {
78 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1000_SIGN_CHANGE]]
79 #line 1000
80 return x;
83 // CHECK-LABEL: @convert_signed_int_to_unsigned_char
84 unsigned char convert_signed_int_to_unsigned_char(signed int x) {
85 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1100_SIGNED_TRUNCATION]]
86 #line 1100
87 return x;
90 // CHECK-LABEL: @convert_signed_char_to_unsigned_char
91 unsigned char convert_signed_char_to_unsigned_char(signed char x) {
92 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1200_SIGN_CHANGE]]
93 #line 1200
94 return x;
97 // CHECK-LABEL: @convert_unsigned_char_to_signed_char
98 signed char convert_unsigned_char_to_signed_char(unsigned char x) {
99 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1300_SIGN_CHANGE]]
100 #line 1300
101 return x;
104 // CHECK-LABEL: @convert_signed_char_to_unsigned_int
105 unsigned int convert_signed_char_to_unsigned_int(signed char x) {
106 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1400_SIGN_CHANGE]]
107 #line 1400
108 return x;
111 // CHECK-LABEL: @convert_unsigned_int_to_signed_char
112 signed char convert_unsigned_int_to_signed_char(unsigned int x) {
113 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE]]
114 #line 1500
115 return x;
118 // CHECK-LABEL: @convert_signed_int_to_signed_char
119 signed char convert_signed_int_to_signed_char(signed int x) {
120 // CHECK: call void @__ubsan_handle_implicit_conversion(ptr @[[LINE_1600_SIGNED_TRUNCATION]]
121 #line 1600
122 return x;