1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK
2 // RUN: %clang_cc1 -fsanitize=implicit-integer-sign-change -fno-sanitize-recover=implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE
3 // RUN: %clang_cc1 -fsanitize=implicit-integer-sign-change -fsanitize-recover=implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE
4 // RUN: %clang_cc1 -fsanitize=implicit-integer-sign-change -fsanitize-trap=implicit-integer-sign-change -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SANITIZE
6 extern "C" { // Disable name mangling.
8 // ========================================================================== //
9 // The expected true-negatives.
10 // ========================================================================== //
12 // Sanitization is explicitly disabled.
13 // ========================================================================== //
15 // CHECK-LABEL: @ignorelist_0
16 __attribute__((no_sanitize("undefined"))) unsigned int ignorelist_0(signed int src
) {
17 // We are not in "undefined" group, so that doesn't work.
18 // CHECK-SANITIZE: call
23 // CHECK-LABEL: @ignorelist_1
24 __attribute__((no_sanitize("integer"))) unsigned int ignorelist_1(signed int src
) {
25 // CHECK-SANITIZE-NOT: call
30 // CHECK-LABEL: @ignorelist_2
31 __attribute__((no_sanitize("implicit-conversion"))) unsigned int ignorelist_2(signed int src
) {
32 // CHECK-SANITIZE-NOT: call
37 // CHECK-LABEL: @ignorelist_3
38 __attribute__((no_sanitize("implicit-integer-sign-change"))) unsigned int ignorelist_3(signed int src
) {
39 // CHECK-SANITIZE-NOT: call
44 // Explicit sign-changing conversions.
45 // ========================================================================== //
47 // CHECK-LABEL: @explicit_signed_int_to_unsigned_int
48 unsigned int explicit_signed_int_to_unsigned_int(signed int src
) {
49 // CHECK-SANITIZE-NOT: call
51 return (unsigned int)src
;
54 // CHECK-LABEL: @explicit_unsigned_int_to_signed_int
55 signed int explicit_unsigned_int_to_signed_int(unsigned int src
) {
56 // CHECK-SANITIZE-NOT: call
58 return (signed int)src
;
61 // Explicit NOP conversions.
62 // ========================================================================== //
64 // CHECK-LABEL: @explicit_unsigned_int_to_unsigned_int
65 unsigned int explicit_unsigned_int_to_unsigned_int(unsigned int src
) {
66 // CHECK-SANITIZE-NOT: call
68 return (unsigned int)src
;
71 // CHECK-LABEL: @explicit_signed_int_to_signed_int
72 signed int explicit_signed_int_to_signed_int(signed int src
) {
73 // CHECK-SANITIZE-NOT: call
75 return (signed int)src
;
78 // Explicit functional sign-changing casts.
79 // ========================================================================== //
81 using UnsignedInt
= unsigned int;
82 using SignedInt
= signed int;
84 // CHECK-LABEL: explicit_functional_unsigned_int_to_signed_int
85 signed int explicit_functional_unsigned_int_to_signed_int(unsigned int src
) {
86 // CHECK-SANITIZE-NOT: call
88 return SignedInt(src
);
91 // CHECK-LABEL: @explicit_functional_signed_int_to_unsigned_int
92 unsigned int explicit_functional_signed_int_to_unsigned_int(signed int src
) {
93 // CHECK-SANITIZE-NOT: call
95 return UnsignedInt(src
);
98 // Explicit functional NOP casts.
99 // ========================================================================== //
101 // CHECK-LABEL: @explicit_functional_unsigned_int_to_unsigned_int
102 unsigned int explicit_functional_unsigned_int_to_unsigned_int(unsigned int src
) {
103 // CHECK-SANITIZE-NOT: call
105 return UnsignedInt(src
);
108 // CHECK-LABEL: @explicit_functional_signed_int_to_signed_int
109 signed int explicit_functional_signed_int_to_signed_int(signed int src
) {
110 // CHECK-SANITIZE-NOT: call
112 return SignedInt(src
);
115 // Explicit C++-style sign-changing casts.
116 // ========================================================================== //
118 // CHECK-LABEL: @explicit_cppstyle_unsigned_int_to_signed_int
119 signed int explicit_cppstyle_unsigned_int_to_signed_int(unsigned int src
) {
120 // CHECK-SANITIZE-NOT: call
122 return static_cast<signed int>(src
);
125 // CHECK-LABEL: @explicit_cppstyle_signed_int_to_unsigned_int
126 unsigned int explicit_cppstyle_signed_int_to_unsigned_int(signed int src
) {
127 // CHECK-SANITIZE-NOT: call
129 return static_cast<unsigned int>(src
);
132 // Explicit C++-style casts NOP casts.
133 // ========================================================================== //
135 // CHECK-LABEL: @explicit_cppstyle_unsigned_int_to_unsigned_int
136 unsigned int explicit_cppstyle_unsigned_int_to_unsigned_int(unsigned int src
) {
137 // CHECK-SANITIZE-NOT: call
139 return static_cast<unsigned int>(src
);
142 // CHECK-LABEL: @explicit_cppstyle_signed_int_to_signed_int
143 signed int explicit_cppstyle_signed_int_to_signed_int(signed int src
) {
144 // CHECK-SANITIZE-NOT: call
146 return static_cast<signed int>(src
);