Debian Codegraph @

gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c

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