1 // RUN: %clang_cc1 -fsanitize=implicit-integer-truncation -fsanitize-recover=implicit-integer-truncation -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_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, {{.*}}, i8 0 } 13 // CHECK-DAG: @[[LINE_1100_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 0 } 14 // CHECK-DAG: @[[LINE_1500_TRUNCATION:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 0 } 15 // CHECK-DAG: @[[LINE_1600_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 0 } 16 17 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_int 18 unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) { 19 // CHECK: } 20 #line 100 21 return x; 22 } 23 24 // CHECK-LABEL: @convert_unsigned_char_to_unsigned_char 25 unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) { 26 // CHECK: } 27 #line 200 28 return x; 29 } 30 31 // CHECK-LABEL: @convert_signed_int_to_signed_int 32 signed int convert_signed_int_to_signed_int(signed int x) { 33 // CHECK: } 34 #line 300 35 return x; 36 } 37 38 // CHECK-LABEL: @convert_signed_char_to_signed_char 39 signed char convert_signed_char_to_signed_char(signed char x) { 40 // CHECK: } 41 #line 400 42 return x; 43 } 44 45 // CHECK-LABEL: @convert_unsigned_int_to_unsigned_char 46 unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) { 47 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_500_TRUNCATION]] to i8*) 48 // CHECK: } 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 // CHECK: } 56 #line 600 57 return x; 58 } 59 60 // CHECK-LABEL: @convert_unsigned_char_to_signed_int 61 signed int convert_unsigned_char_to_signed_int(unsigned char x) { 62 // CHECK: } 63 #line 700 64 return x; 65 } 66 67 // CHECK-LABEL: @convert_signed_char_to_signed_int 68 signed int convert_signed_char_to_signed_int(signed char x) { 69 // CHECK: } 70 #line 800 71 return x; 72 } 73 74 // CHECK-LABEL: @convert_unsigned_int_to_signed_int 75 signed int convert_unsigned_int_to_signed_int(unsigned int x) { 76 // CHECK: } 77 #line 900 78 return x; 79 } 80 81 // CHECK-LABEL: @convert_signed_int_to_unsigned_int 82 unsigned int convert_signed_int_to_unsigned_int(signed int x) { 83 // CHECK: } 84 #line 1000 85 return x; 86 } 87 88 // CHECK-LABEL: @convert_signed_int_to_unsigned_char 89 unsigned char convert_signed_int_to_unsigned_char(signed int x) { 90 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1100_TRUNCATION]] to i8*) 91 // CHECK: } 92 #line 1100 93 return x; 94 } 95 96 // CHECK-LABEL: @convert_signed_char_to_unsigned_char 97 unsigned char convert_signed_char_to_unsigned_char(signed char x) { 98 // CHECK: } 99 #line 1200 100 return x; 101 } 102 103 // CHECK-LABEL: @convert_unsigned_char_to_signed_char 104 signed char convert_unsigned_char_to_signed_char(unsigned char x) { 105 // CHECK: } 106 #line 1300 107 return x; 108 } 109 110 // CHECK-LABEL: @convert_signed_char_to_unsigned_int 111 unsigned int convert_signed_char_to_unsigned_int(signed char x) { 112 // CHECK: } 113 #line 1400 114 return x; 115 } 116 117 // CHECK-LABEL: @convert_unsigned_int_to_signed_char 118 signed char convert_unsigned_int_to_signed_char(unsigned int x) { 119 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1500_TRUNCATION]] to i8*) 120 // CHECK: } 121 #line 1500 122 return x; 123 } 124 125 // CHECK-LABEL: @convert_signed_int_to_signed_char 126 signed char convert_signed_int_to_signed_char(signed int x) { 127 // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1600_TRUNCATION]] to i8*) 128 // CHECK: } 129 #line 1600 130 return x; 131 } 132