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 | |
| 6 | // This testcase checks that allocas and VLAs inside loop are correctly unpoisoned. |
| 7 | |
| 8 | #include <assert.h> |
| 9 | #include <alloca.h> |
| 10 | #include <stdint.h> |
| 11 | #include "sanitizer/asan_interface.h" |
| 12 | |
| 13 | void *top, *bot; |
| 14 | |
| 15 | __attribute__((noinline)) void foo(int len) { |
| 16 | char x; |
| 17 | top = &x; |
| 18 | char array[len]; // NOLINT |
| 19 | assert(!(reinterpret_cast<uintptr_t>(array) & 31L)); |
| 20 | alloca(len); |
| 21 | for (int i = 0; i < 32; ++i) { |
| 22 | char array[i]; // NOLINT |
| 23 | bot = alloca(i); |
| 24 | assert(!(reinterpret_cast<uintptr_t>(bot) & 31L)); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | int main(int argc, char **argv) { |
| 29 | foo(32); |
| 30 | void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot); |
| 31 | assert(!q); |
| 32 | return 0; |
| 33 | } |