brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 645c070 Raw
124 lines · c
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=CHECK2 3// Test plan:4//  * Two types - int and char5//  * Two signs - signed and unsigned6//  * 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_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }13// CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }14// CHECK-DAG: @[[LINE_1100_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }15// CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }16// CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }17// CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3, i32 0 }18// CHECK-DAG: @[[LINE_1500_SIGNED_TRUNCATION_OR_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 4, i32 0 }19// CHECK-DAG: @[[LINE_1600_SIGNED_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 2, i32 0 }20 21// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int22unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {23#line 10024  return x;25}26 27// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char28unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {29#line 20030  return x;31}32 33// CHECK-LABEL: @convert_signed_int_to_signed_int34signed int convert_signed_int_to_signed_int(signed int x) {35#line 30036  return x;37}38 39// CHECK-LABEL: @convert_signed_char_to_signed_char40signed char convert_signed_char_to_signed_char(signed char x) {41#line 40042  return x;43}44 45// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char46unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {47#line 50048  return x;49}50 51// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int52unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {53#line 60054  return x;55}56 57// CHECK-LABEL: @convert_unsigned_char_to_signed_int58signed int convert_unsigned_char_to_signed_int(unsigned char x) {59#line 70060  return x;61}62 63// CHECK-LABEL: @convert_signed_char_to_signed_int64signed int convert_signed_char_to_signed_int(signed char x) {65#line 80066  return x;67}68 69// CHECK-LABEL: @convert_unsigned_int_to_signed_int70signed 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 90073  return x;74}75 76// CHECK-LABEL: @convert_signed_int_to_unsigned_int77unsigned 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 100080  return x;81}82 83// CHECK-LABEL: @convert_signed_int_to_unsigned_char84unsigned 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 110087  return x;88}89 90// CHECK-LABEL: @convert_signed_char_to_unsigned_char91unsigned 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 120094  return x;95}96 97// CHECK-LABEL: @convert_unsigned_char_to_signed_char98signed 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 1300101  return x;102}103 104// CHECK-LABEL: @convert_signed_char_to_unsigned_int105unsigned 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 1400108  return x;109}110 111// CHECK-LABEL: @convert_unsigned_int_to_signed_char112signed 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 1500115  return x;116}117 118// CHECK-LABEL: @convert_signed_int_to_signed_char119signed 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 1600122  return x;123}124