Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/null-deref-pr102671-2.c

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