(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
asan/
alloca_loop_unpoisoning.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target alloca } */
       3  /* { dg-options "--param=asan-use-after-return=0" } */
       4  
       5  /* This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.  */
       6  
       7  #include <assert.h>
       8  #include <stdint.h>
       9  #include <stdlib.h>
      10  #include <stdio.h>
      11  #include "sanitizer/asan_interface.h"
      12  
      13  void *top, *bot;
      14  volatile int thirty_two = 32;
      15  
      16  __attribute__((noinline)) void foo(int len) {
      17    char x;
      18    top = &x;
      19    volatile char array[len];
      20    assert(!((uintptr_t) array & 31L));
      21    void *p = __builtin_alloca(len);
      22    for (int i = 0; i < thirty_two; ++i) {
      23      char array[i];
      24      bot = array;
      25      /* Just to prevent optimization.  */
      26      printf("%p\n", bot);
      27      assert(!((uintptr_t) bot & 31L));
      28    }
      29  }
      30  
      31  int main(int argc, char **argv) {
      32    foo(thirty_two);
      33    void *q = __asan_region_is_poisoned(bot, (char *)top - (char *)bot);
      34    assert(!q);
      35    return 0;
      36  }