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