[compiler-rt] r339996 - [NFC] Some small test updates for Implicit Conversion sanitizer.

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 17 00:33:38 PDT 2018


Author: lebedevri
Date: Fri Aug 17 00:33:38 2018
New Revision: 339996

URL: http://llvm.org/viewvc/llvm-project?rev=339996&view=rev
Log:
[NFC] Some small test updates for Implicit Conversion sanitizer.

Split off from D50251.

Added:
    compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c
Modified:
    compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test
    compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c
    compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c

Modified: compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test?rev=339996&r1=339995&r2=339996&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test (original)
+++ compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test Fri Aug 17 00:33:38 2018
@@ -1,5 +1,5 @@
 RUN: rm -f %t-ImplicitIntegerTruncationTest-Ubsan
 RUN: %cpp_compiler -fsanitize=implicit-integer-truncation -fno-sanitize-recover=all %S/ImplicitIntegerTruncationTest.cpp -o %t-ImplicitIntegerTruncationTest-Ubsan
 RUN: not %run %t-ImplicitIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s
-CHECK: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
+CHECK: ImplicitIntegerTruncationTest.cpp:22:17: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
 CHECK: Test unit written to ./crash-

Added: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c?rev=339996&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c (added)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-conversion.c Fri Aug 17 00:33:38 2018
@@ -0,0 +1,70 @@
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5
+// RUN: %clang   -x c   -fsanitize=implicit-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6
+
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV1 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V1
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV2 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V2
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV5 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V5
+// RUN: %clang   -x c++ -fsanitize=implicit-integer-truncation %s -DV6 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V6
+
+#include <stdint.h>
+
+int8_t positive6_convert_unsigned_int_to_signed_char(uint32_t x) {
+#line 100
+  return x;
+}
+
+#line 1120 // !!!
+
+void test_positives() {
+  // No bits set.
+  positive6_convert_unsigned_int_to_signed_char(0);
+
+  // One lowest bit set.
+  positive6_convert_unsigned_int_to_signed_char(1);
+
+#if defined(V0)
+  // All source bits set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX);
+#elif defined(V1)
+  // Source 'Sign' bit set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN);
+// CHECK-V1: {{.*}}integer-conversion.c:100:10: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2147483648 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to 0 (8-bit, signed)
+#elif defined(V2)
+  // All bits except the source 'Sign' bit are set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX);
+// CHECK-V2: {{.*}}integer-conversion.c:100:10: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2147483647 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to -1 (8-bit, signed)
+#elif defined(V3)
+  // All destination bits set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX);
+// CHECK-V3: {{.*}}integer-conversion.c:100:10: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 255 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to -1 (8-bit, signed)
+#elif defined(V4)
+  // Destination 'sign' bit set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)INT8_MIN);
+#elif defined(V5)
+  // All bits except the destination 'sign' bit are set.
+  positive6_convert_unsigned_int_to_signed_char(~((uint32_t)(uint8_t)INT8_MIN));
+// CHECK-V5: {{.*}}integer-conversion.c:100:10: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967167 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to 127 (8-bit, signed)
+#elif defined(V6)
+  // Only the source and destination sign bits are set.
+  positive6_convert_unsigned_int_to_signed_char((uint32_t)((uint32_t)INT32_MIN | (uint32_t)((uint8_t)INT8_MIN)));
+// CHECK-V6: {{.*}}integer-conversion.c:100:10: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2147483776 (32-bit, unsigned) to type 'int8_t' (aka 'signed char') changed the value to -128 (8-bit, signed)
+#else
+#error Some V* needs to be defined!
+#endif
+}
+
+// CHECK-NOT: implicit conversion
+
+int main() {
+  test_positives();
+
+  return 0;
+}

Modified: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c?rev=339996&r1=339995&r2=339996&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c Fri Aug 17 00:33:38 2018
@@ -3,16 +3,22 @@
 // XFAIL: android
 // UNSUPPORTED: ios
 
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation                           -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion"
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation                           -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion"
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation                           -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion"
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation                           -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion"
+
 // RUN: rm -f %tmp
 // RUN: echo "[implicit-integer-truncation]" >> %tmp
-// RUN: echo "fun:*implicitTruncation*" >> %tmp
-// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1
-// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1
-// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1
-// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1
+// RUN: echo "fun:implicitTruncation" >> %tmp
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O0 %s -o %t && not %run %t 2>&1 | not FileCheck %s
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O1 %s -o %t && not %run %t 2>&1 | not FileCheck %s
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O2 %s -o %t && not %run %t 2>&1 | not FileCheck %s
+// RUN: %clang -fsanitize=implicit-integer-truncation -fno-sanitize-recover=implicit-integer-truncation -fsanitize-blacklist=%tmp -O3 %s -o %t && not %run %t 2>&1 | not FileCheck %s
 
 unsigned char implicitTruncation(unsigned int argc) {
   return argc; // BOOM
+// CHECK: {{.*}}integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned)
 }
 
 int main(int argc, char **argv) {

Modified: compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c?rev=339996&r1=339995&r2=339996&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c (original)
+++ compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c Fri Aug 17 00:33:38 2018
@@ -3,7 +3,7 @@
 #include <stdint.h>
 
 int main() {
-// CHECK-NOT: integer-truncation.c
+// CHECK-NOT: implicit-conversion
 
   // Negative tests. Even if they produce unexpected results, this sanitizer does not care.
   int8_t n0 = (~((uint32_t)(0))); // ~0 -> -1, but do not warn.
@@ -19,6 +19,7 @@ int main() {
   // Positive tests.
   uint8_t t0 = (~((uint32_t)(0)));
 // CHECK: implicit-conversion
+// CHECK-NOT: implicit-conversion
 
   return 0;
 }




More information about the llvm-commits mailing list