(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
hwasan/
unprotected-allocas-0.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target hwaddress_exec } */
       3  /* { dg-additional-options "--param hwasan-instrument-allocas=0 -save-temps" } */
       4  /* Only run this test without optimisation.  When running with optimisation we
       5     use the unprotected-allocas-1.c file that also checks there are no memory
       6     tagging calls (since when optimised the only variable on the stack should be
       7     the vararray/alloca).  */
       8  /* { dg-skip-if "" { *-*-* } { "-O1" "-O2" "-O3" } { "" } } */
       9  
      10  #define alloca __builtin_alloca
      11  #define assert(x) if (!(x)) __builtin_abort ()
      12  
      13  char tag_of (void * x) { return ((unsigned long long)x) >> 56; }
      14  
      15  int __attribute__ ((noinline))
      16  using_alloca (int num)
      17  {
      18    int retval = 0;
      19    int *big_array = (int*)alloca (num * sizeof (int));
      20    char alloca_tag = tag_of (big_array);
      21    assert (alloca_tag == 0);
      22    for (int i = 0; i < num; ++i) {
      23        retval += big_array[i];
      24    }
      25    return retval;
      26  }
      27  
      28  int __attribute__ ((noinline))
      29  using_vararray (int num)
      30  {
      31    int retval = 0;
      32    int big_array[num];
      33    char vararray_tag = tag_of (big_array);
      34    assert (vararray_tag == 0);
      35    for (int i = 0; i < num; ++i) {
      36        retval += big_array[i];
      37    }
      38    return retval;
      39  }
      40  
      41  int main()
      42  {
      43    using_alloca (16);
      44    using_vararray (12);
      45    return 0;
      46  }