(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
ubsan/
object-size-5.c
       1  /* { dg-do run } */
       2  /* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
       3  /* { dg-options "-fsanitize=object-size" } */
       4  
       5  /* Test structures with -fsanitize=object-size.  */
       6  
       7  #define N 20
       8  
       9  struct S { char *p; int i; };
      10  struct T { struct S *s; };
      11  
      12  __attribute__((noinline, noclone)) void
      13  f1 (int i)
      14  {
      15    volatile int j;
      16    struct S s;
      17    s.p = (char *) __builtin_calloc (N, 1);
      18    j = s.p[i];
      19    j = *(s.p + i);
      20    __builtin_free (s.p);
      21  }
      22  
      23  /* { dg-output "load of address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" } */
      24  /* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
      25  /* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
      26  /* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
      27  /* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" } */
      28  /* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
      29  /* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
      30  /* { dg-output "\[^\n\r]*\\^" } */
      31  
      32  int
      33  main ()
      34  {
      35    f1 (N);
      36    f1 (N - 1);
      37    return 0;
      38  }