(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
attr-alloc_size.c
       1  /* { dg-do compile } */
       2  /* { dg-options "-O2 -Wall -Wno-array-bounds -ftrack-macro-expansion=0" } */
       3  
       4  extern void abort (void);
       5  
       6  #include "../gcc.c-torture/execute/builtins/chk.h"
       7  
       8  extern char *mallocminus1(int size) __attribute__((alloc_size(-1))); /* { dg-warning ".alloc_size. attribute argument value .-1. exceeds the number of function parameters 1" } */
       9  extern char *malloc0(int size) __attribute__((alloc_size(0))); /* { dg-warning ".alloc_size. attribute argument value .0. does not refer to a function parameter" } */
      10  extern char *malloc1(int size) __attribute__((alloc_size(1)));
      11  extern char *malloc2(int empty, int size) __attribute__((alloc_size(2)));
      12  extern char *calloc1(int size, int elements) __attribute__((alloc_size(1,2)));
      13  extern char *calloc2(int size, int empty, int elements) __attribute__((alloc_size(1,3)));
      14  extern char *balloc1(void *size) __attribute__((alloc_size(1)));   /* { dg-warning ".alloc_size. attribute argument value .1. refers to parameter type .void *." } */
      15  
      16  void
      17  test (void)
      18  {
      19    char *p;
      20  
      21    p = malloc0 (6);
      22    strcpy (p, "Hello");
      23    p = malloc1 (6);
      24    strcpy (p, "Hello");
      25    strcpy (p, "Hello World"); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "strcpy" } */
      26    p = malloc2 (__INT_MAX__ >= 1700000 ? 424242 : __INT_MAX__ / 4, 6);
      27    strcpy (p, "World");
      28    strcpy (p, "Hello World"); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "strcpy" } */
      29    p = calloc1 (2, 5);
      30    strcpy (p, "World");
      31    strcpy (p, "Hello World"); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "strcpy" } */
      32    p = calloc2 (2, __INT_MAX__ >= 1700000 ? 424242 : __INT_MAX__ / 4, 5);
      33    strcpy (p, "World");
      34    strcpy (p, "Hello World"); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "strcpy" } */
      35  }
      36