Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-allocas %s -o %t |
| 2 | // RUN: %run %t 2>&1 |
| 3 | // |
| 4 | // REQUIRES: stable-runtime |
| 5 | // XFAIL: powerpc64 |
| 6 | |
| 7 | // This testcase checks correct interaction between VLAs and allocas. |
| 8 | |
| 9 | #include <assert.h> |
| 10 | #include <alloca.h> |
| 11 | #include <stdint.h> |
| 12 | #include "sanitizer/asan_interface.h" |
| 13 | |
| 14 | #define RZ 32 |
| 15 | |
| 16 | __attribute__((noinline)) void foo(int len) { |
| 17 | char *top, *bot; |
| 18 | // This alloca call should live until the end of foo. |
| 19 | char *alloca1 = (char *)alloca(len); |
| 20 | assert(!(reinterpret_cast<uintptr_t>(alloca1) & 31L)); |
| 21 | // This should be first poisoned address after loop. |
| 22 | top = alloca1 - RZ; |
| 23 | for (int i = 0; i < 32; ++i) { |
| 24 | // Check that previous alloca was unpoisoned at the end of iteration. |
| 25 | if (i) assert(!__asan_region_is_poisoned(bot, 96)); |
| 26 | // VLA is unpoisoned at the end of iteration. |
| 27 | volatile char array[i]; |
| 28 | assert(!(reinterpret_cast<uintptr_t>(array) & 31L)); |
| 29 | // Alloca is unpoisoned at the end of iteration, |
| 30 | // because dominated by VLA. |
| 31 | bot = (char *)alloca(i) - RZ; |
| 32 | } |
| 33 | // Check that all allocas from loop were unpoisoned correctly. |
| 34 | void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot + 1); |
| 35 | assert(q == top); |
| 36 | } |
| 37 | |
| 38 | int main(int argc, char **argv) { |
| 39 | foo(32); |
| 40 | return 0; |
| 41 | } |