1  /* PR middle-end/98166: bogus -Wmismatched-dealloc on user-defined allocator
       2     and inlining
       3     Verify that the allocator can be declared inline without a warning when
       4     it's associated with a standard deallocator.  Associating an inline
       5     deallocator with an allocator would cause false positives when the former
       6     calls a deallocation function the allocator isn't associated with, so
       7     that triggers a warning on declaration.
       8     { dg-do compile }
       9     { dg-options "-O2 -Wall" } */
      10  
      11  __attribute__ ((malloc (__builtin_free)))
      12  inline int*
      13  alloc_int (int n)
      14  {
      15    return (int*)__builtin_malloc (n + sizeof (int));
      16  }
      17  
      18  void test_nowarn_int (int n)
      19  {
      20    {
      21      int *p = alloc_int (n);
      22      __builtin_free (p);
      23    }
      24  
      25    {
      26      int *p = alloc_int (n);
      27      __builtin_free (p + 1);   // { dg-warning "\\\[-Wfree-nonheap-object" }
      28    }
      29  }
      30  
      31  
      32  inline void
      33  dealloc_long (long *p)
      34  {
      35    __builtin_free (p);         // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
      36  }
      37  
      38  __attribute__ ((malloc (dealloc_long)))
      39  long* alloc_long (int);       // { dg-warning "'malloc \\\(dealloc_long\\\)' attribute ignored with deallocation functions declared 'inline'" }
      40  
      41  void test_nowarn_long (int n)
      42  {
      43    {
      44      long *p = alloc_long (n);
      45      dealloc_long (p);
      46    }
      47  
      48    {
      49      long *p = alloc_long (n);
      50      dealloc_long (p + 1);
      51    }
      52  }