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> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 9 | #include <stdint.h> |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 10 | #include <stdlib.h> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 11 | #include "sanitizer/asan_interface.h" |
| 12 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 13 | // MSVC provides _alloca instead of alloca. |
| 14 | #if defined(_MSC_VER) && !defined(alloca) |
| 15 | # define alloca _alloca |
| 16 | #endif |
| 17 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 18 | void *top, *bot; |
| 19 | |
| 20 | __attribute__((noinline)) void foo(int len) { |
| 21 | char x; |
| 22 | top = &x; |
| 23 | char array[len]; // NOLINT |
| 24 | assert(!(reinterpret_cast<uintptr_t>(array) & 31L)); |
| 25 | alloca(len); |
| 26 | for (int i = 0; i < 32; ++i) { |
| 27 | char array[i]; // NOLINT |
| 28 | bot = alloca(i); |
| 29 | assert(!(reinterpret_cast<uintptr_t>(bot) & 31L)); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | int main(int argc, char **argv) { |
| 34 | foo(32); |
| 35 | void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot); |
| 36 | assert(!q); |
| 37 | return 0; |
| 38 | } |