Debian Codegraph @

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

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