(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
null-deref-pr102671-2.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  struct Lisp_Cons { struct lisp *cdr; };
       8  
       9  static struct Lisp_Cons *
      10  XCONS (struct lisp *a)
      11  {
      12    return (struct Lisp_Cons *) ((char *) a - 3);
      13  }
      14  
      15  static struct lisp *
      16  XCDR (struct lisp *c)
      17  {
      18    return XCONS (c)->cdr;
      19  }
      20  
      21  static _Bool
      22  TAGGEDP (struct lisp *a, unsigned tag)
      23  {
      24    return ! (((unsigned) (long) a - tag) & 7);
      25  }
      26  
      27  static _Bool
      28  VECTORLIKEP (struct lisp *x)
      29  {
      30    return TAGGEDP (x, 5);
      31  }
      32  
      33  static _Bool
      34  PSEUDOVECTOR_TYPEP (union vectorlike_header const *a, int code)
      35  {
      36    long PSEUDOVECTOR_FLAG = 1L << 62;
      37    long PVEC_TYPE_MASK = 0x3fL << 24;
      38    return ((a->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK)) /* { dg-bogus "dereference of NULL 'time'" "PR analyzer/107526" { xfail *-*-* } } */
      39  	  == (PSEUDOVECTOR_FLAG | (code << 24)));
      40  }
      41  
      42  static _Bool
      43  PSEUDOVECTORP (struct lisp *a, int code)
      44  {
      45    if (! VECTORLIKEP (a))
      46      return 0;
      47    else
      48      return PSEUDOVECTOR_TYPEP ((union vectorlike_header *) ((char *) a - 5),
      49  			       code);
      50  }
      51  
      52  static _Bool
      53  FIXNUMP (struct lisp *x)
      54  {
      55    return ! (((unsigned) (long) x - 2) & 3);
      56  }
      57  
      58  static _Bool
      59  BIGNUMP (struct lisp *x)
      60  {
      61    return PSEUDOVECTORP (x, 2);
      62  }
      63  
      64  void some_function ();
      65  
      66  static void
      67  decode_time_components (struct lisp *low)
      68  {
      69    if (BIGNUMP (low))
      70      some_function ();
      71  }
      72  
      73  _Bool
      74  Ftime_convert (struct lisp *time)
      75  {
      76    decode_time_components (time ? XCDR (time) : time);
      77    return BIGNUMP (time);
      78  }