Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | // Test various levels of coverage |
| 2 | // |
| 3 | // RUN: mkdir -p %T/coverage-levels |
| 4 | // RUN: OPT=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 5 | // RUN: %clangxx -fsanitize=shift -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func %s -o %t |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 6 | // RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 7 | // RUN: %clangxx -fsanitize=undefined -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=func %s -o %t |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 8 | // RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 9 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 10 | // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=func %s -o %t |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 11 | // RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 12 | // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=bb %s -o %t |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 13 | // RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 14 | // RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=edge %s -o %t |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 15 | // RUN: UBSAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 16 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 17 | // Coverage is not yet implemented in TSan. |
| 18 | // XFAIL: ubsan-tsan |
| 19 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | volatile int sink; |
| 21 | int main(int argc, char **argv) { |
| 22 | int shift = argc * 32; |
| 23 | #if GOOD_SHIFT |
| 24 | shift = 3; |
| 25 | #endif |
| 26 | if ((argc << shift) == 16) // False. |
| 27 | return 1; |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | // CHECK_WARN: shift exponent 32 is too large |
| 32 | // CHECK_NOWARN-NOT: ERROR |
| 33 | // FIXME: Currently, coverage instrumentation kicks in after ubsan, so we get |
| 34 | // more than the minimal number of instrumented blocks. |
| 35 | // FIXME: Currently, ubsan with -fno-sanitize-recover and w/o asan will fail |
| 36 | // to dump coverage. |
| 37 | // CHECK1: 1 PCs written |
| 38 | // CHECK2: 3 PCs written |
| 39 | // CHECK3: 4 PCs written |