Files
clang-p2996/compiler-rt/test/ubsan_minimal/TestCases/implicit-unsigned-integer-truncation.c
Roman Lebedev d32c0d1466 [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

llvm-svn: 344231
2018-10-11 09:09:52 +00:00

26 lines
695 B
C

// RUN: %clang -fsanitize=implicit-unsigned-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;
}