brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 7e77d96 Raw
51 lines · cpp
1// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t2// RUN: %env_asan_opts=detect_stack_use_after_return=0 %run %t 2>&13//4// REQUIRES: stable-runtime5 6// This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.7 8// MSVC doesn't support VLAs in the first place.9// UNSUPPORTED: msvc10 11#include "defines.h"12#include "sanitizer/asan_interface.h"13#include <assert.h>14#include <stdint.h>15#include <stdlib.h>16 17// MSVC provides _alloca instead of alloca.18#if defined(_MSC_VER) && !defined(alloca)19# define alloca _alloca20#endif21 22#if defined(__sun__) && defined(__svr4__)23#include <alloca.h>24#endif25 26void *top, *bot;27 28ATTRIBUTE_NOINLINE void foo(int len) {29  char x;30  top = &x;31  volatile char array[len];32  if (len)33    array[0] = 0;34  assert(!(reinterpret_cast<uintptr_t>(array) & 31L));35  alloca(len);36  for (int i = 0; i < 32; ++i) {37    volatile char array[i];38    if (i)39      array[0] = 0;40    bot = alloca(i);41    assert(!(reinterpret_cast<uintptr_t>(bot) & 31L));42  }43}44 45int main(int argc, char **argv) {46  foo(32);47  void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot);48  assert(!q);49  return 0;50}51