1  /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
       2  
       3  #include "analyzer-decls.h"
       4  
       5  typedef __SIZE_TYPE__ size_t;
       6  
       7  #define NULL ((void *)0)
       8  
       9  extern void *malloc (size_t __size)
      10    __attribute__ ((__nothrow__ , __leaf__))
      11    __attribute__ ((__malloc__))
      12    __attribute__ ((__alloc_size__ (1)));
      13  extern void *realloc (void *__ptr, size_t __size)
      14    __attribute__ ((__nothrow__ , __leaf__))
      15    __attribute__ ((__warn_unused_result__))
      16    __attribute__ ((__alloc_size__ (2)));
      17  extern void free (void *__ptr)
      18    __attribute__ ((__nothrow__ , __leaf__));
      19  extern void *memset (void *__ptr, int __value, size_t __size);
      20  
      21  /* realloc where the region shrinks on success_with_move.  */
      22  
      23  void test_1 ()
      24  {
      25    char *p = malloc (16);
      26    if (!p)
      27      return;
      28    memset (p, 1, 16);
      29  
      30    char *q = realloc (p, 8);
      31    if (!q)
      32      {
      33        free (p);
      34        return;
      35      }
      36    else if (p != q)
      37      {
      38        __analyzer_dump_capacity (q); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)8'" } */
      39        __analyzer_eval (q[8] == 1); /* { dg-line eval } */
      40      
      41        /* { dg-warning "UNKNOWN" "warning" { target *-*-* } eval } */
      42        /* { dg-warning "heap-based buffer over-read" "warning" { target *-*-* } eval } */
      43        /* { dg-warning "use of uninitialized value" "warning" { target *-*-* } eval } */
      44      }
      45  
      46    free (q);
      47  }