]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/ubsan_minimal/TestCases/implicit-integer-truncation.c
Vendor import of compiler-rt trunk r338536:
[FreeBSD/FreeBSD.git] / test / ubsan_minimal / TestCases / implicit-integer-truncation.c
1 // RUN: %clang -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
2
3 #include <stdint.h>
4
5 int main() {
6 // CHECK-NOT: integer-truncation.c
7
8   // Negative tests. Even if they produce unexpected results, this sanitizer does not care.
9   int8_t n0 = (~((uint32_t)(0))); // ~0 -> -1, but do not warn.
10   uint8_t n2 = 128;
11   uint8_t n3 = 255;
12   // Bools do not count
13   _Bool b0 = (~((uint32_t)(0)));
14   _Bool b1 = 255;
15
16   // Explicit and-ing of bits will silence it.
17   uint8_t nc0 = ((~((uint32_t)(0))) & 255);
18
19   // Positive tests.
20   uint8_t t0 = (~((uint32_t)(0)));
21 // CHECK: implicit-conversion
22
23   return 0;
24 }