Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/null-deref-pr105755.c

raw
1 /* { dg-require-effective-target int32plus } */
2 /* { dg-additional-options "-Wno-analyzer-too-complex -Wno-analyzer-symbol-too-complex -O2" } */
3
4 typedef long int ptrdiff_t;
5 typedef long int EMACS_INT;
6 typedef long int intmax_t;
7
8 enum Lisp_Type
9 {
10 Lisp_Symbol = 0,
11 Lisp_Vectorlike = 5,
12 };
13 typedef struct Lisp_X *Lisp_Object;
14
15 static inline EMACS_INT
16 XLI (Lisp_Object o)
17 {
18 return (EMACS_INT) o;
19 }
20
21 static inline void *
22 XLP (Lisp_Object o)
23 {
24 return (void *) o;
25 }
26
27 struct Lisp_Symbol
28 {
29 Lisp_Object name;
30 Lisp_Object value;
31 };
32 extern struct Lisp_Symbol lispsym[1455];
33
34 union vectorlike_header
35 {
36 ptrdiff_t size;
37 };
38 static inline _Bool
39 TAGGEDP (Lisp_Object a, enum Lisp_Type tag)
40 {
41 return (! (((unsigned) XLI (a) - (unsigned) (tag)) & 7));
42 }
43
44 struct Lisp_Symbol_With_Pos
45 {
46 union vectorlike_header header;
47 Lisp_Object sym;
48 Lisp_Object pos;
49 };
50
51 static inline _Bool
52 PSEUDOVECTORP (Lisp_Object a, int code)
53 {
54 return (TAGGEDP (a, Lisp_Vectorlike)
55 && ((((union vectorlike_header *)
56 ((char *) XLP ((a)) - Lisp_Vectorlike))->size
57 & 0x400000003f000000)
58 == (0x4000000000000000 | (code << 24))));
59 }
60
61 static inline _Bool
62 BARE_SYMBOL_P (Lisp_Object x)
63 {
64 return TAGGEDP (x, Lisp_Symbol);
65 }
66
67 static inline _Bool
68 SYMBOL_WITH_POS_P (Lisp_Object x)
69 {
70 return PSEUDOVECTORP (x, 6);
71 }
72
73 static inline struct Lisp_Symbol_With_Pos *
74 XSYMBOL_WITH_POS (Lisp_Object a)
75 {
76 return (struct Lisp_Symbol_With_Pos *) ((char *) XLP (a) - Lisp_Vectorlike);
77 }
78
79 static inline Lisp_Object
80 make_lisp_symbol (struct Lisp_Symbol *sym)
81 {
82 return (Lisp_Object) ((char *) sym - (char *) lispsym);
83 }
84
85 static inline Lisp_Object
86 builtin_lisp_symbol (int index)
87 {
88 return make_lisp_symbol (&lispsym[index]);
89 }
90
91 static inline _Bool
92 BASE_EQ (Lisp_Object x, Lisp_Object y)
93 {
94 return XLI (x) == XLI (y);
95 }
96
97 extern _Bool symbols_with_pos_enabled;
98
99 static inline _Bool
100 EQ (Lisp_Object x, Lisp_Object y)
101 {
102 return (XLI (x) == XLI (y)
103 || (symbols_with_pos_enabled
104 && (SYMBOL_WITH_POS_P (x)
105 ? (BARE_SYMBOL_P (y)
106 ? XLI (XSYMBOL_WITH_POS(x)->sym) == XLI (y)
107 : (SYMBOL_WITH_POS_P(y)
108 && (XLI (XSYMBOL_WITH_POS(x)->sym)
109 == XLI (XSYMBOL_WITH_POS(y)->sym))))
110 : (SYMBOL_WITH_POS_P (y) && BARE_SYMBOL_P (x)
111 && (XLI (x) == XLI ((XSYMBOL_WITH_POS (y))->sym))))));
112 }
113
114 static inline _Bool
115 NILP (Lisp_Object x)
116 {
117 return BASE_EQ (x, builtin_lisp_symbol (0));
118 }
119
120 static inline _Bool
121 ASCII_CHAR_P (intmax_t c)
122 {
123 return 0 <= c && c < 0x80;
124 }
125
126 struct Lisp_Char_Table
127 {
128 union vectorlike_header header;
129 Lisp_Object defalt;
130 Lisp_Object parent;
131 Lisp_Object ascii;
132 };
133
134 extern Lisp_Object char_table_ref (Lisp_Object, int);
135
136 static inline _Bool
137 CHAR_TABLE_P (Lisp_Object a)
138 {
139 return PSEUDOVECTORP (a, 28);
140 }
141
142 static inline struct Lisp_Char_Table *
143 XCHAR_TABLE (Lisp_Object a)
144 {
145 return (struct Lisp_Char_Table *) ((char *) XLP (a) - Lisp_Vectorlike);
146 }
147
148 struct Lisp_Sub_Char_Table
149 {
150 union vectorlike_header header;
151 Lisp_Object contents[];
152 };
153
154 static inline _Bool
155 SUB_CHAR_TABLE_P (Lisp_Object a)
156 {
157 return PSEUDOVECTORP (a, 29);
158 }
159
160 static inline struct Lisp_Sub_Char_Table *
161 XSUB_CHAR_TABLE (Lisp_Object a)
162 {
163 return (struct Lisp_Sub_Char_Table *) ((char *) XLP (a) - Lisp_Vectorlike);
164 }
165
166 static inline Lisp_Object
167 CHAR_TABLE_REF_ASCII (Lisp_Object ct, ptrdiff_t idx)
168 {
169 for (struct Lisp_Char_Table *tbl = XCHAR_TABLE (ct); ;
170 tbl = XCHAR_TABLE (tbl->parent))
171 {
172 Lisp_Object val = (! SUB_CHAR_TABLE_P (tbl->ascii) ? tbl->ascii
173 : XSUB_CHAR_TABLE (tbl->ascii)->contents[idx]);
174 if (NILP (val))
175 val = tbl->defalt;
176 if (!NILP (val) || NILP (tbl->parent))
177 return val;
178 }
179 }
180
181 static inline Lisp_Object
182 CHAR_TABLE_REF (Lisp_Object ct, int idx)
183 {
184 return (ASCII_CHAR_P (idx)
185 ? CHAR_TABLE_REF_ASCII (ct, idx)
186 : char_table_ref (ct, idx));
187 }
188
189 _Bool
190 word_boundary_p (Lisp_Object char_script_table, int c1, int c2)
191 {
192 return EQ (CHAR_TABLE_REF (char_script_table, c1),
193 CHAR_TABLE_REF (char_script_table, c2));
194 }