// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=implicit-integer-sign-change -fsanitize-recover=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
// Test plan:
// * Two types - int and char
// * Two signs - signed and unsigned
// * Square that - we have input and output types.
// Thus, there are total of (2*2)^2 == 16 tests.
// These are all the possible variations/combinations of casts.
// However, not all of them should result in the check.
// So here, we *only* check which should and which should not result in checks.
// CHECK-DAG: @[[LINE_900_SIGN_CHANGE:.*]] = {{.*}}, i32 900, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1000_SIGN_CHANGE:.*]] = {{.*}}, i32 1000, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1100_SIGN_CHANGE:.*]] = {{.*}}, i32 1100, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1200_SIGN_CHANGE:.*]] = {{.*}}, i32 1200, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1300_SIGN_CHANGE:.*]] = {{.*}}, i32 1300, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1400_SIGN_CHANGE:.*]] = {{.*}}, i32 1400, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1500_SIGN_CHANGE:.*]] = {{.*}}, i32 1500, i32 10 }, {{.*}}, {{.*}}, i8 3 }
// CHECK-DAG: @[[LINE_1600_SIGN_CHANGE:.*]] = {{.*}}, i32 1600, i32 10 }, {{.*}}, {{.*}}, i8 3 }
//============================================================================//
// Half of the cases do not need the check. //
//============================================================================//
//----------------------------------------------------------------------------//
// No cast happens at all. No check needed.
//----------------------------------------------------------------------------//
// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
unsigned int
// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
unsigned char
// CHECK-LABEL: @convert_signed_int_to_signed_int
signed int
// CHECK-LABEL: @convert_signed_char_to_signed_char
signed char
//----------------------------------------------------------------------------//
// Both types are unsigned. No check needed.
//----------------------------------------------------------------------------//
// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
unsigned char
// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
unsigned int
//----------------------------------------------------------------------------//
// Source type was unsigned, destination type is signed, but non-negative.
// Because zero-extension happens - the sign bit will be 0. No check needed.
//----------------------------------------------------------------------------//
// CHECK-LABEL: @convert_unsigned_char_to_signed_int
signed int
//----------------------------------------------------------------------------//
// Both types are signed, and have the same sign, since sign-extension happens,
// i.e. the sign bit will be propagated. No check needed.
//----------------------------------------------------------------------------//
// CHECK-LABEL: @convert_signed_char_to_signed_int
signed int
//============================================================================//
// The remaining 8 cases *do* need the check. //
//============================================================================//
// These 3 result in simple 'icmp sge i32 %x, 0'
// CHECK-LABEL: @convert_unsigned_int_to_signed_int
signed int
// CHECK-LABEL: @convert_signed_int_to_unsigned_int
unsigned int
// CHECK-LABEL: @convert_signed_int_to_unsigned_char
unsigned char
// These 3 result in simple 'icmp sge i8 %x, 0'
// CHECK-LABEL: @convert_signed_char_to_unsigned_char
unsigned char
// CHECK-LABEL: @convert_unsigned_char_to_signed_char
signed char
// CHECK-LABEL: @convert_signed_char_to_unsigned_int
unsigned int
// 'icmp sge i8 (trunc i32 %x), 0'
// CHECK-LABEL: @convert_unsigned_int_to_signed_char
signed char
// 'xor i1 (icmp sge i8 (trunc i32 %x), 0), (icmp sge i32 %x, 0)'
// CHECK-LABEL: @convert_signed_int_to_signed_char
signed char