summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-08-02 17:33:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-08-02 17:33:19 +0000
commit005b7ed8f76756d94ef6266ded755ab7863cb936 (patch)
treede2aa8f0c2f604d3b4f81a94dd20ea0c50bf1e68 /test
parent93c1b73a09a52d4a265f683bf1954b08bb430049 (diff)
Notes
Diffstat (limited to 'test')
-rw-r--r--test/asan/TestCases/intercept-rethrow-exception.cc2
-rw-r--r--test/fuzzer/ImplicitIntegerTruncationTest.cpp27
-rw-r--r--test/fuzzer/fuzzer-implicit-integer-truncation.test5
-rw-r--r--test/profile/Inputs/instrprof-gcov-fork.c15
-rw-r--r--test/profile/Inputs/instrprof-gcov-fork.c.gcov23
-rw-r--r--test/profile/Inputs/instrprof-gcov-switch1.c18
-rw-r--r--test/profile/Inputs/instrprof-gcov-switch1.c.gcov23
-rw-r--r--test/profile/Inputs/instrprof-gcov-switch2.c18
-rw-r--r--test/profile/Inputs/instrprof-gcov-switch2.c.gcov23
-rw-r--r--test/profile/Posix/instrprof-gcov-fork.test12
-rw-r--r--test/profile/instrprof-gcov-switch.test16
-rw-r--r--test/profile/instrprof-set-dir-mode.c48
-rw-r--r--test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c20
-rw-r--r--test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp13
-rw-r--r--test/ubsan/TestCases/ImplicitConversion/integer-truncation.c63
-rw-r--r--test/ubsan_minimal/TestCases/implicit-integer-truncation.c24
-rw-r--r--test/xray/TestCases/Posix/profiling-multi-threaded.cc5
-rw-r--r--test/xray/TestCases/Posix/profiling-single-threaded.cc7
18 files changed, 357 insertions, 5 deletions
diff --git a/test/asan/TestCases/intercept-rethrow-exception.cc b/test/asan/TestCases/intercept-rethrow-exception.cc
index fa9ea7d3b09ec..e81dc5398a989 100644
--- a/test/asan/TestCases/intercept-rethrow-exception.cc
+++ b/test/asan/TestCases/intercept-rethrow-exception.cc
@@ -1,7 +1,7 @@
// Regression test for
// https://bugs.llvm.org/show_bug.cgi?id=32434
-// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: %clangxx_asan -fexceptions -O0 %s -o %t
// RUN: %run %t
#include <assert.h>
diff --git a/test/fuzzer/ImplicitIntegerTruncationTest.cpp b/test/fuzzer/ImplicitIntegerTruncationTest.cpp
new file mode 100644
index 0000000000000..cb935da0c13e3
--- /dev/null
+++ b/test/fuzzer/ImplicitIntegerTruncationTest.cpp
@@ -0,0 +1,27 @@
+// 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;
+}
diff --git a/test/fuzzer/fuzzer-implicit-integer-truncation.test b/test/fuzzer/fuzzer-implicit-integer-truncation.test
new file mode 100644
index 0000000000000..212559bdca3c4
--- /dev/null
+++ b/test/fuzzer/fuzzer-implicit-integer-truncation.test
@@ -0,0 +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: Test unit written to ./crash-
diff --git a/test/profile/Inputs/instrprof-gcov-fork.c b/test/profile/Inputs/instrprof-gcov-fork.c
new file mode 100644
index 0000000000000..818c459c50ddc
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-fork.c
@@ -0,0 +1,15 @@
+#include <unistd.h>
+
+void func1() {}
+void func2() {}
+
+int main(void)
+{
+ func1();
+
+ fork();
+
+ func2();
+
+ return 0;
+}
diff --git a/test/profile/Inputs/instrprof-gcov-fork.c.gcov b/test/profile/Inputs/instrprof-gcov-fork.c.gcov
new file mode 100644
index 0000000000000..9591f62ed602c
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-fork.c.gcov
@@ -0,0 +1,23 @@
+// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-fork.c
+// CHECK-NEXT: -: 0:Graph:instrprof-gcov-fork.gcno
+// CHECK-NEXT: -: 0:Data:instrprof-gcov-fork.gcda
+// CHECK-NEXT: -: 0:Runs:1
+// CHECK-NEXT: -: 0:Programs:1
+// CHECK-NEXT: -: 1:#include <unistd.h>
+// CHECK-NEXT: -: 2:
+// CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100%
+// CHECK-NEXT: 1: 3:void func1() {}
+// CHECK-NEXT:function func2 called 2 returned 100% blocks executed 100%
+// CHECK-NEXT: 2: 4:void func2() {}
+// CHECK-NEXT: -: 5:
+// CHECK-NEXT:function main called 1 returned 100% blocks executed 100%
+// CHECK-NEXT: -: 6:int main(void)
+// CHECK-NEXT: -: 7:{
+// CHECK-NEXT: 1: 8: func1();
+// CHECK-NEXT: -: 9:
+// CHECK-NEXT: 1: 10: fork();
+// CHECK-NEXT: -: 11:
+// CHECK-NEXT: 2: 12: func2();
+// CHECK-NEXT: -: 13:
+// CHECK-NEXT: 2: 14: return 0;
+// CHECK-NEXT: -: 15:}
diff --git a/test/profile/Inputs/instrprof-gcov-switch1.c b/test/profile/Inputs/instrprof-gcov-switch1.c
new file mode 100644
index 0000000000000..25544323c5556
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-switch1.c
@@ -0,0 +1,18 @@
+int main(void)
+{
+ int i = 22;
+
+ switch (i) {
+ case 7:
+ break;
+
+ case 22:
+ i = 7;
+ break;
+
+ case 42:
+ break;
+ }
+
+ return 0;
+}
diff --git a/test/profile/Inputs/instrprof-gcov-switch1.c.gcov b/test/profile/Inputs/instrprof-gcov-switch1.c.gcov
new file mode 100644
index 0000000000000..7d136dc98ec3a
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-switch1.c.gcov
@@ -0,0 +1,23 @@
+// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-switch1.c
+// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch1.gcno
+// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch1.gcda
+// CHECK-NEXT: -: 0:Runs:1
+// CHECK-NEXT: -: 0:Programs:1
+// CHECK-NEXT: -: 1:int main(void)
+// CHECK-NEXT: -: 2:{
+// CHECK-NEXT: 2: 3: int i = 22;
+// CHECK-NEXT: -: 4:
+// CHECK-NEXT: 2: 5: switch (i) {
+// CHECK-NEXT: -: 6: case 7:
+// CHECK-NEXT: #####: 7: break;
+// CHECK-NEXT: -: 8:
+// CHECK-NEXT: -: 9: case 22:
+// CHECK-NEXT: 1: 10: i = 7;
+// CHECK-NEXT: 1: 11: break;
+// CHECK-NEXT: -: 12:
+// CHECK-NEXT: -: 13: case 42:
+// CHECK-NEXT: #####: 14: break;
+// CHECK-NEXT: -: 15: }
+// CHECK-NEXT: -: 16:
+// CHECK-NEXT: 1: 17: return 0;
+// CHECK-NEXT: -: 18:}
diff --git a/test/profile/Inputs/instrprof-gcov-switch2.c b/test/profile/Inputs/instrprof-gcov-switch2.c
new file mode 100644
index 0000000000000..14e8a84de5079
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-switch2.c
@@ -0,0 +1,18 @@
+int main(void)
+{
+ int i = 22;
+
+ switch (i) {
+ case 7:
+ break;
+
+ case 22:
+ i = 7;
+
+ case 42:
+ i = 22;
+ break;
+ }
+
+ return 0;
+}
diff --git a/test/profile/Inputs/instrprof-gcov-switch2.c.gcov b/test/profile/Inputs/instrprof-gcov-switch2.c.gcov
new file mode 100644
index 0000000000000..67f408606a394
--- /dev/null
+++ b/test/profile/Inputs/instrprof-gcov-switch2.c.gcov
@@ -0,0 +1,23 @@
+// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-gcov-switch2.c
+// CHECK-NEXT: -: 0:Graph:instrprof-gcov-switch2.gcno
+// CHECK-NEXT: -: 0:Data:instrprof-gcov-switch2.gcda
+// CHECK-NEXT: -: 0:Runs:1
+// CHECK-NEXT: -: 0:Programs:1
+// CHECK-NEXT: -: 1:int main(void)
+// CHECK-NEXT: -: 2:{
+// CHECK-NEXT: 3: 3: int i = 22;
+// CHECK-NEXT: -: 4:
+// CHECK-NEXT: 3: 5: switch (i) {
+// CHECK-NEXT: -: 6: case 7:
+// CHECK-NEXT: #####: 7: break;
+// CHECK-NEXT: -: 8:
+// CHECK-NEXT: -: 9: case 22:
+// CHECK-NEXT: 1: 10: i = 7;
+// CHECK-NEXT: -: 11:
+// CHECK-NEXT: -: 12: case 42:
+// CHECK-NEXT: 1: 13: i = 22;
+// CHECK-NEXT: 1: 14: break;
+// CHECK-NEXT: -: 15: }
+// CHECK-NEXT: -: 16:
+// CHECK-NEXT: 1: 17: return 0;
+// CHECK-NEXT: -: 18:}
diff --git a/test/profile/Posix/instrprof-gcov-fork.test b/test/profile/Posix/instrprof-gcov-fork.test
new file mode 100644
index 0000000000000..436d7e663faa5
--- /dev/null
+++ b/test/profile/Posix/instrprof-gcov-fork.test
@@ -0,0 +1,12 @@
+XFAIL: *
+
+RUN: mkdir -p %t.d
+RUN: cd %t.d
+
+RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-fork.c
+RUN: test -f instrprof-gcov-fork.gcno
+
+RUN: rm -f instrprof-gcov-fork.gcda
+RUN: %run %t
+RUN: llvm-cov gcov -b -c instrprof-gcov-fork.gcda
+RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-fork.c.gcov %S/../Inputs/instrprof-gcov-fork.c.gcov
diff --git a/test/profile/instrprof-gcov-switch.test b/test/profile/instrprof-gcov-switch.test
new file mode 100644
index 0000000000000..9c43a93dc646a
--- /dev/null
+++ b/test/profile/instrprof-gcov-switch.test
@@ -0,0 +1,16 @@
+RUN: mkdir -p %t.d
+RUN: cd %t.d
+
+RUN: %clang --coverage -o %t %S/Inputs/instrprof-gcov-switch1.c
+RUN: test -f instrprof-gcov-switch1.gcno
+RUN: rm -f instrprof-gcov-switch1.gcda
+RUN: %run %t
+RUN: llvm-cov gcov instrprof-gcov-switch1.gcda
+RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-switch1.c.gcov %S/Inputs/instrprof-gcov-switch1.c.gcov
+
+RUN: %clang --coverage -o %t %S/Inputs/instrprof-gcov-switch2.c
+RUN: test -f instrprof-gcov-switch2.gcno
+RUN: rm -f instrprof-gcov-switch2.gcda
+RUN: %run %t
+RUN: llvm-cov gcov instrprof-gcov-switch2.gcda
+RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-switch2.c.gcov %S/Inputs/instrprof-gcov-switch2.c.gcov
diff --git a/test/profile/instrprof-set-dir-mode.c b/test/profile/instrprof-set-dir-mode.c
new file mode 100644
index 0000000000000..25eb29db533d3
--- /dev/null
+++ b/test/profile/instrprof-set-dir-mode.c
@@ -0,0 +1,48 @@
+// UNSUPPORTED: windows
+// RUN: %clang_pgogen -o %t.bin %s -DTESTPATH=\"%t.dir\"
+// RUN: rm -rf %t.dir
+// RUN: %run %t.bin
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+void __llvm_profile_set_dir_mode(unsigned Mode);
+unsigned __llvm_profile_get_dir_mode(void);
+void __llvm_profile_recursive_mkdir(char *Path);
+
+static int test(unsigned Mode, const char *TestDir) {
+ int Ret = 0;
+
+ /* Create a dir and set the mode accordingly. */
+ char *Dir = strdup(TestDir);
+ if (!Dir)
+ return -1;
+ __llvm_profile_set_dir_mode(Mode);
+ __llvm_profile_recursive_mkdir(Dir);
+
+ if (Mode != __llvm_profile_get_dir_mode())
+ Ret = -1;
+ else {
+ const unsigned Expected = ~umask(0) & Mode;
+ struct stat DirSt;
+ if (stat(Dir, &DirSt) == -1)
+ Ret = -1;
+ else if (DirSt.st_mode != Expected) {
+ printf("Modes do not match: Expected %o but found %o (%s)\n", Expected,
+ DirSt.st_mode, Dir);
+ Ret = -1;
+ }
+ }
+
+ free(Dir);
+ return Ret;
+}
+
+int main(void) {
+ if (test(S_IFDIR | 0777, TESTPATH "/foo/bar/baz/") ||
+ test(S_IFDIR | 0666, TESTPATH "/foo/bar/qux/"))
+ return -1;
+ return 0;
+}
diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c
new file mode 100644
index 0000000000000..13d4dca4ff141
--- /dev/null
+++ b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-blacklist.c
@@ -0,0 +1,20 @@
+// 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: 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
+
+unsigned char implicitTruncation(unsigned int argc) {
+ return argc; // BOOM
+}
+
+int main(int argc, char **argv) {
+ return implicitTruncation(~0U);
+}
diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp
new file mode 100644
index 0000000000000..a92e01fb4ab6a
--- /dev/null
+++ b/test/ubsan/TestCases/ImplicitConversion/integer-truncation-summary.cpp
@@ -0,0 +1,13 @@
+// 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;
+}
diff --git a/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c
new file mode 100644
index 0000000000000..995eb7d0faf46
--- /dev/null
+++ b/test/ubsan/TestCases/ImplicitConversion/integer-truncation.c
@@ -0,0 +1,63 @@
+// RUN: %clang -x c -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+// RUN: %clangxx -x c++ -fsanitize=implicit-integer-truncation %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
+
+#include <stdint.h>
+
+#if !defined(__cplusplus)
+#define bool _Bool
+#endif
+
+int main() {
+// CHECK-NOT: integer-truncation.c
+
+ // 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;
+
+ // Explicit casts
+ uint8_t i0 = (uint8_t)(~((uint32_t)0));
+
+#if defined(__cplusplus)
+ uint8_t i1 = uint8_t(~(uint32_t(0)));
+ uint8_t i2 = static_cast<uint8_t>(~(uint32_t(0)));
+#endif
+
+ // Positive tests.
+
+ uint8_t t_b0 = (~((uint16_t)(0)));
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
+
+ uint8_t t_b1 = (~((uint32_t)0));
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
+ uint16_t t_b2 = (~((uint32_t)0));
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit, unsigned)
+
+ uint8_t t_b3 = ~((uint64_t)0);
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:18: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint8_t' (aka 'unsigned char') changed the value to 255 (8-bit, unsigned)
+ uint16_t t_b4 = ~((uint64_t)0);
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint16_t' (aka 'unsigned short') changed the value to 65535 (16-bit, unsigned)
+ uint32_t t_b5 = ~((uint64_t)0);
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:19: runtime error: implicit conversion from type 'uint64_t' (aka 'unsigned long{{[^']*}}') of value 18446744073709551615 (64-bit, unsigned) to type 'uint32_t' (aka 'unsigned int') changed the value to 4294967295 (32-bit, unsigned)
+
+ int8_t t1 = 255;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 255 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to -1 (8-bit, signed)
+ uint8_t t2 = 256;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:16: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 0 (8-bit, unsigned)
+ int8_t t3 = 256;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 256 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to 0 (8-bit, signed)
+ uint8_t t4 = 257;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:16: runtime error: implicit conversion from type 'int' of value 257 (32-bit, signed) to type 'uint8_t' (aka 'unsigned char') changed the value to 1 (8-bit, unsigned)
+ int8_t t5 = 257;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 257 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to 1 (8-bit, signed)
+ int8_t t6 = 128;
+// CHECK: {{.*}}integer-truncation.c:[[@LINE-1]]:15: runtime error: implicit conversion from type 'int' of value 128 (32-bit, signed) to type 'int8_t' (aka 'signed char') changed the value to -128 (8-bit, signed)
+
+ return 0;
+}
diff --git a/test/ubsan_minimal/TestCases/implicit-integer-truncation.c b/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
new file mode 100644
index 0000000000000..1db6e6976815c
--- /dev/null
+++ b/test/ubsan_minimal/TestCases/implicit-integer-truncation.c
@@ -0,0 +1,24 @@
+// 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: integer-truncation.c
+
+ // 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
+
+ return 0;
+}
diff --git a/test/xray/TestCases/Posix/profiling-multi-threaded.cc b/test/xray/TestCases/Posix/profiling-multi-threaded.cc
index 7ccad1bac1fd9..45e5e70226da5 100644
--- a/test/xray/TestCases/Posix/profiling-multi-threaded.cc
+++ b/test/xray/TestCases/Posix/profiling-multi-threaded.cc
@@ -51,7 +51,8 @@ volatile int buffer_counter = 0;
assert(__xray_log_finalize() == XRayLogInitStatus::XRAY_LOG_FINALIZED);
assert(__xray_log_process_buffers(process_buffer) ==
XRayLogFlushStatus::XRAY_LOG_FLUSHED);
- // We're running three threds, so we expect three buffers.
- assert(buffer_counter == 3);
+ // We're running three threads, so we expect four buffers (including the file
+ // header buffer).
+ assert(buffer_counter == 4);
assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
}
diff --git a/test/xray/TestCases/Posix/profiling-single-threaded.cc b/test/xray/TestCases/Posix/profiling-single-threaded.cc
index fd508b1acd147..fc518145edbba 100644
--- a/test/xray/TestCases/Posix/profiling-single-threaded.cc
+++ b/test/xray/TestCases/Posix/profiling-single-threaded.cc
@@ -47,7 +47,10 @@ volatile int buffer_counter = 0;
f0();
assert(__xray_log_process_buffers(process_buffer) ==
XRayLogFlushStatus::XRAY_LOG_FLUSHED);
- assert(buffer_counter == 1);
+ // There's always at least one buffer, containing the profile file header. We
+ // assert that we have two, to indicate that we're expecting exactly one
+ // thread's worth of data.
+ assert(buffer_counter == 2);
assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
// Let's reset the counter.
@@ -60,6 +63,6 @@ volatile int buffer_counter = 0;
f0();
assert(__xray_log_process_buffers(process_buffer) ==
XRayLogFlushStatus::XRAY_LOG_FLUSHED);
- assert(buffer_counter == 1);
+ assert(buffer_counter == 2);
assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
}