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