Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / catch-implicit-integer-sign-changes-true-negatives.cpp
blob82f39ed99cb864d9f7286c5917cbcdb52ba6d57e
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
19 // CHECK: }
20 return src;
23 // CHECK-LABEL: @ignorelist_1
24 __attribute__((no_sanitize("integer"))) unsigned int ignorelist_1(signed int src) {
25 // CHECK-SANITIZE-NOT: call
26 // CHECK: }
27 return src;
30 // CHECK-LABEL: @ignorelist_2
31 __attribute__((no_sanitize("implicit-conversion"))) unsigned int ignorelist_2(signed int src) {
32 // CHECK-SANITIZE-NOT: call
33 // CHECK: }
34 return src;
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
40 // CHECK: }
41 return src;
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
50 // CHECK: }
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
57 // CHECK: }
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
67 // CHECK: }
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
74 // CHECK: }
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
87 // CHECK: }
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
94 // CHECK: }
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
104 // CHECK: }
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
111 // CHECK: }
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
121 // CHECK: }
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
128 // CHECK: }
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
138 // CHECK: }
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
145 // CHECK: }
146 return static_cast<signed int>(src);
149 } // extern "C"