(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
null-deref-pr102671-1.c
       1  /* { dg-additional-options "-O2 -Wno-shift-count-overflow" } */
       2  
       3  struct lisp;
       4  union vectorlike_header { long size; };
       5  struct Lisp_Symbol { void *unused; };
       6  extern struct Lisp_Symbol lispsym[];
       7  
       8  static _Bool
       9  TAGGEDP (struct lisp *a, unsigned tag)
      10  {
      11    return ! (((unsigned) (long) a - tag) & 7);
      12  }
      13  
      14  static _Bool
      15  VECTORLIKEP (struct lisp *x)
      16  {
      17    return TAGGEDP (x, 5);
      18  }
      19  
      20  static _Bool
      21  PSEUDOVECTOR_TYPEP (union vectorlike_header const *a, int code)
      22  {
      23    long PSEUDOVECTOR_FLAG = 1L << 62;
      24    long PVEC_TYPE_MASK = 0x3fL << 24;
      25    return ((a->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))
      26  	  == (PSEUDOVECTOR_FLAG | (code << 24)));
      27  }
      28  
      29  static _Bool
      30  PSEUDOVECTORP (struct lisp *a, int code)
      31  {
      32    if (! VECTORLIKEP (a))
      33      return 0;
      34    else
      35      return PSEUDOVECTOR_TYPEP ((union vectorlike_header *) ((char *) a - 5),
      36  			       code);
      37  }
      38  
      39  static struct lisp *
      40  builtin_lisp_symbol (int index)
      41  {
      42    return (struct lisp *) (index * sizeof *lispsym);
      43  }
      44  
      45  static _Bool
      46  NILP (struct lisp *x)
      47  {
      48    return x == builtin_lisp_symbol (0);
      49  }
      50  
      51  
      52  void wrong_type_argument (struct lisp *, struct lisp *);
      53  
      54  static void
      55  CHECK_TYPE (int ok, struct lisp *predicate, struct lisp *x)
      56  {
      57    if (!ok)
      58      wrong_type_argument (predicate, x);
      59  }
      60  
      61  
      62  struct buffer
      63  {
      64    union vectorlike_header header;
      65    struct buffer *base_buffer;
      66    int window_count;
      67  };
      68  
      69  static _Bool
      70  BUFFERP (struct lisp *a)
      71  {
      72    return PSEUDOVECTORP (a, 12);
      73  }
      74  
      75  static struct buffer *
      76  XBUFFER (struct lisp *a)
      77  {
      78    return (struct buffer *) ((char *) a - 5);
      79  }
      80  
      81  
      82  struct window
      83  {
      84    union vectorlike_header header;
      85    struct lisp *next;
      86    struct lisp *contents;
      87  };
      88  
      89  static _Bool
      90  WINDOWP (struct lisp *a)
      91  {
      92    return PSEUDOVECTORP (a, 12);
      93  }
      94  
      95  static void
      96  CHECK_WINDOW (struct lisp *x)
      97  {
      98    CHECK_TYPE (WINDOWP (x), builtin_lisp_symbol (1360), x);
      99  }
     100  
     101  static struct window *
     102  XWINDOW (struct lisp *a)
     103  {
     104    return (struct window *) ((char *) a - 5);
     105  }
     106  
     107  static void
     108  wset_combination (struct window *w, _Bool horflag, struct lisp *val)
     109  {
     110    w->contents = val;
     111  }
     112  
     113  extern struct lisp *selected_window;
     114  
     115  struct window *
     116  decode_live_window (register struct lisp *window)
     117  {
     118    if (NILP (window))
     119      return XWINDOW (selected_window);
     120    CHECK_TYPE (WINDOWP (window) && BUFFERP (XWINDOW (window)->contents),
     121  	      builtin_lisp_symbol (1351), window);
     122    return XWINDOW (window);
     123  }
     124  
     125  struct window *
     126  decode_any_window (register struct lisp *window)
     127  {
     128    struct window *w;
     129    if (NILP (window))
     130      return XWINDOW (selected_window);
     131    CHECK_WINDOW (window);
     132    w = XWINDOW (window);
     133    return w;
     134  }
     135  
     136  static void
     137  adjust_window_count (struct window *w, int arg)
     138  {
     139    if (BUFFERP (w->contents))
     140      {
     141        struct buffer *b = XBUFFER (w->contents);
     142        if (b->base_buffer)
     143  	b = b->base_buffer;
     144        b->window_count += arg;
     145      }
     146  }
     147  
     148  void
     149  wset_buffer (struct window *w, struct lisp *val)
     150  {
     151    adjust_window_count (w, -1);
     152    w->contents = val;
     153    adjust_window_count (w, 1);
     154  }
     155  
     156  void
     157  delete_all_child_windows (struct lisp *window)
     158  {
     159    struct window *w = XWINDOW (window);
     160    if (!NILP (w->next))
     161      delete_all_child_windows (w->next);
     162    if (WINDOWP (w->contents))
     163      {
     164        delete_all_child_windows (w->contents);
     165        wset_combination (w, 0, builtin_lisp_symbol (0));
     166      }
     167  }