[compiler-rt] r344231 - [compiler-rt][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 11 02:09:52 PDT 2018
Author: lebedevri
Date: Thu Oct 11 02:09:52 2018
New Revision: 344231
URL: http://llvm.org/viewvc/llvm-project?rev=344231&view=rev
Log:
[compiler-rt][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks
Summary:
This is compiler-rt part.
clang part is D50901.
Reviewers: rsmith, vsk, filcab, Sanitizers
Reviewed by: filcab
Differential Revision: https://reviews.llvm.org/D50902
Added:
compiler-rt/trunk/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp
- copied, changed from r344229, compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp
compiler-rt/trunk/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp
- copied, changed from r344229, compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp
compiler-rt/trunk/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test
compiler-rt/trunk/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp
- copied, changed from r344229, compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp
- copied, changed from r344229, compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp
compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c
compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c
- copied, changed from r344229, compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c
- copied, changed from r344229, compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
Removed:
compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp
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/TestCases/ImplicitConversion/integer-truncation-summary.cpp
compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
Modified:
compiler-rt/trunk/lib/ubsan/ubsan_checks.inc
compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
Modified: compiler-rt/trunk/lib/ubsan/ubsan_checks.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_checks.inc?rev=344231&r1=344230&r2=344231&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_checks.inc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_checks.inc Thu Oct 11 02:09:52 2018
@@ -30,8 +30,12 @@ UBSAN_CHECK(IntegerDivideByZero, "intege
"integer-divide-by-zero")
UBSAN_CHECK(FloatDivideByZero, "float-divide-by-zero", "float-divide-by-zero")
UBSAN_CHECK(InvalidBuiltin, "invalid-builtin-use", "invalid-builtin-use")
-UBSAN_CHECK(ImplicitIntegerTruncation, "implicit-integer-truncation",
- "implicit-integer-truncation")
+UBSAN_CHECK(ImplicitUnsignedIntegerTruncation,
+ "implicit-unsigned-integer-truncation",
+ "implicit-unsigned-integer-truncation")
+UBSAN_CHECK(ImplicitSignedIntegerTruncation,
+ "implicit-signed-integer-truncation",
+ "implicit-signed-integer-truncation")
UBSAN_CHECK(InvalidShiftBase, "invalid-shift-base", "shift-base")
UBSAN_CHECK(InvalidShiftExponent, "invalid-shift-exponent", "shift-exponent")
UBSAN_CHECK(OutOfBoundsIndex, "out-of-bounds-index", "bounds")
Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc?rev=344231&r1=344230&r2=344231&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc Thu Oct 11 02:09:52 2018
@@ -457,18 +457,35 @@ static void handleImplicitConversion(Imp
SourceLocation Loc = Data->Loc.acquire();
ErrorType ET = ErrorType::GenericUB;
+ const TypeDescriptor &SrcTy = Data->FromType;
+ const TypeDescriptor &DstTy = Data->ToType;
+
+ bool SrcSigned = SrcTy.isSignedIntegerTy();
+ bool DstSigned = DstTy.isSignedIntegerTy();
+
switch (Data->Kind) {
- case ICCK_IntegerTruncation:
- ET = ErrorType::ImplicitIntegerTruncation;
+ case ICCK_IntegerTruncation: { // Legacy, no longer used.
+ // Let's figure out what it should be as per the new types, and upgrade.
+ // If both types are unsigned, then it's an unsigned truncation.
+ // Else, it is a signed truncation.
+ if (!SrcSigned && !DstSigned) {
+ ET = ErrorType::ImplicitUnsignedIntegerTruncation;
+ } else {
+ ET = ErrorType::ImplicitSignedIntegerTruncation;
+ }
+ break;
+ }
+ case ICCK_UnsignedIntegerTruncation:
+ ET = ErrorType::ImplicitUnsignedIntegerTruncation;
+ break;
+ case ICCK_SignedIntegerTruncation:
+ ET = ErrorType::ImplicitSignedIntegerTruncation;
break;
}
if (ignoreReport(Loc, Opts, ET))
return;
- const TypeDescriptor &SrcTy = Data->FromType;
- const TypeDescriptor &DstTy = Data->ToType;
-
ScopedReport R(Opts, Loc, ET);
// FIXME: is it possible to dump the values as hex with fixed width?
@@ -477,8 +494,8 @@ static void handleImplicitConversion(Imp
"implicit conversion from type %0 of value %1 (%2-bit, %3signed) to "
"type %4 changed the value to %5 (%6-bit, %7signed)")
<< SrcTy << Value(SrcTy, Src) << SrcTy.getIntegerBitWidth()
- << (SrcTy.isSignedIntegerTy() ? "" : "un") << DstTy << Value(DstTy, Dst)
- << DstTy.getIntegerBitWidth() << (DstTy.isSignedIntegerTy() ? "" : "un");
+ << (SrcSigned ? "" : "un") << DstTy << Value(DstTy, Dst)
+ << DstTy.getIntegerBitWidth() << (DstSigned ? "" : "un");
}
void __ubsan::__ubsan_handle_implicit_conversion(ImplicitConversionData *Data,
Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.h?rev=344231&r1=344230&r2=344231&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.h Thu Oct 11 02:09:52 2018
@@ -125,7 +125,9 @@ RECOVERABLE(load_invalid_value, InvalidV
/// Known implicit conversion check kinds.
/// Keep in sync with the enum of the same name in CGExprScalar.cpp
enum ImplicitConversionCheckKind : unsigned char {
- ICCK_IntegerTruncation = 0,
+ ICCK_IntegerTruncation = 0, // Legacy, was only used by clang 7.
+ ICCK_UnsignedIntegerTruncation = 1,
+ ICCK_SignedIntegerTruncation = 2,
};
struct ImplicitConversionData {
Removed: compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp?rev=344230&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp (removed)
@@ -1,27 +0,0 @@
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-
-// Test for signed-integer-overflow.
-#include <assert.h>
-#include <climits>
-#include <cstddef>
-#include <cstdint>
-#include <cstdlib>
-#include <iostream>
-
-static volatile int Sink;
-static unsigned char Large = UINT8_MAX;
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
- assert(Data);
- if (Size > 0 && Data[0] == 'H') {
- Sink = 1;
- if (Size > 1 && Data[1] == 'i') {
- Sink = 2;
- if (Size > 2 && Data[2] == '!') {
- Large = Large + 1; // 'char overflow'.
- }
- }
- }
- return 0;
-}
Copied: compiler-rt/trunk/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp (from r344229, compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp?p2=compiler-rt/trunk/test/fuzzer/ImplicitSignedIntegerTruncationTest.cpp&p1=compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
(empty)
Copied: compiler-rt/trunk/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp (from r344229, compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp?p2=compiler-rt/trunk/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp&p1=compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/ImplicitIntegerTruncationTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/ImplicitUnsignedIntegerTruncationTest.cpp Thu Oct 11 02:09:52 2018
@@ -1,7 +1,7 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
-// Test for signed-integer-overflow.
+// Test for unsigned-integer-overflow.
#include <assert.h>
#include <climits>
#include <cstddef>
@@ -19,7 +19,7 @@ extern "C" int LLVMFuzzerTestOneInput(co
if (Size > 1 && Data[1] == 'i') {
Sink = 2;
if (Size > 2 && Data[2] == '!') {
- Large = Large + 1; // 'char overflow'.
+ Large = (unsigned int)Large + 1U; // 'char overflow'.
}
}
}
Removed: 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=344230&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test (original)
+++ compiler-rt/trunk/test/fuzzer/fuzzer-implicit-integer-truncation.test (removed)
@@ -1,5 +0,0 @@
-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: 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/fuzzer/fuzzer-implicit-signed-integer-truncation.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test (added)
+++ compiler-rt/trunk/test/fuzzer/fuzzer-implicit-signed-integer-truncation.test Thu Oct 11 02:09:52 2018
@@ -0,0 +1,5 @@
+RUN: rm -f %t-ImplicitSignedIntegerTruncationTest-Ubsan
+RUN: %cpp_compiler -fsanitize=implicit-signed-integer-truncation -fno-sanitize-recover=all %S/ImplicitSignedIntegerTruncationTest.cpp -o %t-ImplicitSignedIntegerTruncationTest-Ubsan
+RUN: not %run %t-ImplicitSignedIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s
+CHECK: ImplicitSignedIntegerTruncationTest.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/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test (added)
+++ compiler-rt/trunk/test/fuzzer/fuzzer-implicit-unsigned-integer-truncation.test Thu Oct 11 02:09:52 2018
@@ -0,0 +1,5 @@
+RUN: rm -f %t-ImplicitUnsignedIntegerTruncationTest-Ubsan
+RUN: %cpp_compiler -fsanitize=implicit-unsigned-integer-truncation -fno-sanitize-recover=all %S/ImplicitUnsignedIntegerTruncationTest.cpp -o %t-ImplicitUnsignedIntegerTruncationTest-Ubsan
+RUN: not %run %t-ImplicitUnsignedIntegerTruncationTest-Ubsan 2>&1 | FileCheck %s
+CHECK: ImplicitUnsignedIntegerTruncationTest.cpp:22:17: runtime error: implicit conversion from type 'unsigned int' of value 256 (32-bit, unsigned) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
+CHECK: Test unit written to ./crash-
Removed: 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=344230&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c (removed)
@@ -1,26 +0,0 @@
-// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
-// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases.
-// 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 | 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) {
- return implicitTruncation(~0U);
-}
Removed: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp?rev=344230&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp (removed)
@@ -1,13 +0,0 @@
-// RUN: %clangxx -fsanitize=implicit-integer-truncation %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE
-// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE
-// REQUIRES: !ubsan-standalone && !ubsan-standalone-static
-
-#include <stdint.h>
-
-int main() {
- uint8_t t0 = (~(uint32_t(0)));
- // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16
- // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16
- return 0;
-}
Added: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c (added)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-blacklist.c Thu Oct 11 02:09:52 2018
@@ -0,0 +1,58 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases.
+// 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 "[integer]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-conversion]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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 | 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 | 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 | 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 | FileCheck %s
+
+unsigned char implicitUnsignedTruncation(signed int argc) {
+ return argc; // BOOM
+// CHECK: {{.*}}signed-integer-truncation-blacklist.c:[[@LINE-1]]:10: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned)
+}
+
+int main(int argc, char **argv) {
+ return implicitUnsignedTruncation(-1);
+}
Copied: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp (from r344229, compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp?p2=compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp&p1=compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation-summary.cpp Thu Oct 11 02:09:52 2018
@@ -1,4 +1,4 @@
-// RUN: %clangxx -fsanitize=implicit-integer-truncation %s -o %t
+// RUN: %clangxx -fsanitize=implicit-signed-integer-truncation %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE
// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE
// REQUIRES: !ubsan-standalone && !ubsan-standalone-static
@@ -6,8 +6,8 @@
#include <stdint.h>
int main() {
- uint8_t t0 = (~(uint32_t(0)));
+ uint8_t t0 = int32_t(-1);
// CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16
- // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16
+ // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-signed-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16
return 0;
}
Added: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c (added)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/signed-integer-truncation.c Thu Oct 11 02:09:52 2018
@@ -0,0 +1,318 @@
+// RUN: %clang -x c -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang -x c -fsanitize=implicit-signed-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-signed-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-signed-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-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
+// RUN: %clang -x c -fsanitize=implicit-signed-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-signed-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-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
+
+// RUN: %clang -x c++ -fsanitize=implicit-signed-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang -x c++ -fsanitize=implicit-signed-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-signed-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-signed-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-signed-integer-truncation %s -DV4 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V4
+// RUN: %clang -x c++ -fsanitize=implicit-signed-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-signed-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-signed-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
+
+#include <stdint.h>
+
+// 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.
+
+unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
+#line 100
+ return x;
+}
+
+unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
+#line 200
+ return x;
+}
+
+signed int convert_signed_int_to_signed_int(signed int x) {
+#line 300
+ return x;
+}
+
+signed char convert_signed_char_to_signed_char(signed char x) {
+#line 400
+ return x;
+}
+
+unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {
+#line 500
+ return x;
+}
+
+unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
+#line 600
+ return x;
+}
+
+signed int convert_unsigned_char_to_signed_int(unsigned char x) {
+#line 700
+ return x;
+}
+
+signed int convert_signed_char_to_signed_int(signed char x) {
+#line 800
+ return x;
+}
+
+signed int convert_unsigned_int_to_signed_int(unsigned int x) {
+#line 900
+ return x;
+}
+
+unsigned int convert_signed_int_to_unsigned_int(signed int x) {
+#line 1000
+ return x;
+}
+
+unsigned char convert_signed_int_to_unsigned_char(signed int x) {
+#line 1100
+ return x;
+}
+
+unsigned char convert_signed_char_to_unsigned_char(signed char x) {
+#line 1200
+ return x;
+}
+
+signed char convert_unsigned_char_to_signed_char(unsigned char x) {
+#line 1300
+ return x;
+}
+
+unsigned int convert_signed_char_to_unsigned_int(signed char x) {
+#line 1400
+ return x;
+}
+
+signed char convert_unsigned_int_to_signed_char(unsigned int x) {
+#line 1500
+ return x;
+}
+
+signed char convert_signed_int_to_signed_char(signed int x) {
+#line 1600
+ return x;
+}
+
+#line 1111 // !!!
+
+int main() {
+ // No bits set.
+ convert_unsigned_int_to_unsigned_int(0);
+ convert_unsigned_char_to_unsigned_char(0);
+ convert_signed_int_to_signed_int(0);
+ convert_signed_char_to_signed_char(0);
+ convert_unsigned_int_to_unsigned_char(0);
+ convert_unsigned_char_to_unsigned_int(0);
+ convert_unsigned_char_to_signed_int(0);
+ convert_signed_char_to_signed_int(0);
+ convert_unsigned_int_to_signed_int(0);
+ convert_signed_int_to_unsigned_int(0);
+ convert_signed_int_to_unsigned_char(0);
+ convert_signed_char_to_unsigned_char(0);
+ convert_unsigned_char_to_signed_char(0);
+ convert_signed_char_to_unsigned_int(0);
+ convert_unsigned_int_to_signed_char(0);
+ convert_signed_int_to_signed_char(0);
+
+ // One lowest bit set.
+ convert_unsigned_int_to_unsigned_int(1);
+ convert_unsigned_char_to_unsigned_char(1);
+ convert_signed_int_to_signed_int(1);
+ convert_signed_char_to_signed_char(1);
+ convert_unsigned_int_to_unsigned_char(1);
+ convert_unsigned_char_to_unsigned_int(1);
+ convert_unsigned_char_to_signed_int(1);
+ convert_signed_char_to_signed_int(1);
+ convert_unsigned_int_to_signed_int(1);
+ convert_signed_int_to_unsigned_int(1);
+ convert_signed_int_to_unsigned_char(1);
+ convert_signed_char_to_unsigned_char(1);
+ convert_unsigned_char_to_signed_char(1);
+ convert_signed_char_to_unsigned_int(1);
+ convert_unsigned_int_to_signed_char(1);
+ convert_signed_int_to_signed_char(1);
+
+#if defined(V0)
+ // All source bits set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX);
+ convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX);
+// CHECK-V0: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX);
+#elif defined(V1)
+ // Source 'Sign' bit set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN);
+ convert_signed_char_to_signed_char((int8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN);
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN);
+// CHECK-V1: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN);
+// CHECK-V1: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'signed char' changed the value to 0 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN);
+// CHECK-V1: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483648 (32-bit, signed) to type 'signed char' changed the value to 0 (8-bit, signed)
+#elif defined(V2)
+ // All bits except the source 'Sign' bit are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)INT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX);
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX);
+// CHECK-V2: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'unsigned char' changed the value to 255 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX);
+// CHECK-V2: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX);
+// CHECK-V2: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483647 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed)
+#elif defined(V3)
+ // All destination bits set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX);
+ convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX);
+// CHECK-V3: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 255 (32-bit, unsigned) to type 'signed char' changed the value to -1 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX);
+// CHECK-V3: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 255 (32-bit, signed) to type 'signed char' changed the value to -1 (8-bit, signed)
+#elif defined(V4)
+ // Destination 'sign' bit set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN);
+// CHECK-V4: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 128 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+// CHECK-V4: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed)
+#elif defined(V5)
+ // All bits except the destination 'sign' bit are set.
+ convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V5: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V5: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V5: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -129 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed)
+#elif defined(V6)
+ // Only the source and destination sign bits are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)INT32_MIN);
+ convert_signed_char_to_signed_char((int8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN));
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V6: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'unsigned char' changed the value to 128 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V6: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'signed char' changed the value to -128 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V6: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value -2147483520 (32-bit, signed) to type 'signed char' changed the value to -128 (8-bit, signed)
+#elif defined(V7)
+ // All bits except the source and destination sign bits are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)INT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)INT8_MAX);
+ convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))));
+// CHECK-V7: {{.*}}signed-integer-truncation.c:1100:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'unsigned char' changed the value to 127 (8-bit, unsigned)
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V7: {{.*}}signed-integer-truncation.c:1500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'signed char' changed the value to 127 (8-bit, signed)
+ convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V7: {{.*}}signed-integer-truncation.c:1600:10: runtime error: implicit conversion from type 'int' of value 2147483519 (32-bit, signed) to type 'signed char' changed the value to 127 (8-bit, signed)
+#else
+#error Some V* needs to be defined!
+#endif
+
+ return 0;
+}
Added: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c (added)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-blacklist.c Thu Oct 11 02:09:52 2018
@@ -0,0 +1,58 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// I'm not sure this is actually *that* issue, but this seems oddly similar to the other XFAIL'ed cases.
+// 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 "[integer]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-conversion]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-unsigned-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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
+
+// RUN: rm -f %tmp
+// RUN: echo "[implicit-signed-integer-truncation]" >> %tmp
+// RUN: echo "fun:implicitUnsignedTruncation" >> %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 | 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 | 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 | 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 | FileCheck %s
+
+unsigned char implicitUnsignedTruncation(unsigned int argc) {
+ return argc; // BOOM
+// CHECK: {{.*}}unsigned-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) {
+ return implicitUnsignedTruncation(~0U);
+}
Copied: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp (from r344229, compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp?p2=compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp&p1=compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation-summary.cpp Thu Oct 11 02:09:52 2018
@@ -1,4 +1,4 @@
-// RUN: %clangxx -fsanitize=implicit-integer-truncation %s -o %t
+// RUN: %clangxx -fsanitize=implicit-unsigned-integer-truncation %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOTYPE
// RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-TYPE
// REQUIRES: !ubsan-standalone && !ubsan-standalone-static
@@ -8,6 +8,6 @@
int main() {
uint8_t t0 = (~(uint32_t(0)));
// CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:16
- // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16
+ // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: implicit-unsigned-integer-truncation {{.*}}summary.cpp:[[@LINE-2]]:16
return 0;
}
Added: compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c?rev=344231&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c (added)
+++ compiler-rt/trunk/test/ubsan/TestCases/ImplicitConversion/unsigned-integer-truncation.c Thu Oct 11 02:09:52 2018
@@ -0,0 +1,304 @@
+// RUN: %clang -x c -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang -x c -fsanitize=implicit-unsigned-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-unsigned-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-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
+// RUN: %clang -x c -fsanitize=implicit-unsigned-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-unsigned-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-unsigned-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-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
+
+// RUN: %clang -x c++ -fsanitize=implicit-unsigned-integer-truncation %s -DV0 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V0
+// RUN: %clang -x c++ -fsanitize=implicit-unsigned-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-unsigned-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-unsigned-integer-truncation %s -DV3 -o %t && %run %t 2>&1 | not FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V3
+// RUN: %clang -x c++ -fsanitize=implicit-unsigned-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-unsigned-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-unsigned-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-unsigned-integer-truncation %s -DV7 -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="implicit conversion" --check-prefixes=CHECK-V7
+
+#include <stdint.h>
+
+// 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.
+
+unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
+#line 100
+ return x;
+}
+
+unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
+#line 200
+ return x;
+}
+
+signed int convert_signed_int_to_signed_int(signed int x) {
+#line 300
+ return x;
+}
+
+signed char convert_signed_char_to_signed_char(signed char x) {
+#line 400
+ return x;
+}
+
+unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {
+#line 500
+ return x;
+}
+
+unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
+#line 600
+ return x;
+}
+
+signed int convert_unsigned_char_to_signed_int(unsigned char x) {
+#line 700
+ return x;
+}
+
+signed int convert_signed_char_to_signed_int(signed char x) {
+#line 800
+ return x;
+}
+
+signed int convert_unsigned_int_to_signed_int(unsigned int x) {
+#line 900
+ return x;
+}
+
+unsigned int convert_signed_int_to_unsigned_int(signed int x) {
+#line 1000
+ return x;
+}
+
+unsigned char convert_signed_int_to_unsigned_char(signed int x) {
+#line 1100
+ return x;
+}
+
+unsigned char convert_signed_char_to_unsigned_char(signed char x) {
+#line 1200
+ return x;
+}
+
+signed char convert_unsigned_char_to_signed_char(unsigned char x) {
+#line 1300
+ return x;
+}
+
+unsigned int convert_signed_char_to_unsigned_int(signed char x) {
+#line 1400
+ return x;
+}
+
+signed char convert_unsigned_int_to_signed_char(unsigned int x) {
+#line 1500
+ return x;
+}
+
+signed char convert_signed_int_to_signed_char(signed int x) {
+#line 1600
+ return x;
+}
+
+#line 1111 // !!!
+
+int main() {
+ // No bits set.
+ convert_unsigned_int_to_unsigned_int(0);
+ convert_unsigned_char_to_unsigned_char(0);
+ convert_signed_int_to_signed_int(0);
+ convert_signed_char_to_signed_char(0);
+ convert_unsigned_int_to_unsigned_char(0);
+ convert_unsigned_char_to_unsigned_int(0);
+ convert_unsigned_char_to_signed_int(0);
+ convert_signed_char_to_signed_int(0);
+ convert_unsigned_int_to_signed_int(0);
+ convert_signed_int_to_unsigned_int(0);
+ convert_signed_int_to_unsigned_char(0);
+ convert_signed_char_to_unsigned_char(0);
+ convert_unsigned_char_to_signed_char(0);
+ convert_signed_char_to_unsigned_int(0);
+ convert_unsigned_int_to_signed_char(0);
+ convert_signed_int_to_signed_char(0);
+
+ // One lowest bit set.
+ convert_unsigned_int_to_unsigned_int(1);
+ convert_unsigned_char_to_unsigned_char(1);
+ convert_signed_int_to_signed_int(1);
+ convert_signed_char_to_signed_char(1);
+ convert_unsigned_int_to_unsigned_char(1);
+ convert_unsigned_char_to_unsigned_int(1);
+ convert_unsigned_char_to_signed_int(1);
+ convert_signed_char_to_signed_int(1);
+ convert_unsigned_int_to_signed_int(1);
+ convert_signed_int_to_unsigned_int(1);
+ convert_signed_int_to_unsigned_char(1);
+ convert_signed_char_to_unsigned_char(1);
+ convert_unsigned_char_to_signed_char(1);
+ convert_signed_char_to_unsigned_int(1);
+ convert_unsigned_int_to_signed_char(1);
+ convert_signed_int_to_signed_char(1);
+
+#if defined(V0)
+ // All source bits set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)UINT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)UINT32_MAX);
+// CHECK-V0: {{.*}}unsigned-integer-truncation.c:500: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
+ convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)UINT32_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT32_MAX);
+ convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)UINT32_MAX);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT32_MAX);
+#elif defined(V1)
+ // Source 'Sign' bit set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MIN);
+ convert_signed_char_to_signed_char((int8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MIN);
+// CHECK-V1: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483648 (32-bit, unsigned) to type 'unsigned char' changed the value to 0 (8-bit, unsigned)
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MIN);
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((uint32_t)INT32_MIN);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MIN);
+#elif defined(V2)
+ // All bits except the source 'Sign' bit are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)INT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)INT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)INT32_MAX);
+// CHECK-V2: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483647 (32-bit, unsigned) to type 'unsigned char' changed the value to 255 (8-bit, unsigned)
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)INT32_MAX);
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)INT32_MAX);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)INT32_MAX);
+#elif defined(V3)
+ // All destination bits set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)UINT8_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)UINT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_char_to_signed_char((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_unsigned_char((uint32_t)UINT8_MAX);
+ convert_unsigned_char_to_unsigned_int((uint8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)UINT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)UINT8_MAX);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_char((int8_t)UINT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)UINT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)UINT8_MAX);
+ convert_unsigned_int_to_signed_char((uint32_t)UINT8_MAX);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)UINT8_MAX);
+#elif defined(V4)
+ // Destination 'sign' bit set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((uint32_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_unsigned_int((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((uint32_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_char((int32_t)(uint32_t)(uint8_t)INT8_MIN);
+#elif defined(V5)
+ // All bits except the destination 'sign' bit are set.
+ convert_unsigned_int_to_unsigned_int((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_unsigned_char_to_unsigned_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_char_to_signed_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char((~((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V5: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 4294967167 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned)
+ convert_unsigned_char_to_unsigned_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_unsigned_int((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_unsigned_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_char_to_unsigned_char((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)(uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)(uint8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((~((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_signed_char((int32_t)(~((uint32_t)(uint8_t)INT8_MIN)));
+#elif defined(V6)
+ // Only the source and destination sign bits are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MIN);
+ convert_signed_int_to_signed_int((int32_t)INT32_MIN);
+ convert_signed_char_to_signed_char((int8_t)INT8_MIN);
+ convert_unsigned_int_to_unsigned_char(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN));
+// CHECK-V6: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483776 (32-bit, unsigned) to type 'unsigned char' changed the value to 128 (8-bit, unsigned)
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MIN);
+ convert_signed_char_to_signed_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_int((uint32_t)INT32_MIN);
+ convert_signed_int_to_unsigned_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MIN);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MIN);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MIN);
+ convert_unsigned_int_to_signed_char((((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_signed_char((int32_t)(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+#elif defined(V7)
+ // All bits except the source and destination sign bits are set.
+ convert_unsigned_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_unsigned_char_to_unsigned_char((uint8_t)INT8_MAX);
+ convert_signed_int_to_signed_int((int32_t)INT32_MAX);
+ convert_signed_char_to_signed_char((int8_t)INT8_MAX);
+ convert_unsigned_int_to_unsigned_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+// CHECK-V7: {{.*}}unsigned-integer-truncation.c:500:10: runtime error: implicit conversion from type 'unsigned int' of value 2147483519 (32-bit, unsigned) to type 'unsigned char' changed the value to 127 (8-bit, unsigned)
+ convert_unsigned_char_to_unsigned_int((uint8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_int((uint8_t)INT8_MAX);
+ convert_signed_char_to_signed_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_int((uint32_t)INT32_MAX);
+ convert_signed_int_to_unsigned_char((int32_t)(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN))));
+ convert_signed_char_to_unsigned_char((int8_t)INT8_MAX);
+ convert_unsigned_char_to_signed_char((uint8_t)INT8_MAX);
+ convert_signed_char_to_unsigned_int((int8_t)INT8_MAX);
+ convert_unsigned_int_to_signed_char(~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+ convert_signed_int_to_signed_char((int32_t)~(((uint32_t)INT32_MIN) | ((uint32_t)(uint8_t)INT8_MIN)));
+#else
+#error Some V* needs to be defined!
+#endif
+
+ return 0;
+}
Removed: 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=344230&view=auto
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c (original)
+++ compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c (removed)
@@ -1,25 +0,0 @@
-// RUN: %clang -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
-
-#include <stdint.h>
-
-int main() {
-// 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.
- uint8_t n2 = 128;
- uint8_t n3 = 255;
- // Bools do not count
- _Bool b0 = (~((uint32_t)(0)));
- _Bool b1 = 255;
-
- // Explicit and-ing of bits will silence it.
- uint8_t nc0 = ((~((uint32_t)(0))) & 255);
-
- // Positive tests.
- uint8_t t0 = (~((uint32_t)(0)));
-// CHECK: implicit-conversion
-// CHECK-NOT: implicit-conversion
-
- return 0;
-}
Copied: compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c (from r344229, 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-signed-integer-truncation.c?p2=compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c&p1=compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c (original)
+++ compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-signed-integer-truncation.c Thu Oct 11 02:09:52 2018
@@ -1,4 +1,4 @@
-// RUN: %clang -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang -fsanitize=implicit-signed-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
#include <stdint.h>
@@ -14,10 +14,10 @@ int main() {
_Bool b1 = 255;
// Explicit and-ing of bits will silence it.
- uint8_t nc0 = ((~((uint32_t)(0))) & 255);
+ uint8_t nc0 = ((int32_t)(-1)) & 255;
// Positive tests.
- uint8_t t0 = (~((uint32_t)(0)));
+ uint8_t t0 = (int32_t)(-1);
// CHECK: implicit-conversion
// CHECK-NOT: implicit-conversion
Copied: compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c (from r344229, 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-unsigned-integer-truncation.c?p2=compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c&p1=compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c&r1=344229&r2=344231&rev=344231&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-integer-truncation.c (original)
+++ compiler-rt/trunk/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c Thu Oct 11 02:09:52 2018
@@ -1,4 +1,4 @@
-// RUN: %clang -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang -fsanitize=implicit-unsigned-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
#include <stdint.h>
More information about the llvm-commits
mailing list