Bug Summary

File:build/libcpp/macro.c
Warning:line 568, column 8
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name macro.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/libcpp -resource-dir /usr/lib64/clang/13.0.0 -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/backward -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-long-long -fdeprecated-macro -fdebug-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/libcpp -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-11-20-133755-20252-1/report-uUwb4q.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c
1/* Part of CPP library. (Macro and #define handling.)
2 Copyright (C) 1986-2021 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
6
7This program is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by the
9Free Software Foundation; either version 3, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>.
20
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding! */
24
25#include "config.h"
26#include "system.h"
27#include "cpplib.h"
28#include "internal.h"
29
30typedef struct macro_arg macro_arg;
31/* This structure represents the tokens of a macro argument. These
32 tokens can be macro themselves, in which case they can be either
33 expanded or unexpanded. When they are expanded, this data
34 structure keeps both the expanded and unexpanded forms. */
35struct macro_arg
36{
37 const cpp_token **first; /* First token in unexpanded argument. */
38 const cpp_token **expanded; /* Macro-expanded argument. */
39 const cpp_token *stringified; /* Stringified argument. */
40 unsigned int count; /* # of tokens in argument. */
41 unsigned int expanded_count; /* # of tokens in expanded argument. */
42 location_t *virt_locs; /* Where virtual locations for
43 unexpanded tokens are stored. */
44 location_t *expanded_virt_locs; /* Where virtual locations for
45 expanded tokens are
46 stored. */
47};
48
49/* The kind of macro tokens which the instance of
50 macro_arg_token_iter is supposed to iterate over. */
51enum macro_arg_token_kind {
52 MACRO_ARG_TOKEN_NORMAL,
53 /* This is a macro argument token that got transformed into a string
54 literal, e.g. #foo. */
55 MACRO_ARG_TOKEN_STRINGIFIED,
56 /* This is a token resulting from the expansion of a macro
57 argument that was itself a macro. */
58 MACRO_ARG_TOKEN_EXPANDED
59};
60
61/* An iterator over tokens coming from a function-like macro
62 argument. */
63typedef struct macro_arg_token_iter macro_arg_token_iter;
64struct macro_arg_token_iter
65{
66 /* Whether or not -ftrack-macro-expansion is used. */
67 bool track_macro_exp_p;
68 /* The kind of token over which we are supposed to iterate. */
69 enum macro_arg_token_kind kind;
70 /* A pointer to the current token pointed to by the iterator. */
71 const cpp_token **token_ptr;
72 /* A pointer to the "full" location of the current token. If
73 -ftrack-macro-expansion is used this location tracks loci across
74 macro expansion. */
75 const location_t *location_ptr;
76#if CHECKING_P1
77 /* The number of times the iterator went forward. This useful only
78 when checking is enabled. */
79 size_t num_forwards;
80#endif
81};
82
83/* Saved data about an identifier being used as a macro argument
84 name. */
85struct macro_arg_saved_data {
86 /* The canonical (UTF-8) spelling of this identifier. */
87 cpp_hashnode *canonical_node;
88 /* The previous value & type of this identifier. */
89 union _cpp_hashnode_value value;
90 node_type type;
91};
92
93static const char *vaopt_paste_error =
94 N_("'##' cannot appear at either end of __VA_OPT__")"'##' cannot appear at either end of __VA_OPT__";
95
96static void expand_arg (cpp_reader *, macro_arg *);
97
98/* A class for tracking __VA_OPT__ state while iterating over a
99 sequence of tokens. This is used during both macro definition and
100 expansion. */
101class vaopt_state {
102
103 public:
104
105 enum update_type
106 {
107 ERROR,
108 DROP,
109 INCLUDE,
110 BEGIN,
111 END
112 };
113
114 /* Initialize the state tracker. ANY_ARGS is true if variable
115 arguments were provided to the macro invocation. */
116 vaopt_state (cpp_reader *pfile, bool is_variadic, macro_arg *arg)
117 : m_pfile (pfile),
118 m_arg (arg),
119 m_variadic (is_variadic),
120 m_last_was_paste (false),
121 m_stringify (false),
122 m_state (0),
123 m_paste_location (0),
124 m_location (0),
125 m_update (ERROR)
126 {
127 }
128
129 /* Given a token, update the state of this tracker and return a
130 boolean indicating whether the token should be be included in the
131 expansion. */
132 update_type update (const cpp_token *token)
133 {
134 /* If the macro isn't variadic, just don't bother. */
135 if (!m_variadic)
136 return INCLUDE;
137
138 if (token->type == CPP_NAME
139 && token->val.node.node == m_pfile->spec_nodes.n__VA_OPT__)
140 {
141 if (m_state > 0)
142 {
143 cpp_error_at (m_pfile, CPP_DL_ERROR, token->src_loc,
144 "__VA_OPT__ may not appear in a __VA_OPT__");
145 return ERROR;
146 }
147 ++m_state;
148 m_location = token->src_loc;
149 m_stringify = (token->flags & STRINGIFY_ARG(1 << 2)) != 0;
150 return BEGIN;
151 }
152 else if (m_state == 1)
153 {
154 if (token->type != CPP_OPEN_PAREN)
155 {
156 cpp_error_at (m_pfile, CPP_DL_ERROR, m_location,
157 "__VA_OPT__ must be followed by an "
158 "open parenthesis");
159 return ERROR;
160 }
161 ++m_state;
162 if (m_update == ERROR)
163 {
164 if (m_arg == NULL__null)
165 m_update = INCLUDE;
166 else
167 {
168 m_update = DROP;
169 if (!m_arg->expanded)
170 expand_arg (m_pfile, m_arg);
171 for (unsigned idx = 0; idx < m_arg->expanded_count; ++idx)
172 if (m_arg->expanded[idx]->type != CPP_PADDING)
173 {
174 m_update = INCLUDE;
175 break;
176 }
177 }
178 }
179 return DROP;
180 }
181 else if (m_state >= 2)
182 {
183 if (m_state == 2 && token->type == CPP_PASTE)
184 {
185 cpp_error_at (m_pfile, CPP_DL_ERROR, token->src_loc,
186 vaopt_paste_error);
187 return ERROR;
188 }
189 /* Advance states before further considering this token, in
190 case we see a close paren immediately after the open
191 paren. */
192 if (m_state == 2)
193 ++m_state;
194
195 bool was_paste = m_last_was_paste;
196 m_last_was_paste = false;
197 if (token->type == CPP_PASTE)
198 {
199 m_last_was_paste = true;
200 m_paste_location = token->src_loc;
201 }
202 else if (token->type == CPP_OPEN_PAREN)
203 ++m_state;
204 else if (token->type == CPP_CLOSE_PAREN)
205 {
206 --m_state;
207 if (m_state == 2)
208 {
209 /* Saw the final paren. */
210 m_state = 0;
211
212 if (was_paste)
213 {
214 cpp_error_at (m_pfile, CPP_DL_ERROR, token->src_loc,
215 vaopt_paste_error);
216 return ERROR;
217 }
218
219 return END;
220 }
221 }
222 return m_update;
223 }
224
225 /* Nothing to do with __VA_OPT__. */
226 return INCLUDE;
227 }
228
229 /* Ensure that any __VA_OPT__ was completed. If ok, return true.
230 Otherwise, issue an error and return false. */
231 bool completed ()
232 {
233 if (m_variadic && m_state != 0)
234 cpp_error_at (m_pfile, CPP_DL_ERROR, m_location,
235 "unterminated __VA_OPT__");
236 return m_state == 0;
237 }
238
239 /* Return true for # __VA_OPT__. */
240 bool stringify () const
241 {
242 return m_stringify;
243 }
244
245 private:
246
247 /* The cpp_reader. */
248 cpp_reader *m_pfile;
249
250 /* The __VA_ARGS__ argument. */
251 macro_arg *m_arg;
252
253 /* True if the macro is variadic. */
254 bool m_variadic;
255 /* If true, the previous token was ##. This is used to detect when
256 a paste occurs at the end of the sequence. */
257 bool m_last_was_paste;
258 /* True for #__VA_OPT__. */
259 bool m_stringify;
260
261 /* The state variable:
262 0 means not parsing
263 1 means __VA_OPT__ seen, looking for "("
264 2 means "(" seen (so the next token can't be "##")
265 >= 3 means looking for ")", the number encodes the paren depth. */
266 int m_state;
267
268 /* The location of the paste token. */
269 location_t m_paste_location;
270
271 /* Location of the __VA_OPT__ token. */
272 location_t m_location;
273
274 /* If __VA_ARGS__ substitutes to no preprocessing tokens,
275 INCLUDE, otherwise DROP. ERROR when unknown yet. */
276 update_type m_update;
277};
278
279/* Macro expansion. */
280
281static cpp_macro *get_deferred_or_lazy_macro (cpp_reader *, cpp_hashnode *,
282 location_t);
283static int enter_macro_context (cpp_reader *, cpp_hashnode *,
284 const cpp_token *, location_t);
285static int builtin_macro (cpp_reader *, cpp_hashnode *,
286 location_t, location_t);
287static void push_ptoken_context (cpp_reader *, cpp_hashnode *, _cpp_buff *,
288 const cpp_token **, unsigned int);
289static void push_extended_tokens_context (cpp_reader *, cpp_hashnode *,
290 _cpp_buff *, location_t *,
291 const cpp_token **, unsigned int);
292static _cpp_buff *collect_args (cpp_reader *, const cpp_hashnode *,
293 _cpp_buff **, unsigned *);
294static cpp_context *next_context (cpp_reader *);
295static const cpp_token *padding_token (cpp_reader *, const cpp_token *);
296static const cpp_token *new_string_token (cpp_reader *, uchar *, unsigned int);
297static const cpp_token *stringify_arg (cpp_reader *, const cpp_token **,
298 unsigned int, bool);
299static void paste_all_tokens (cpp_reader *, const cpp_token *);
300static bool paste_tokens (cpp_reader *, location_t,
301 const cpp_token **, const cpp_token *);
302static void alloc_expanded_arg_mem (cpp_reader *, macro_arg *, size_t);
303static void ensure_expanded_arg_room (cpp_reader *, macro_arg *, size_t, size_t *);
304static void delete_macro_args (_cpp_buff*, unsigned num_args);
305static void set_arg_token (macro_arg *, const cpp_token *,
306 location_t, size_t,
307 enum macro_arg_token_kind,
308 bool);
309static const location_t *get_arg_token_location (const macro_arg *,
310 enum macro_arg_token_kind);
311static const cpp_token **arg_token_ptr_at (const macro_arg *,
312 size_t,
313 enum macro_arg_token_kind,
314 location_t **virt_location);
315
316static void macro_arg_token_iter_init (macro_arg_token_iter *, bool,
317 enum macro_arg_token_kind,
318 const macro_arg *,
319 const cpp_token **);
320static const cpp_token *macro_arg_token_iter_get_token
321(const macro_arg_token_iter *it);
322static location_t macro_arg_token_iter_get_location
323(const macro_arg_token_iter *);
324static void macro_arg_token_iter_forward (macro_arg_token_iter *);
325static _cpp_buff *tokens_buff_new (cpp_reader *, size_t,
326 location_t **);
327static size_t tokens_buff_count (_cpp_buff *);
328static const cpp_token **tokens_buff_last_token_ptr (_cpp_buff *);
329static inline const cpp_token **tokens_buff_put_token_to (const cpp_token **,
330 location_t *,
331 const cpp_token *,
332 location_t,
333 location_t,
334 const line_map_macro *,
335 unsigned int);
336
337static const cpp_token **tokens_buff_add_token (_cpp_buff *,
338 location_t *,
339 const cpp_token *,
340 location_t,
341 location_t,
342 const line_map_macro *,
343 unsigned int);
344static inline void tokens_buff_remove_last_token (_cpp_buff *);
345static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
346 macro_arg *, location_t);
347static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
348 _cpp_buff **, unsigned *);
349static cpp_macro *create_iso_definition (cpp_reader *);
350
351/* #define directive parsing and handling. */
352
353static cpp_macro *lex_expansion_token (cpp_reader *, cpp_macro *);
354static bool parse_params (cpp_reader *, unsigned *, bool *);
355static void check_trad_stringification (cpp_reader *, const cpp_macro *,
356 const cpp_string *);
357static bool reached_end_of_context (cpp_context *);
358static void consume_next_token_from_context (cpp_reader *pfile,
359 const cpp_token **,
360 location_t *);
361static const cpp_token* cpp_get_token_1 (cpp_reader *, location_t *);
362
363static cpp_hashnode* macro_of_context (cpp_context *context);
364
365/* Statistical counter tracking the number of macros that got
366 expanded. */
367unsigned num_expanded_macros_counter = 0;
368/* Statistical counter tracking the total number tokens resulting
369 from macro expansion. */
370unsigned num_macro_tokens_counter = 0;
371
372/* Wrapper around cpp_get_token to skip CPP_PADDING tokens
373 and not consume CPP_EOF. */
374static const cpp_token *
375cpp_get_token_no_padding (cpp_reader *pfile)
376{
377 for (;;)
378 {
379 const cpp_token *ret = cpp_peek_token (pfile, 0);
380 if (ret->type == CPP_EOF)
381 return ret;
382 ret = cpp_get_token (pfile);
383 if (ret->type != CPP_PADDING)
384 return ret;
385 }
386}
387
388/* Handle meeting "__has_include" builtin macro. */
389
390static int
391builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next)
392{
393 int result = 0;
394
395 if (!pfile->state.in_directive)
396 cpp_error (pfile, CPP_DL_ERROR,
397 "\"%s\" used outside of preprocessing directive",
398 NODE_NAME (op)(((&(op)->ident))->str));
399
400 pfile->state.angled_headers = true;
401 const cpp_token *token = cpp_get_token_no_padding (pfile);
402 bool paren = token->type == CPP_OPEN_PAREN;
403 if (paren)
404 token = cpp_get_token_no_padding (pfile);
405 else
406 cpp_error (pfile, CPP_DL_ERROR,
407 "missing '(' before \"%s\" operand", NODE_NAME (op)(((&(op)->ident))->str));
408 pfile->state.angled_headers = false;
409
410 bool bracket = token->type != CPP_STRING;
411 char *fname = NULL__null;
412 if (token->type == CPP_STRING || token->type == CPP_HEADER_NAME)
413 {
414 fname = XNEWVEC (char, token->val.str.len - 1)((char *) xmalloc (sizeof (char) * (token->val.str.len - 1
)))
;
415 memcpy (fname, token->val.str.text + 1, token->val.str.len - 2);
416 fname[token->val.str.len - 2] = '\0';
417 }
418 else if (token->type == CPP_LESS)
419 fname = _cpp_bracket_include (pfile);
420 else
421 cpp_error (pfile, CPP_DL_ERROR,
422 "operator \"%s\" requires a header-name", NODE_NAME (op)(((&(op)->ident))->str));
423
424 if (fname)
425 {
426 /* Do not do the lookup if we're skipping, that's unnecessary
427 IO. */
428 if (!pfile->state.skip_eval
429 && _cpp_has_header (pfile, fname, bracket,
430 has_next ? IT_INCLUDE_NEXT : IT_INCLUDE))
431 result = 1;
432
433 XDELETEVEC (fname)free ((void*) (fname));
434 }
435
436 if (paren
437 && cpp_get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
438 cpp_error (pfile, CPP_DL_ERROR,
439 "missing ')' after \"%s\" operand", NODE_NAME (op)(((&(op)->ident))->str));
440
441 return result;
442}
443
444/* Emits a warning if NODE is a macro defined in the main file that
445 has not been used. */
446int
447_cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
448 void *v ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
449{
450 if (cpp_user_macro_p (node))
451 {
452 cpp_macro *macro = node->value.macro;
453
454 if (!macro->used
455 && MAIN_FILE_P (linemap_check_ordinary
456 (linemap_lookup (pfile->line_table,
457 macro->line))))
458 cpp_warning_with_line (pfile, CPP_W_UNUSED_MACROS, macro->line, 0,
459 "macro \"%s\" is not used", NODE_NAME (node)(((&(node)->ident))->str));
460 }
461
462 return 1;
463}
464
465/* Allocates and returns a CPP_STRING token, containing TEXT of length
466 LEN, after null-terminating it. TEXT must be in permanent storage. */
467static const cpp_token *
468new_string_token (cpp_reader *pfile, unsigned char *text, unsigned int len)
469{
470 cpp_token *token = _cpp_temp_token (pfile);
471
472 text[len] = '\0';
473 token->type = CPP_STRING;
474 token->val.str.len = len;
475 token->val.str.text = text;
476 token->flags = 0;
477 return token;
478}
479
480static const char * const monthnames[] =
481{
482 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
483 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
484};
485
486/* Helper function for builtin_macro. Returns the text generated by
487 a builtin macro. */
488const uchar *
489_cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
490 location_t loc)
491{
492 const uchar *result = NULL__null;
493 linenum_type number = 1;
494
495 switch (node->value.builtin)
32
Control jumps to 'case BT_FILE_NAME:' at line 545
496 {
497 default:
498 cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
499 NODE_NAME (node)(((&(node)->ident))->str));
500 break;
501
502 case BT_TIMESTAMP:
503 {
504 if (CPP_OPTION (pfile, warn_date_time)((pfile)->opts.warn_date_time))
505 cpp_warning (pfile, CPP_W_DATE_TIME, "macro \"%s\" might prevent "
506 "reproducible builds", NODE_NAME (node)(((&(node)->ident))->str));
507
508 cpp_buffer *pbuffer = cpp_get_buffer (pfile);
509 if (pbuffer->timestamp == NULL__null)
510 {
511 /* Initialize timestamp value of the assotiated file. */
512 struct _cpp_file *file = cpp_get_file (pbuffer);
513 if (file)
514 {
515 /* Generate __TIMESTAMP__ string, that represents
516 the date and time of the last modification
517 of the current source file. The string constant
518 looks like "Sun Sep 16 01:03:52 1973". */
519 struct tm *tb = NULL__null;
520 struct stat *st = _cpp_get_file_stat (file);
521 if (st)
522 tb = localtime (&st->st_mtimest_mtim.tv_sec);
523 if (tb)
524 {
525 char *str = asctime (tb);
526 size_t len = strlen (str);
527 unsigned char *buf = _cpp_unaligned_alloc (pfile, len + 2);
528 buf[0] = '"';
529 strcpy ((char *) buf + 1, str);
530 buf[len] = '"';
531 pbuffer->timestamp = buf;
532 }
533 else
534 {
535 cpp_errno (pfile, CPP_DL_WARNING,
536 "could not determine file timestamp");
537 pbuffer->timestamp = UC(const uchar *)"\"??? ??? ?? ??:??:?? ????\"";
538 }
539 }
540 }
541 result = pbuffer->timestamp;
542 }
543 break;
544 case BT_FILE:
545 case BT_FILE_NAME:
546 case BT_BASE_FILE:
547 {
548 unsigned int len;
549 const char *name;
550 uchar *buf;
551
552 if (node->value.builtin
32.1
Field 'builtin' is not equal to BT_FILE
== BT_FILE
33
Taking true branch
553 || node->value.builtin
32.2
Field 'builtin' is equal to BT_FILE_NAME
== BT_FILE_NAME)
554 {
555 name = linemap_get_expansion_filename (pfile->line_table,
34
Value assigned to 'name'
556 pfile->line_table->highest_line);
557 if ((node->value.builtin
34.1
Field 'builtin' is equal to BT_FILE_NAME
== BT_FILE_NAME) && name
)
35
Assuming 'name' is null
36
Assuming pointer value is null
37
Taking false branch
558 name = lbasename (name);
559 }
560 else
561 {
562 name = _cpp_get_file_name (pfile->main_file);
563 if (!name)
564 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 564, __FUNCTION__)
;
565 }
566 if (pfile->cb.remap_filename)
38
Assuming field 'remap_filename' is null
39
Taking false branch
567 name = pfile->cb.remap_filename (name);
568 len = strlen (name);
40
Null pointer passed to 1st parameter expecting 'nonnull'
569 buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
570 result = buf;
571 *buf = '"';
572 buf = cpp_quote_string (buf + 1, (const unsigned char *) name, len);
573 *buf++ = '"';
574 *buf = '\0';
575 }
576 break;
577
578 case BT_INCLUDE_LEVEL:
579 /* The line map depth counts the primary source as level 1, but
580 historically __INCLUDE_DEPTH__ has called the primary source
581 level 0. */
582 number = pfile->line_table->depth - 1;
583 break;
584
585 case BT_SPECLINE:
586 /* If __LINE__ is embedded in a macro, it must expand to the
587 line of the macro's invocation, not its definition.
588 Otherwise things like assert() will not work properly.
589 See WG14 N1911, WG21 N4220 sec 6.5, and PR 61861. */
590 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
591 loc = pfile->line_table->highest_line;
592 else
593 loc = linemap_resolve_location (pfile->line_table, loc,
594 LRK_MACRO_EXPANSION_POINT, NULL__null);
595 number = linemap_get_expansion_line (pfile->line_table, loc);
596 break;
597
598 /* __STDC__ has the value 1 under normal circumstances.
599 However, if (a) we are in a system header, (b) the option
600 stdc_0_in_system_headers is true (set by target config), and
601 (c) we are not in strictly conforming mode, then it has the
602 value 0. (b) and (c) are already checked in cpp_init_builtins. */
603 case BT_STDC:
604 if (_cpp_in_system_header (pfile))
605 number = 0;
606 else
607 number = 1;
608 break;
609
610 case BT_DATE:
611 case BT_TIME:
612 if (CPP_OPTION (pfile, warn_date_time)((pfile)->opts.warn_date_time))
613 cpp_warning (pfile, CPP_W_DATE_TIME, "macro \"%s\" might prevent "
614 "reproducible builds", NODE_NAME (node)(((&(node)->ident))->str));
615 if (pfile->date == NULL__null)
616 {
617 /* Allocate __DATE__ and __TIME__ strings from permanent
618 storage. We only do this once, and don't generate them
619 at init time, because time() and localtime() are very
620 slow on some systems. */
621 time_t tt;
622 auto kind = cpp_get_date (pfile, &tt);
623
624 if (kind == CPP_time_kind::UNKNOWN)
625 {
626 cpp_errno (pfile, CPP_DL_WARNING,
627 "could not determine date and time");
628
629 pfile->date = UC(const uchar *)"\"??? ?? ????\"";
630 pfile->time = UC(const uchar *)"\"??:??:??\"";
631 }
632 else
633 {
634 struct tm *tb = (kind == CPP_time_kind::FIXED
635 ? gmtime : localtime) (&tt);
636
637 pfile->date = _cpp_unaligned_alloc (pfile,
638 sizeof ("\"Oct 11 1347\""));
639 sprintf ((char *) pfile->date, "\"%s %2d %4d\"",
640 monthnames[tb->tm_mon], tb->tm_mday,
641 tb->tm_year + 1900);
642
643 pfile->time = _cpp_unaligned_alloc (pfile,
644 sizeof ("\"12:34:56\""));
645 sprintf ((char *) pfile->time, "\"%02d:%02d:%02d\"",
646 tb->tm_hour, tb->tm_min, tb->tm_sec);
647 }
648 }
649
650 if (node->value.builtin == BT_DATE)
651 result = pfile->date;
652 else
653 result = pfile->time;
654 break;
655
656 case BT_COUNTER:
657 if (CPP_OPTION (pfile, directives_only)((pfile)->opts.directives_only) && pfile->state.in_directive)
658 cpp_error (pfile, CPP_DL_ERROR,
659 "__COUNTER__ expanded inside directive with -fdirectives-only");
660 number = pfile->counter++;
661 break;
662
663 case BT_HAS_ATTRIBUTE:
664 number = pfile->cb.has_attribute (pfile, false);
665 break;
666
667 case BT_HAS_STD_ATTRIBUTE:
668 number = pfile->cb.has_attribute (pfile, true);
669 break;
670
671 case BT_HAS_BUILTIN:
672 number = pfile->cb.has_builtin (pfile);
673 break;
674
675 case BT_HAS_INCLUDE:
676 case BT_HAS_INCLUDE_NEXT:
677 number = builtin_has_include (pfile, node,
678 node->value.builtin == BT_HAS_INCLUDE_NEXT);
679 break;
680 }
681
682 if (result == NULL__null)
683 {
684 /* 21 bytes holds all NUL-terminated unsigned 64-bit numbers. */
685 result = _cpp_unaligned_alloc (pfile, 21);
686 sprintf ((char *) result, "%u", number);
687 }
688
689 return result;
690}
691
692/* Get an idempotent date. Either the cached value, the value from
693 source epoch, or failing that, the value from time(2). Use this
694 during compilation so that every time stamp is the same. */
695CPP_time_kind
696cpp_get_date (cpp_reader *pfile, time_t *result)
697{
698 if (!pfile->time_stamp_kind)
699 {
700 int kind = 0;
701 if (pfile->cb.get_source_date_epoch)
702 {
703 /* Try reading the fixed epoch. */
704 pfile->time_stamp = pfile->cb.get_source_date_epoch (pfile);
705 if (pfile->time_stamp != time_t (-1))
706 kind = int (CPP_time_kind::FIXED);
707 }
708
709 if (!kind)
710 {
711 /* Pedantically time_t (-1) is a legitimate value for
712 "number of seconds since the Epoch". It is a silly
713 time. */
714 errno(*__errno_location ()) = 0;
715 pfile->time_stamp = time (nullptr);
716 /* Annoyingly a library could legally set errno and return a
717 valid time! Bad library! */
718 if (pfile->time_stamp == time_t (-1) && errno(*__errno_location ()))
719 kind = errno(*__errno_location ());
720 else
721 kind = int (CPP_time_kind::DYNAMIC);
722 }
723
724 pfile->time_stamp_kind = kind;
725 }
726
727 *result = pfile->time_stamp;
728 if (pfile->time_stamp_kind >= 0)
729 {
730 errno(*__errno_location ()) = pfile->time_stamp_kind;
731 return CPP_time_kind::UNKNOWN;
732 }
733
734 return CPP_time_kind (pfile->time_stamp_kind);
735}
736
737/* Convert builtin macros like __FILE__ to a token and push it on the
738 context stack. Also handles _Pragma, for which a new token may not
739 be created. Returns 1 if it generates a new token context, 0 to
740 return the token to the caller. LOC is the location of the expansion
741 point of the macro. */
742static int
743builtin_macro (cpp_reader *pfile, cpp_hashnode *node,
744 location_t loc, location_t expand_loc)
745{
746 const uchar *buf;
747 size_t len;
748 char *nbuf;
749
750 if (node->value.builtin == BT_PRAGMA)
29
Assuming field 'builtin' is not equal to BT_PRAGMA
30
Taking false branch
751 {
752 /* Don't interpret _Pragma within directives. The standard is
753 not clear on this, but to me this makes most sense. */
754 if (pfile->state.in_directive)
755 return 0;
756
757 return _cpp_do__Pragma (pfile, loc);
758 }
759
760 buf = _cpp_builtin_macro_text (pfile, node, expand_loc);
31
Calling '_cpp_builtin_macro_text'
761 len = ustrlen (buf);
762 nbuf = (char *) alloca (len + 1)__builtin_alloca(len + 1);
763 memcpy (nbuf, buf, len);
764 nbuf[len]='\n';
765
766 cpp_push_buffer (pfile, (uchar *) nbuf, len, /* from_stage3 */ true);
767 _cpp_clean_line (pfile);
768
769 /* Set pfile->cur_token as required by _cpp_lex_direct. */
770 pfile->cur_token = _cpp_temp_token (pfile);
771 cpp_token *token = _cpp_lex_direct (pfile);
772 /* We should point to the expansion point of the builtin macro. */
773 token->src_loc = loc;
774 if (pfile->context->tokens_kind == TOKENS_KIND_EXTENDED)
775 {
776 /* We are tracking tokens resulting from macro expansion.
777 Create a macro line map and generate a virtual location for
778 the token resulting from the expansion of the built-in
779 macro. */
780 location_t *virt_locs = NULL__null;
781 _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs);
782 const line_map_macro * map =
783 linemap_enter_macro (pfile->line_table, node, loc, 1);
784 tokens_buff_add_token (token_buf, virt_locs, token,
785 pfile->line_table->builtin_location,
786 pfile->line_table->builtin_location,
787 map, /*macro_token_index=*/0);
788 push_extended_tokens_context (pfile, node, token_buf, virt_locs,
789 (const cpp_token **)token_buf->base,
790 1);
791 }
792 else
793 _cpp_push_token_context (pfile, NULL__null, token, 1);
794 if (pfile->buffer->cur != pfile->buffer->rlimit)
795 cpp_error (pfile, CPP_DL_ICE, "invalid built-in macro \"%s\"",
796 NODE_NAME (node)(((&(node)->ident))->str));
797 _cpp_pop_buffer (pfile);
798
799 return 1;
800}
801
802/* Copies SRC, of length LEN, to DEST, adding backslashes before all
803 backslashes and double quotes. DEST must be of sufficient size.
804 Returns a pointer to the end of the string. */
805uchar *
806cpp_quote_string (uchar *dest, const uchar *src, unsigned int len)
807{
808 while (len--)
809 {
810 uchar c = *src++;
811
812 switch (c)
813 {
814 case '\n':
815 /* Naked LF can appear in raw string literals */
816 c = 'n';
817 /* FALLTHROUGH */
818
819 case '\\':
820 case '"':
821 *dest++ = '\\';
822 /* FALLTHROUGH */
823
824 default:
825 *dest++ = c;
826 }
827 }
828
829 return dest;
830}
831
832/* Convert a token sequence FIRST to FIRST+COUNT-1 to a single string token
833 according to the rules of the ISO C #-operator. */
834static const cpp_token *
835stringify_arg (cpp_reader *pfile, const cpp_token **first, unsigned int count,
836 bool va_opt)
837{
838 unsigned char *dest;
839 unsigned int i, escape_it, backslash_count = 0;
840 const cpp_token *source = NULL__null;
841 size_t len;
842
843 if (BUFF_ROOM (pfile->u_buff)(size_t) ((pfile->u_buff)->limit - (pfile->u_buff)->
cur)
< 3)
844 _cpp_extend_buff (pfile, &pfile->u_buff, 3);
845 dest = BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur);
846 *dest++ = '"';
847
848 /* Loop, reading in the argument's tokens. */
849 for (i = 0; i < count; i++)
850 {
851 const cpp_token *token = first[i];
852
853 if (va_opt && (token->flags & PASTE_LEFT(1 << 3)))
854 {
855 location_t virt_loc = pfile->invocation_location;
856 const cpp_token *rhs;
857 do
858 {
859 if (i == count)
860 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 860, __FUNCTION__)
;
861 rhs = first[++i];
862 if (!paste_tokens (pfile, virt_loc, &token, rhs))
863 {
864 --i;
865 break;
866 }
867 }
868 while (rhs->flags & PASTE_LEFT(1 << 3));
869 }
870
871 if (token->type == CPP_PADDING)
872 {
873 if (source == NULL__null
874 || (!(source->flags & PREV_WHITE(1 << 0))
875 && token->val.source == NULL__null))
876 source = token->val.source;
877 continue;
878 }
879
880 escape_it = (token->type == CPP_STRING || token->type == CPP_CHAR
881 || token->type == CPP_WSTRING || token->type == CPP_WCHAR
882 || token->type == CPP_STRING32 || token->type == CPP_CHAR32
883 || token->type == CPP_STRING16 || token->type == CPP_CHAR16
884 || token->type == CPP_UTF8STRING || token->type == CPP_UTF8CHAR
885 || cpp_userdef_string_p (token->type)
886 || cpp_userdef_char_p (token->type));
887
888 /* Room for each char being written in octal, initial space and
889 final quote and NUL. */
890 len = cpp_token_len (token);
891 if (escape_it)
892 len *= 4;
893 len += 3;
894
895 if ((size_t) (BUFF_LIMIT (pfile->u_buff)((pfile->u_buff)->limit) - dest) < len)
896 {
897 size_t len_so_far = dest - BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur);
898 _cpp_extend_buff (pfile, &pfile->u_buff, len);
899 dest = BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur) + len_so_far;
900 }
901
902 /* Leading white space? */
903 if (dest - 1 != BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur))
904 {
905 if (source == NULL__null)
906 source = token;
907 if (source->flags & PREV_WHITE(1 << 0))
908 *dest++ = ' ';
909 }
910 source = NULL__null;
911
912 if (escape_it)
913 {
914 _cpp_buff *buff = _cpp_get_buff (pfile, len);
915 unsigned char *buf = BUFF_FRONT (buff)((buff)->cur);
916 len = cpp_spell_token (pfile, token, buf, true) - buf;
917 dest = cpp_quote_string (dest, buf, len);
918 _cpp_release_buff (pfile, buff);
919 }
920 else
921 dest = cpp_spell_token (pfile, token, dest, true);
922
923 if (token->type == CPP_OTHER && token->val.str.text[0] == '\\')
924 backslash_count++;
925 else
926 backslash_count = 0;
927 }
928
929 /* Ignore the final \ of invalid string literals. */
930 if (backslash_count & 1)
931 {
932 cpp_error (pfile, CPP_DL_WARNING,
933 "invalid string literal, ignoring final '\\'");
934 dest--;
935 }
936
937 /* Commit the memory, including NUL, and return the token. */
938 *dest++ = '"';
939 len = dest - BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur);
940 BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur) = dest + 1;
941 return new_string_token (pfile, dest - len, len);
942}
943
944/* Try to paste two tokens. On success, return nonzero. In any
945 case, PLHS is updated to point to the pasted token, which is
946 guaranteed to not have the PASTE_LEFT flag set. LOCATION is
947 the virtual location used for error reporting. */
948static bool
949paste_tokens (cpp_reader *pfile, location_t location,
950 const cpp_token **plhs, const cpp_token *rhs)
951{
952 unsigned char *buf, *end, *lhsend;
953 cpp_token *lhs;
954 unsigned int len;
955
956 len = cpp_token_len (*plhs) + cpp_token_len (rhs) + 2;
957 buf = (unsigned char *) alloca (len)__builtin_alloca(len);
958 end = lhsend = cpp_spell_token (pfile, *plhs, buf, true);
959
960 /* Avoid comment headers, since they are still processed in stage 3.
961 It is simpler to insert a space here, rather than modifying the
962 lexer to ignore comments in some circumstances. Simply returning
963 false doesn't work, since we want to clear the PASTE_LEFT flag. */
964 if ((*plhs)->type == CPP_DIV && rhs->type != CPP_EQ)
965 *end++ = ' ';
966 /* In one obscure case we might see padding here. */
967 if (rhs->type != CPP_PADDING)
968 end = cpp_spell_token (pfile, rhs, end, true);
969 *end = '\n';
970
971 cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true);
972 _cpp_clean_line (pfile);
973
974 /* Set pfile->cur_token as required by _cpp_lex_direct. */
975 pfile->cur_token = _cpp_temp_token (pfile);
976 lhs = _cpp_lex_direct (pfile);
977 if (pfile->buffer->cur != pfile->buffer->rlimit)
978 {
979 location_t saved_loc = lhs->src_loc;
980
981 _cpp_pop_buffer (pfile);
982
983 unsigned char *rhsstart = lhsend;
984 if ((*plhs)->type == CPP_DIV && rhs->type != CPP_EQ)
985 rhsstart++;
986
987 /* We have to remove the PASTE_LEFT flag from the old lhs, but
988 we want to keep the new location. */
989 *lhs = **plhs;
990 *plhs = lhs;
991 lhs->src_loc = saved_loc;
992 lhs->flags &= ~PASTE_LEFT(1 << 3);
993
994 /* Mandatory error for all apart from assembler. */
995 if (CPP_OPTION (pfile, lang)((pfile)->opts.lang) != CLK_ASM)
996 cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
997 "pasting \"%.*s\" and \"%.*s\" does not give "
998 "a valid preprocessing token",
999 (int) (lhsend - buf), buf,
1000 (int) (end - rhsstart), rhsstart);
1001 return false;
1002 }
1003
1004 *plhs = lhs;
1005 _cpp_pop_buffer (pfile);
1006 return true;
1007}
1008
1009/* Handles an arbitrarily long sequence of ## operators, with initial
1010 operand LHS. This implementation is left-associative,
1011 non-recursive, and finishes a paste before handling succeeding
1012 ones. If a paste fails, we back up to the RHS of the failing ##
1013 operator before pushing the context containing the result of prior
1014 successful pastes, with the effect that the RHS appears in the
1015 output stream after the pasted LHS normally. */
1016static void
1017paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs)
1018{
1019 const cpp_token *rhs = NULL__null;
1020 cpp_context *context = pfile->context;
1021 location_t virt_loc = 0;
1022
1023 /* We are expanding a macro and we must have been called on a token
1024 that appears at the left hand side of a ## operator. */
1025 if (macro_of_context (pfile->context) == NULL__null
1026 || (!(lhs->flags & PASTE_LEFT(1 << 3))))
1027 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1027, __FUNCTION__)
;
1028
1029 if (context->tokens_kind == TOKENS_KIND_EXTENDED)
1030 /* The caller must have called consume_next_token_from_context
1031 right before calling us. That has incremented the pointer to
1032 the current virtual location. So it now points to the location
1033 of the token that comes right after *LHS. We want the
1034 resulting pasted token to have the location of the current
1035 *LHS, though. */
1036 virt_loc = context->c.mc->cur_virt_loc[-1];
1037 else
1038 /* We are not tracking macro expansion. So the best virtual
1039 location we can get here is the expansion point of the macro we
1040 are currently expanding. */
1041 virt_loc = pfile->invocation_location;
1042
1043 do
1044 {
1045 /* Take the token directly from the current context. We can do
1046 this, because we are in the replacement list of either an
1047 object-like macro, or a function-like macro with arguments
1048 inserted. In either case, the constraints to #define
1049 guarantee we have at least one more token. */
1050 if (context->tokens_kind == TOKENS_KIND_DIRECT)
1051 rhs = FIRST (context)((context)->u.iso.first).token++;
1052 else if (context->tokens_kind == TOKENS_KIND_INDIRECT)
1053 rhs = *FIRST (context)((context)->u.iso.first).ptoken++;
1054 else if (context->tokens_kind == TOKENS_KIND_EXTENDED)
1055 {
1056 /* So we are in presence of an extended token context, which
1057 means that each token in this context has a virtual
1058 location attached to it. So let's not forget to update
1059 the pointer to the current virtual location of the
1060 current token when we update the pointer to the current
1061 token */
1062
1063 rhs = *FIRST (context)((context)->u.iso.first).ptoken++;
1064 /* context->c.mc must be non-null, as if we were not in a
1065 macro context, context->tokens_kind could not be equal to
1066 TOKENS_KIND_EXTENDED. */
1067 context->c.mc->cur_virt_loc++;
1068 }
1069
1070 if (rhs->type == CPP_PADDING)
1071 {
1072 if (rhs->flags & PASTE_LEFT(1 << 3))
1073 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1073, __FUNCTION__)
;
1074 }
1075 if (!paste_tokens (pfile, virt_loc, &lhs, rhs))
1076 {
1077 _cpp_backup_tokens (pfile, 1);
1078 break;
1079 }
1080 }
1081 while (rhs->flags & PASTE_LEFT(1 << 3));
1082
1083 /* Put the resulting token in its own context. */
1084 if (context->tokens_kind == TOKENS_KIND_EXTENDED)
1085 {
1086 location_t *virt_locs = NULL__null;
1087 _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs);
1088 tokens_buff_add_token (token_buf, virt_locs, lhs,
1089 virt_loc, 0, NULL__null, 0);
1090 push_extended_tokens_context (pfile, context->c.mc->macro_node,
1091 token_buf, virt_locs,
1092 (const cpp_token **)token_buf->base, 1);
1093 }
1094 else
1095 _cpp_push_token_context (pfile, NULL__null, lhs, 1);
1096}
1097
1098/* Returns TRUE if the number of arguments ARGC supplied in an
1099 invocation of the MACRO referenced by NODE is valid. An empty
1100 invocation to a macro with no parameters should pass ARGC as zero.
1101
1102 Note that MACRO cannot necessarily be deduced from NODE, in case
1103 NODE was redefined whilst collecting arguments. */
1104bool
1105_cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node, unsigned int argc)
1106{
1107 if (argc == macro->paramc)
1108 return true;
1109
1110 if (argc < macro->paramc)
1111 {
1112 /* In C++20 (here the va_opt flag is used), and also as a GNU
1113 extension, variadic arguments are allowed to not appear in
1114 the invocation at all.
1115 e.g. #define debug(format, args...) something
1116 debug("string");
1117
1118 This is exactly the same as if an empty variadic list had been
1119 supplied - debug("string", ). */
1120
1121 if (argc + 1 == macro->paramc && macro->variadic)
1122 {
1123 if (CPP_PEDANTIC (pfile)((pfile)->opts.cpp_pedantic) && ! macro->syshdr
1124 && ! CPP_OPTION (pfile, va_opt)((pfile)->opts.va_opt))
1125 {
1126 if (CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus))
1127 cpp_error (pfile, CPP_DL_PEDWARN,
1128 "ISO C++11 requires at least one argument "
1129 "for the \"...\" in a variadic macro");
1130 else
1131 cpp_error (pfile, CPP_DL_PEDWARN,
1132 "ISO C99 requires at least one argument "
1133 "for the \"...\" in a variadic macro");
1134 }
1135 return true;
1136 }
1137
1138 cpp_error (pfile, CPP_DL_ERROR,
1139 "macro \"%s\" requires %u arguments, but only %u given",
1140 NODE_NAME (node)(((&(node)->ident))->str), macro->paramc, argc);
1141 }
1142 else
1143 cpp_error (pfile, CPP_DL_ERROR,
1144 "macro \"%s\" passed %u arguments, but takes just %u",
1145 NODE_NAME (node)(((&(node)->ident))->str), argc, macro->paramc);
1146
1147 if (macro->line > RESERVED_LOCATION_COUNT)
1148 cpp_error_at (pfile, CPP_DL_NOTE, macro->line, "macro \"%s\" defined here",
1149 NODE_NAME (node)(((&(node)->ident))->str));
1150
1151 return false;
1152}
1153
1154/* Reads and returns the arguments to a function-like macro
1155 invocation. Assumes the opening parenthesis has been processed.
1156 If there is an error, emits an appropriate diagnostic and returns
1157 NULL. Each argument is terminated by a CPP_EOF token, for the
1158 future benefit of expand_arg(). If there are any deferred
1159 #pragma directives among macro arguments, store pointers to the
1160 CPP_PRAGMA ... CPP_PRAGMA_EOL tokens into *PRAGMA_BUFF buffer.
1161
1162 What is returned is the buffer that contains the memory allocated
1163 to hold the macro arguments. NODE is the name of the macro this
1164 function is dealing with. If NUM_ARGS is non-NULL, *NUM_ARGS is
1165 set to the actual number of macro arguments allocated in the
1166 returned buffer. */
1167static _cpp_buff *
1168collect_args (cpp_reader *pfile, const cpp_hashnode *node,
1169 _cpp_buff **pragma_buff, unsigned *num_args)
1170{
1171 _cpp_buff *buff, *base_buff;
1172 cpp_macro *macro;
1173 macro_arg *args, *arg;
1174 const cpp_token *token;
1175 unsigned int argc;
1176 location_t virt_loc;
1177 bool track_macro_expansion_p = CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion);
1178 unsigned num_args_alloced = 0;
1179
1180 macro = node->value.macro;
1181 if (macro->paramc)
1182 argc = macro->paramc;
1183 else
1184 argc = 1;
1185
1186#define DEFAULT_NUM_TOKENS_PER_MACRO_ARG50 50
1187#define ARG_TOKENS_EXTENT1000 1000
1188
1189 buff = _cpp_get_buff (pfile, argc * (DEFAULT_NUM_TOKENS_PER_MACRO_ARG50
1190 * sizeof (cpp_token *)
1191 + sizeof (macro_arg)));
1192 base_buff = buff;
1193 args = (macro_arg *) buff->base;
1194 memset (args, 0, argc * sizeof (macro_arg));
1195 buff->cur = (unsigned char *) &args[argc];
1196 arg = args, argc = 0;
1197
1198 /* Collect the tokens making up each argument. We don't yet know
1199 how many arguments have been supplied, whether too many or too
1200 few. Hence the slightly bizarre usage of "argc" and "arg". */
1201 do
1202 {
1203 unsigned int paren_depth = 0;
1204 unsigned int ntokens = 0;
1205 unsigned virt_locs_capacity = DEFAULT_NUM_TOKENS_PER_MACRO_ARG50;
1206 num_args_alloced++;
1207
1208 argc++;
1209 arg->first = (const cpp_token **) buff->cur;
1210 if (track_macro_expansion_p)
1211 {
1212 virt_locs_capacity = DEFAULT_NUM_TOKENS_PER_MACRO_ARG50;
1213 arg->virt_locs = XNEWVEC (location_t,((location_t *) xmalloc (sizeof (location_t) * (virt_locs_capacity
)))
1214 virt_locs_capacity)((location_t *) xmalloc (sizeof (location_t) * (virt_locs_capacity
)))
;
1215 }
1216
1217 for (;;)
1218 {
1219 /* Require space for 2 new tokens (including a CPP_EOF). */
1220 if ((unsigned char *) &arg->first[ntokens + 2] > buff->limit)
1221 {
1222 buff = _cpp_append_extend_buff (pfile, buff,
1223 ARG_TOKENS_EXTENT1000
1224 * sizeof (cpp_token *));
1225 arg->first = (const cpp_token **) buff->cur;
1226 }
1227 if (track_macro_expansion_p
1228 && (ntokens + 2 > virt_locs_capacity))
1229 {
1230 virt_locs_capacity += ARG_TOKENS_EXTENT1000;
1231 arg->virt_locs = XRESIZEVEC (location_t,((location_t *) xrealloc ((void *) (arg->virt_locs), sizeof
(location_t) * (virt_locs_capacity)))
1232 arg->virt_locs,((location_t *) xrealloc ((void *) (arg->virt_locs), sizeof
(location_t) * (virt_locs_capacity)))
1233 virt_locs_capacity)((location_t *) xrealloc ((void *) (arg->virt_locs), sizeof
(location_t) * (virt_locs_capacity)))
;
1234 }
1235
1236 token = cpp_get_token_1 (pfile, &virt_loc);
1237
1238 if (token->type == CPP_PADDING)
1239 {
1240 /* Drop leading padding. */
1241 if (ntokens == 0)
1242 continue;
1243 }
1244 else if (token->type == CPP_OPEN_PAREN)
1245 paren_depth++;
1246 else if (token->type == CPP_CLOSE_PAREN)
1247 {
1248 if (paren_depth-- == 0)
1249 break;
1250 }
1251 else if (token->type == CPP_COMMA)
1252 {
1253 /* A comma does not terminate an argument within
1254 parentheses or as part of a variable argument. */
1255 if (paren_depth == 0
1256 && ! (macro->variadic && argc == macro->paramc))
1257 break;
1258 }
1259 else if (token->type == CPP_EOF
1260 || (token->type == CPP_HASH && token->flags & BOL(1 << 6)))
1261 break;
1262 else if (token->type == CPP_PRAGMA && !(token->flags & PRAGMA_OP(1 << 11)))
1263 {
1264 cpp_token *newtok = _cpp_temp_token (pfile);
1265
1266 /* CPP_PRAGMA token lives in directive_result, which will
1267 be overwritten on the next directive. */
1268 *newtok = *token;
1269 token = newtok;
1270 do
1271 {
1272 if (*pragma_buff == NULL__null
1273 || BUFF_ROOM (*pragma_buff)(size_t) ((*pragma_buff)->limit - (*pragma_buff)->cur) < sizeof (cpp_token *))
1274 {
1275 _cpp_buff *next;
1276 if (*pragma_buff == NULL__null)
1277 *pragma_buff
1278 = _cpp_get_buff (pfile, 32 * sizeof (cpp_token *));
1279 else
1280 {
1281 next = *pragma_buff;
1282 *pragma_buff
1283 = _cpp_get_buff (pfile,
1284 (BUFF_FRONT (*pragma_buff)((*pragma_buff)->cur)
1285 - (*pragma_buff)->base) * 2);
1286 (*pragma_buff)->next = next;
1287 }
1288 }
1289 *(const cpp_token **) BUFF_FRONT (*pragma_buff)((*pragma_buff)->cur) = token;
1290 BUFF_FRONT (*pragma_buff)((*pragma_buff)->cur) += sizeof (cpp_token *);
1291 if (token->type == CPP_PRAGMA_EOL)
1292 break;
1293 token = cpp_get_token_1 (pfile, &virt_loc);
1294 }
1295 while (token->type != CPP_EOF);
1296
1297 /* In deferred pragmas parsing_args and prevent_expansion
1298 had been changed, reset it. */
1299 pfile->state.parsing_args = 2;
1300 pfile->state.prevent_expansion = 1;
1301
1302 if (token->type == CPP_EOF)
1303 break;
1304 else
1305 continue;
1306 }
1307 set_arg_token (arg, token, virt_loc,
1308 ntokens, MACRO_ARG_TOKEN_NORMAL,
1309 CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion));
1310 ntokens++;
1311 }
1312
1313 /* Drop trailing padding. */
1314 while (ntokens > 0 && arg->first[ntokens - 1]->type == CPP_PADDING)
1315 ntokens--;
1316
1317 arg->count = ntokens;
1318 /* Append an EOF to mark end-of-argument. */
1319 set_arg_token (arg, &pfile->endarg, token->src_loc,
1320 ntokens, MACRO_ARG_TOKEN_NORMAL,
1321 CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion));
1322
1323 /* Terminate the argument. Excess arguments loop back and
1324 overwrite the final legitimate argument, before failing. */
1325 if (argc <= macro->paramc)
1326 {
1327 buff->cur = (unsigned char *) &arg->first[ntokens + 1];
1328 if (argc != macro->paramc)
1329 arg++;
1330 }
1331 }
1332 while (token->type != CPP_CLOSE_PAREN && token->type != CPP_EOF);
1333
1334 if (token->type == CPP_EOF)
1335 {
1336 /* Unless the EOF is marking the end of an argument, it's a fake
1337 one from the end of a file that _cpp_clean_line will not have
1338 advanced past. */
1339 if (token == &pfile->endarg)
1340 _cpp_backup_tokens (pfile, 1);
1341 cpp_error (pfile, CPP_DL_ERROR,
1342 "unterminated argument list invoking macro \"%s\"",
1343 NODE_NAME (node)(((&(node)->ident))->str));
1344 }
1345 else
1346 {
1347 /* A single empty argument is counted as no argument. */
1348 if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
1349 argc = 0;
1350 if (_cpp_arguments_ok (pfile, macro, node, argc))
1351 {
1352 /* GCC has special semantics for , ## b where b is a varargs
1353 parameter: we remove the comma if b was omitted entirely.
1354 If b was merely an empty argument, the comma is retained.
1355 If the macro takes just one (varargs) parameter, then we
1356 retain the comma only if we are standards conforming.
1357
1358 If FIRST is NULL replace_args () swallows the comma. */
1359 if (macro->variadic && (argc < macro->paramc
1360 || (argc == 1 && args[0].count == 0
1361 && !CPP_OPTION (pfile, std)((pfile)->opts.std))))
1362 args[macro->paramc - 1].first = NULL__null;
1363 if (num_args)
1364 *num_args = num_args_alloced;
1365 return base_buff;
1366 }
1367 }
1368
1369 /* An error occurred. */
1370 _cpp_release_buff (pfile, base_buff);
1371 return NULL__null;
1372}
1373
1374/* Search for an opening parenthesis to the macro of NODE, in such a
1375 way that, if none is found, we don't lose the information in any
1376 intervening padding tokens. If we find the parenthesis, collect
1377 the arguments and return the buffer containing them. PRAGMA_BUFF
1378 argument is the same as in collect_args. If NUM_ARGS is non-NULL,
1379 *NUM_ARGS is set to the number of arguments contained in the
1380 returned buffer. */
1381static _cpp_buff *
1382funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node,
1383 _cpp_buff **pragma_buff, unsigned *num_args)
1384{
1385 const cpp_token *token, *padding = NULL__null;
1386
1387 for (;;)
1388 {
1389 token = cpp_get_token (pfile);
1390 if (token->type != CPP_PADDING)
1391 break;
1392 if (padding == NULL__null
1393 || (!(padding->flags & PREV_WHITE(1 << 0)) && token->val.source == NULL__null))
1394 padding = token;
1395 }
1396
1397 if (token->type == CPP_OPEN_PAREN)
1398 {
1399 pfile->state.parsing_args = 2;
1400 return collect_args (pfile, node, pragma_buff, num_args);
1401 }
1402
1403 /* Back up. A CPP_EOF is either an EOF from an argument we're
1404 expanding, or a fake one from lex_direct. We want to backup the
1405 former, but not the latter. We may have skipped padding, in
1406 which case backing up more than one token when expanding macros
1407 is in general too difficult. We re-insert it in its own
1408 context. */
1409 if (token->type != CPP_EOF || token == &pfile->endarg)
1410 {
1411 _cpp_backup_tokens (pfile, 1);
1412 if (padding)
1413 _cpp_push_token_context (pfile, NULL__null, padding, 1);
1414 }
1415
1416 return NULL__null;
1417}
1418
1419/* Return the real number of tokens in the expansion of MACRO. */
1420static inline unsigned int
1421macro_real_token_count (const cpp_macro *macro)
1422{
1423 if (__builtin_expect (!macro->extra_tokens, true))
1424 return macro->count;
1425
1426 for (unsigned i = macro->count; i--;)
1427 if (macro->exp.tokens[i].type != CPP_PASTE)
1428 return i + 1;
1429
1430 return 0;
1431}
1432
1433/* Push the context of a macro with hash entry NODE onto the context
1434 stack. If we can successfully expand the macro, we push a context
1435 containing its yet-to-be-rescanned replacement list and return one.
1436 If there were additionally any unexpanded deferred #pragma
1437 directives among macro arguments, push another context containing
1438 the pragma tokens before the yet-to-be-rescanned replacement list
1439 and return two. Otherwise, we don't push a context and return
1440 zero. LOCATION is the location of the expansion point of the
1441 macro. */
1442static int
1443enter_macro_context (cpp_reader *pfile, cpp_hashnode *node,
1444 const cpp_token *result, location_t location)
1445{
1446 /* The presence of a macro invalidates a file's controlling macro. */
1447 pfile->mi_valid = false;
1448
1449 pfile->state.angled_headers = false;
1450
1451 /* From here to when we push the context for the macro later down
1452 this function, we need to flag the fact that we are about to
1453 expand a macro. This is useful when -ftrack-macro-expansion is
1454 turned off. In that case, we need to record the location of the
1455 expansion point of the top-most macro we are about to to expand,
1456 into pfile->invocation_location. But we must not record any such
1457 location once the process of expanding the macro starts; that is,
1458 we must not do that recording between now and later down this
1459 function where set this flag to FALSE. */
1460 pfile->about_to_expand_macro_p = true;
1461
1462 if (cpp_user_macro_p (node))
27
Taking false branch
1463 {
1464 cpp_macro *macro = node->value.macro;
1465 _cpp_buff *pragma_buff = NULL__null;
1466
1467 if (macro->fun_like)
1468 {
1469 _cpp_buff *buff;
1470 unsigned num_args = 0;
1471
1472 pfile->state.prevent_expansion++;
1473 pfile->keep_tokens++;
1474 pfile->state.parsing_args = 1;
1475 buff = funlike_invocation_p (pfile, node, &pragma_buff,
1476 &num_args);
1477 pfile->state.parsing_args = 0;
1478 pfile->keep_tokens--;
1479 pfile->state.prevent_expansion--;
1480
1481 if (buff == NULL__null)
1482 {
1483 if (CPP_WTRADITIONAL (pfile)((pfile)->opts.cpp_warn_traditional) && ! node->value.macro->syshdr)
1484 cpp_warning (pfile, CPP_W_TRADITIONAL,
1485 "function-like macro \"%s\" must be used with arguments in traditional C",
1486 NODE_NAME (node)(((&(node)->ident))->str));
1487
1488 if (pragma_buff)
1489 _cpp_release_buff (pfile, pragma_buff);
1490
1491 pfile->about_to_expand_macro_p = false;
1492 return 0;
1493 }
1494
1495 if (macro->paramc > 0)
1496 replace_args (pfile, node, macro,
1497 (macro_arg *) buff->base,
1498 location);
1499 /* Free the memory used by the arguments of this
1500 function-like macro. This memory has been allocated by
1501 funlike_invocation_p and by replace_args. */
1502 delete_macro_args (buff, num_args);
1503 }
1504
1505 /* Disable the macro within its expansion. */
1506 node->flags |= NODE_DISABLED(1 << 4);
1507
1508 /* Laziness can only affect the expansion tokens of the macro,
1509 not its fun-likeness or parameters. */
1510 _cpp_maybe_notify_macro_use (pfile, node, location);
1511 if (pfile->cb.used)
1512 pfile->cb.used (pfile, location, node);
1513
1514 macro->used = 1;
1515
1516 if (macro->paramc == 0)
1517 {
1518 unsigned tokens_count = macro_real_token_count (macro);
1519 if (CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion))
1520 {
1521 unsigned int i;
1522 const cpp_token *src = macro->exp.tokens;
1523 const line_map_macro *map;
1524 location_t *virt_locs = NULL__null;
1525 _cpp_buff *macro_tokens
1526 = tokens_buff_new (pfile, tokens_count, &virt_locs);
1527
1528 /* Create a macro map to record the locations of the
1529 tokens that are involved in the expansion. LOCATION
1530 is the location of the macro expansion point. */
1531 map = linemap_enter_macro (pfile->line_table,
1532 node, location, tokens_count);
1533 for (i = 0; i < tokens_count; ++i)
1534 {
1535 tokens_buff_add_token (macro_tokens, virt_locs,
1536 src, src->src_loc,
1537 src->src_loc, map, i);
1538 ++src;
1539 }
1540 push_extended_tokens_context (pfile, node,
1541 macro_tokens,
1542 virt_locs,
1543 (const cpp_token **)
1544 macro_tokens->base,
1545 tokens_count);
1546 }
1547 else
1548 _cpp_push_token_context (pfile, node, macro->exp.tokens,
1549 tokens_count);
1550 num_macro_tokens_counter += tokens_count;
1551 }
1552
1553 if (pragma_buff)
1554 {
1555 if (!pfile->state.in_directive)
1556 _cpp_push_token_context (pfile, NULL__null,
1557 padding_token (pfile, result), 1);
1558 do
1559 {
1560 unsigned tokens_count;
1561 _cpp_buff *tail = pragma_buff->next;
1562 pragma_buff->next = NULL__null;
1563 tokens_count = ((const cpp_token **) BUFF_FRONT (pragma_buff)((pragma_buff)->cur)
1564 - (const cpp_token **) pragma_buff->base);
1565 push_ptoken_context (pfile, NULL__null, pragma_buff,
1566 (const cpp_token **) pragma_buff->base,
1567 tokens_count);
1568 pragma_buff = tail;
1569 if (!CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion))
1570 num_macro_tokens_counter += tokens_count;
1571
1572 }
1573 while (pragma_buff != NULL__null);
1574 pfile->about_to_expand_macro_p = false;
1575 return 2;
1576 }
1577
1578 pfile->about_to_expand_macro_p = false;
1579 return 1;
1580 }
1581
1582 pfile->about_to_expand_macro_p = false;
1583 /* Handle built-in macros and the _Pragma operator. */
1584 {
1585 location_t expand_loc;
1586
1587 if (/* The top-level macro invocation that triggered the expansion
1588 we are looking at is with a function-like user macro ... */
1589 cpp_fun_like_macro_p (pfile->top_most_macro_node)
1590 /* ... and we are tracking the macro expansion. */
1591 && CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion))
1592 /* Then the location of the end of the macro invocation is the
1593 location of the expansion point of this macro. */
1594 expand_loc = location;
1595 else
1596 /* Otherwise, the location of the end of the macro invocation is
1597 the location of the expansion point of that top-level macro
1598 invocation. */
1599 expand_loc = pfile->invocation_location;
1600
1601 return builtin_macro (pfile, node, location, expand_loc);
28
Calling 'builtin_macro'
1602 }
1603}
1604
1605/* De-allocate the memory used by BUFF which is an array of instances
1606 of macro_arg. NUM_ARGS is the number of instances of macro_arg
1607 present in BUFF. */
1608static void
1609delete_macro_args (_cpp_buff *buff, unsigned num_args)
1610{
1611 macro_arg *macro_args;
1612 unsigned i;
1613
1614 if (buff == NULL__null)
1615 return;
1616
1617 macro_args = (macro_arg *) buff->base;
1618
1619 /* Walk instances of macro_arg to free their expanded tokens as well
1620 as their macro_arg::virt_locs members. */
1621 for (i = 0; i < num_args; ++i)
1622 {
1623 if (macro_args[i].expanded)
1624 {
1625 free (macro_args[i].expanded);
1626 macro_args[i].expanded = NULL__null;
1627 }
1628 if (macro_args[i].virt_locs)
1629 {
1630 free (macro_args[i].virt_locs);
1631 macro_args[i].virt_locs = NULL__null;
1632 }
1633 if (macro_args[i].expanded_virt_locs)
1634 {
1635 free (macro_args[i].expanded_virt_locs);
1636 macro_args[i].expanded_virt_locs = NULL__null;
1637 }
1638 }
1639 _cpp_free_buff (buff);
1640}
1641
1642/* Set the INDEXth token of the macro argument ARG. TOKEN is the token
1643 to set, LOCATION is its virtual location. "Virtual" location means
1644 the location that encodes loci across macro expansion. Otherwise
1645 it has to be TOKEN->SRC_LOC. KIND is the kind of tokens the
1646 argument ARG is supposed to contain. Note that ARG must be
1647 tailored so that it has enough room to contain INDEX + 1 numbers of
1648 tokens, at least. */
1649static void
1650set_arg_token (macro_arg *arg, const cpp_token *token,
1651 location_t location, size_t index,
1652 enum macro_arg_token_kind kind,
1653 bool track_macro_exp_p)
1654{
1655 const cpp_token **token_ptr;
1656 location_t *loc = NULL__null;
1657
1658 token_ptr =
1659 arg_token_ptr_at (arg, index, kind,
1660 track_macro_exp_p ? &loc : NULL__null);
1661 *token_ptr = token;
1662
1663 if (loc != NULL__null)
1664 {
1665 /* We can't set the location of a stringified argument
1666 token and we can't set any location if we aren't tracking
1667 macro expansion locations. */
1668 gcc_checking_assert (kind != MACRO_ARG_TOKEN_STRINGIFIED((void)(!(kind != MACRO_ARG_TOKEN_STRINGIFIED && track_macro_exp_p
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1669, __FUNCTION__), 0 : 0))
1669 && track_macro_exp_p)((void)(!(kind != MACRO_ARG_TOKEN_STRINGIFIED && track_macro_exp_p
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1669, __FUNCTION__), 0 : 0))
;
1670 *loc = location;
1671 }
1672}
1673
1674/* Get the pointer to the location of the argument token of the
1675 function-like macro argument ARG. This function must be called
1676 only when we -ftrack-macro-expansion is on. */
1677static const location_t *
1678get_arg_token_location (const macro_arg *arg,
1679 enum macro_arg_token_kind kind)
1680{
1681 const location_t *loc = NULL__null;
1682 const cpp_token **token_ptr =
1683 arg_token_ptr_at (arg, 0, kind, (location_t **) &loc);
1684
1685 if (token_ptr == NULL__null)
1686 return NULL__null;
1687
1688 return loc;
1689}
1690
1691/* Return the pointer to the INDEXth token of the macro argument ARG.
1692 KIND specifies the kind of token the macro argument ARG contains.
1693 If VIRT_LOCATION is non NULL, *VIRT_LOCATION is set to the address
1694 of the virtual location of the returned token if the
1695 -ftrack-macro-expansion flag is on; otherwise, it's set to the
1696 spelling location of the returned token. */
1697static const cpp_token **
1698arg_token_ptr_at (const macro_arg *arg, size_t index,
1699 enum macro_arg_token_kind kind,
1700 location_t **virt_location)
1701{
1702 const cpp_token **tokens_ptr = NULL__null;
1703
1704 switch (kind)
1705 {
1706 case MACRO_ARG_TOKEN_NORMAL:
1707 tokens_ptr = arg->first;
1708 break;
1709 case MACRO_ARG_TOKEN_STRINGIFIED:
1710 tokens_ptr = (const cpp_token **) &arg->stringified;
1711 break;
1712 case MACRO_ARG_TOKEN_EXPANDED:
1713 tokens_ptr = arg->expanded;
1714 break;
1715 }
1716
1717 if (tokens_ptr == NULL__null)
1718 /* This can happen for e.g, an empty token argument to a
1719 funtion-like macro. */
1720 return tokens_ptr;
1721
1722 if (virt_location)
1723 {
1724 if (kind == MACRO_ARG_TOKEN_NORMAL)
1725 *virt_location = &arg->virt_locs[index];
1726 else if (kind == MACRO_ARG_TOKEN_EXPANDED)
1727 *virt_location = &arg->expanded_virt_locs[index];
1728 else if (kind == MACRO_ARG_TOKEN_STRINGIFIED)
1729 *virt_location =
1730 (location_t *) &tokens_ptr[index]->src_loc;
1731 }
1732 return &tokens_ptr[index];
1733}
1734
1735/* Initialize an iterator so that it iterates over the tokens of a
1736 function-like macro argument. KIND is the kind of tokens we want
1737 ITER to iterate over. TOKEN_PTR points the first token ITER will
1738 iterate over. */
1739static void
1740macro_arg_token_iter_init (macro_arg_token_iter *iter,
1741 bool track_macro_exp_p,
1742 enum macro_arg_token_kind kind,
1743 const macro_arg *arg,
1744 const cpp_token **token_ptr)
1745{
1746 iter->track_macro_exp_p = track_macro_exp_p;
1747 iter->kind = kind;
1748 iter->token_ptr = token_ptr;
1749 /* Unconditionally initialize this so that the compiler doesn't warn
1750 about iter->location_ptr being possibly uninitialized later after
1751 this code has been inlined somewhere. */
1752 iter->location_ptr = NULL__null;
1753 if (track_macro_exp_p)
1754 iter->location_ptr = get_arg_token_location (arg, kind);
1755#if CHECKING_P1
1756 iter->num_forwards = 0;
1757 if (track_macro_exp_p
1758 && token_ptr != NULL__null
1759 && iter->location_ptr == NULL__null)
1760 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1760, __FUNCTION__)
;
1761#endif
1762}
1763
1764/* Move the iterator one token forward. Note that if IT was
1765 initialized on an argument that has a stringified token, moving it
1766 forward doesn't make sense as a stringified token is essentially one
1767 string. */
1768static void
1769macro_arg_token_iter_forward (macro_arg_token_iter *it)
1770{
1771 switch (it->kind)
1772 {
1773 case MACRO_ARG_TOKEN_NORMAL:
1774 case MACRO_ARG_TOKEN_EXPANDED:
1775 it->token_ptr++;
1776 if (it->track_macro_exp_p)
1777 it->location_ptr++;
1778 break;
1779 case MACRO_ARG_TOKEN_STRINGIFIED:
1780#if CHECKING_P1
1781 if (it->num_forwards > 0)
1782 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1782, __FUNCTION__)
;
1783#endif
1784 break;
1785 }
1786
1787#if CHECKING_P1
1788 it->num_forwards++;
1789#endif
1790}
1791
1792/* Return the token pointed to by the iterator. */
1793static const cpp_token *
1794macro_arg_token_iter_get_token (const macro_arg_token_iter *it)
1795{
1796#if CHECKING_P1
1797 if (it->kind == MACRO_ARG_TOKEN_STRINGIFIED
1798 && it->num_forwards > 0)
1799 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1799, __FUNCTION__)
;
1800#endif
1801 if (it->token_ptr == NULL__null)
1802 return NULL__null;
1803 return *it->token_ptr;
1804}
1805
1806/* Return the location of the token pointed to by the iterator.*/
1807static location_t
1808macro_arg_token_iter_get_location (const macro_arg_token_iter *it)
1809{
1810#if CHECKING_P1
1811 if (it->kind == MACRO_ARG_TOKEN_STRINGIFIED
1812 && it->num_forwards > 0)
1813 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 1813, __FUNCTION__)
;
1814#endif
1815 if (it->track_macro_exp_p)
1816 return *it->location_ptr;
1817 else
1818 return (*it->token_ptr)->src_loc;
1819}
1820
1821/* Return the index of a token [resulting from macro expansion] inside
1822 the total list of tokens resulting from a given macro
1823 expansion. The index can be different depending on whether if we
1824 want each tokens resulting from function-like macro arguments
1825 expansion to have a different location or not.
1826
1827 E.g, consider this function-like macro:
1828
1829 #define M(x) x - 3
1830
1831 Then consider us "calling" it (and thus expanding it) like:
1832
1833 M(1+4)
1834
1835 It will be expanded into:
1836
1837 1+4-3
1838
1839 Let's consider the case of the token '4'.
1840
1841 Its index can be 2 (it's the third token of the set of tokens
1842 resulting from the expansion) or it can be 0 if we consider that
1843 all tokens resulting from the expansion of the argument "1+2" have
1844 the same index, which is 0. In this later case, the index of token
1845 '-' would then be 1 and the index of token '3' would be 2.
1846
1847 The later case is useful to use less memory e.g, for the case of
1848 the user using the option -ftrack-macro-expansion=1.
1849
1850 ABSOLUTE_TOKEN_INDEX is the index of the macro argument token we
1851 are interested in. CUR_REPLACEMENT_TOKEN is the token of the macro
1852 parameter (inside the macro replacement list) that corresponds to
1853 the macro argument for which ABSOLUTE_TOKEN_INDEX is a token index
1854 of.
1855
1856 If we refer to the example above, for the '4' argument token,
1857 ABSOLUTE_TOKEN_INDEX would be set to 2, and CUR_REPLACEMENT_TOKEN
1858 would be set to the token 'x', in the replacement list "x - 3" of
1859 macro M.
1860
1861 This is a subroutine of replace_args. */
1862inline static unsigned
1863expanded_token_index (cpp_reader *pfile, cpp_macro *macro,
1864 const cpp_token *cur_replacement_token,
1865 unsigned absolute_token_index)
1866{
1867 if (CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion) > 1)
1868 return absolute_token_index;
1869 return cur_replacement_token - macro->exp.tokens;
1870}
1871
1872/* Copy whether PASTE_LEFT is set from SRC to *PASTE_FLAG. */
1873
1874static void
1875copy_paste_flag (cpp_reader *pfile, const cpp_token **paste_flag,
1876 const cpp_token *src)
1877{
1878 cpp_token *token = _cpp_temp_token (pfile);
1879 token->type = (*paste_flag)->type;
1880 token->val = (*paste_flag)->val;
1881 if (src->flags & PASTE_LEFT(1 << 3))
1882 token->flags = (*paste_flag)->flags | PASTE_LEFT(1 << 3);
1883 else
1884 token->flags = (*paste_flag)->flags & ~PASTE_LEFT(1 << 3);
1885 *paste_flag = token;
1886}
1887
1888/* True IFF the last token emitted into BUFF (if any) is PTR. */
1889
1890static bool
1891last_token_is (_cpp_buff *buff, const cpp_token **ptr)
1892{
1893 return (ptr && tokens_buff_last_token_ptr (buff) == ptr);
1894}
1895
1896/* Replace the parameters in a function-like macro of NODE with the
1897 actual ARGS, and place the result in a newly pushed token context.
1898 Expand each argument before replacing, unless it is operated upon
1899 by the # or ## operators. EXPANSION_POINT_LOC is the location of
1900 the expansion point of the macro. E.g, the location of the
1901 function-like macro invocation. */
1902static void
1903replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
1904 macro_arg *args, location_t expansion_point_loc)
1905{
1906 unsigned int i, total;
1907 const cpp_token *src, *limit;
1908 const cpp_token **first = NULL__null;
1909 macro_arg *arg;
1910 _cpp_buff *buff = NULL__null;
1911 location_t *virt_locs = NULL__null;
1912 unsigned int exp_count;
1913 const line_map_macro *map = NULL__null;
1914 int track_macro_exp;
1915
1916 /* First, fully macro-expand arguments, calculating the number of
1917 tokens in the final expansion as we go. The ordering of the if
1918 statements below is subtle; we must handle stringification before
1919 pasting. */
1920
1921 /* EXP_COUNT is the number of tokens in the macro replacement
1922 list. TOTAL is the number of tokens /after/ macro parameters
1923 have been replaced by their arguments. */
1924 exp_count = macro_real_token_count (macro);
1925 total = exp_count;
1926 limit = macro->exp.tokens + exp_count;
1927
1928 for (src = macro->exp.tokens; src < limit; src++)
1929 if (src->type == CPP_MACRO_ARG)
1930 {
1931 /* Leading and trailing padding tokens. */
1932 total += 2;
1933 /* Account for leading and padding tokens in exp_count too.
1934 This is going to be important later down this function,
1935 when we want to handle the case of (track_macro_exp <
1936 2). */
1937 exp_count += 2;
1938
1939 /* We have an argument. If it is not being stringified or
1940 pasted it is macro-replaced before insertion. */
1941 arg = &args[src->val.macro_arg.arg_no - 1];
1942
1943 if (src->flags & STRINGIFY_ARG(1 << 2))
1944 {
1945 if (!arg->stringified)
1946 arg->stringified = stringify_arg (pfile, arg->first, arg->count,
1947 false);
1948 }
1949 else if ((src->flags & PASTE_LEFT(1 << 3))
1950 || (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT(1 << 3))))
1951 total += arg->count - 1;
1952 else
1953 {
1954 if (!arg->expanded)
1955 expand_arg (pfile, arg);
1956 total += arg->expanded_count - 1;
1957 }
1958 }
1959
1960 /* When the compiler is called with the -ftrack-macro-expansion
1961 flag, we need to keep track of the location of each token that
1962 results from macro expansion.
1963
1964 A token resulting from macro expansion is not a new token. It is
1965 simply the same token as the token coming from the macro
1966 definition. The new things that are allocated are the buffer
1967 that holds the tokens resulting from macro expansion and a new
1968 location that records many things like the locus of the expansion
1969 point as well as the original locus inside the definition of the
1970 macro. This location is called a virtual location.
1971
1972 So the buffer BUFF holds a set of cpp_token*, and the buffer
1973 VIRT_LOCS holds the virtual locations of the tokens held by BUFF.
1974
1975 Both of these two buffers are going to be hung off of the macro
1976 context, when the latter is pushed. The memory allocated to
1977 store the tokens and their locations is going to be freed once
1978 the context of macro expansion is popped.
1979
1980 As far as tokens are concerned, the memory overhead of
1981 -ftrack-macro-expansion is proportional to the number of
1982 macros that get expanded multiplied by sizeof (location_t).
1983 The good news is that extra memory gets freed when the macro
1984 context is freed, i.e shortly after the macro got expanded. */
1985
1986 /* Is the -ftrack-macro-expansion flag in effect? */
1987 track_macro_exp = CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion);
1988
1989 /* Now allocate memory space for tokens and locations resulting from
1990 the macro expansion, copy the tokens and replace the arguments.
1991 This memory must be freed when the context of the macro MACRO is
1992 popped. */
1993 buff = tokens_buff_new (pfile, total, track_macro_exp ? &virt_locs : NULL__null);
1994
1995 first = (const cpp_token **) buff->base;
1996
1997 /* Create a macro map to record the locations of the tokens that are
1998 involved in the expansion. Note that the expansion point is set
1999 to the location of the closing parenthesis. Otherwise, the
2000 subsequent map created for the first token that comes after the
2001 macro map might have a wrong line number. That would lead to
2002 tokens with wrong line numbers after the macro expansion. This
2003 adds up to the memory overhead of the -ftrack-macro-expansion
2004 flag; for every macro that is expanded, a "macro map" is
2005 created. */
2006 if (track_macro_exp)
2007 {
2008 int num_macro_tokens = total;
2009 if (track_macro_exp < 2)
2010 /* Then the number of macro tokens won't take in account the
2011 fact that function-like macro arguments can expand to
2012 multiple tokens. This is to save memory at the expense of
2013 accuracy.
2014
2015 Suppose we have #define SQUARE(A) A * A
2016
2017 And then we do SQUARE(2+3)
2018
2019 Then the tokens 2, +, 3, will have the same location,
2020 saying they come from the expansion of the argument A. */
2021 num_macro_tokens = exp_count;
2022 map = linemap_enter_macro (pfile->line_table, node,
2023 expansion_point_loc,
2024 num_macro_tokens);
2025 }
2026 i = 0;
2027 vaopt_state vaopt_tracker (pfile, macro->variadic, &args[macro->paramc - 1]);
2028 const cpp_token **vaopt_start = NULL__null;
2029 for (src = macro->exp.tokens; src < limit; src++)
2030 {
2031 unsigned int arg_tokens_count;
2032 macro_arg_token_iter from;
2033 const cpp_token **paste_flag = NULL__null;
2034 const cpp_token **tmp_token_ptr;
2035
2036 /* __VA_OPT__ handling. */
2037 vaopt_state::update_type vostate = vaopt_tracker.update (src);
2038 if (__builtin_expect (vostate != vaopt_state::INCLUDE, false))
2039 {
2040 if (vostate == vaopt_state::BEGIN)
2041 {
2042 /* Padding on the left of __VA_OPT__ (unless RHS of ##). */
2043 if (src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT(1 << 3)))
2044 {
2045 const cpp_token *t = padding_token (pfile, src);
2046 unsigned index = expanded_token_index (pfile, macro, src, i);
2047 /* Allocate a virtual location for the padding token and
2048 append the token and its location to BUFF and
2049 VIRT_LOCS. */
2050 tokens_buff_add_token (buff, virt_locs, t,
2051 t->src_loc, t->src_loc,
2052 map, index);
2053 }
2054 vaopt_start = tokens_buff_last_token_ptr (buff);
2055 }
2056 else if (vostate == vaopt_state::END)
2057 {
2058 const cpp_token **start = vaopt_start;
2059 vaopt_start = NULL__null;
2060
2061 paste_flag = tokens_buff_last_token_ptr (buff);
2062
2063 if (vaopt_tracker.stringify ())
2064 {
2065 unsigned int count
2066 = start ? paste_flag - start : tokens_buff_count (buff);
2067 const cpp_token *t
2068 = stringify_arg (pfile,
2069 start ? start + 1
2070 : (const cpp_token **) (buff->base),
2071 count, true);
2072 while (count--)
2073 tokens_buff_remove_last_token (buff);
2074 if (src->flags & PASTE_LEFT(1 << 3))
2075 copy_paste_flag (pfile, &t, src);
2076 tokens_buff_add_token (buff, virt_locs,
2077 t, t->src_loc, t->src_loc,
2078 NULL__null, 0);
2079 }
2080 else if (src->flags & PASTE_LEFT(1 << 3))
2081 {
2082 /* Don't avoid paste after all. */
2083 while (paste_flag && paste_flag != start
2084 && *paste_flag == &pfile->avoid_paste)
2085 {
2086 tokens_buff_remove_last_token (buff);
2087 paste_flag = tokens_buff_last_token_ptr (buff);
2088 }
2089
2090 /* With a non-empty __VA_OPT__ on the LHS of ##, the last
2091 token should be flagged PASTE_LEFT. */
2092 if (paste_flag && (*paste_flag)->type != CPP_PADDING)
2093 copy_paste_flag (pfile, paste_flag, src);
2094 }
2095 else
2096 {
2097 /* Otherwise, avoid paste on RHS, __VA_OPT__(c)d or
2098 __VA_OPT__(c)__VA_OPT__(d). */
2099 const cpp_token *t = &pfile->avoid_paste;
2100 tokens_buff_add_token (buff, virt_locs,
2101 t, t->src_loc, t->src_loc,
2102 NULL__null, 0);
2103 }
2104 }
2105 continue;
2106 }
2107
2108 if (src->type != CPP_MACRO_ARG)
2109 {
2110 /* Allocate a virtual location for token SRC, and add that
2111 token and its virtual location into the buffers BUFF and
2112 VIRT_LOCS. */
2113 unsigned index = expanded_token_index (pfile, macro, src, i);
2114 tokens_buff_add_token (buff, virt_locs, src,
2115 src->src_loc, src->src_loc,
2116 map, index);
2117 i += 1;
2118 continue;
2119 }
2120
2121 paste_flag = 0;
2122 arg = &args[src->val.macro_arg.arg_no - 1];
2123 /* SRC is a macro parameter that we need to replace with its
2124 corresponding argument. So at some point we'll need to
2125 iterate over the tokens of the macro argument and copy them
2126 into the "place" now holding the correspondig macro
2127 parameter. We are going to use the iterator type
2128 macro_argo_token_iter to handle that iterating. The 'if'
2129 below is to initialize the iterator depending on the type of
2130 tokens the macro argument has. It also does some adjustment
2131 related to padding tokens and some pasting corner cases. */
2132 if (src->flags & STRINGIFY_ARG(1 << 2))
2133 {
2134 arg_tokens_count = 1;
2135 macro_arg_token_iter_init (&from,
2136 CPP_OPTION (pfile,((pfile)->opts.track_macro_expansion)
2137 track_macro_expansion)((pfile)->opts.track_macro_expansion),
2138 MACRO_ARG_TOKEN_STRINGIFIED,
2139 arg, &arg->stringified);
2140 }
2141 else if (src->flags & PASTE_LEFT(1 << 3))
2142 {
2143 arg_tokens_count = arg->count;
2144 macro_arg_token_iter_init (&from,
2145 CPP_OPTION (pfile,((pfile)->opts.track_macro_expansion)
2146 track_macro_expansion)((pfile)->opts.track_macro_expansion),
2147 MACRO_ARG_TOKEN_NORMAL,
2148 arg, arg->first);
2149 }
2150 else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT(1 << 3)))
2151 {
2152 int num_toks;
2153 arg_tokens_count = arg->count;
2154 macro_arg_token_iter_init (&from,
2155 CPP_OPTION (pfile,((pfile)->opts.track_macro_expansion)
2156 track_macro_expansion)((pfile)->opts.track_macro_expansion),
2157 MACRO_ARG_TOKEN_NORMAL,
2158 arg, arg->first);
2159
2160 num_toks = tokens_buff_count (buff);
2161
2162 if (num_toks != 0)
2163 {
2164 /* So the current parameter token is pasted to the previous
2165 token in the replacement list. Let's look at what
2166 we have as previous and current arguments. */
2167
2168 /* This is the previous argument's token ... */
2169 tmp_token_ptr = tokens_buff_last_token_ptr (buff);
2170
2171 if ((*tmp_token_ptr)->type == CPP_COMMA
2172 && macro->variadic
2173 && src->val.macro_arg.arg_no == macro->paramc)
2174 {
2175 /* ... which is a comma; and the current parameter
2176 is the last parameter of a variadic function-like
2177 macro. If the argument to the current last
2178 parameter is NULL, then swallow the comma,
2179 otherwise drop the paste flag. */
2180 if (macro_arg_token_iter_get_token (&from) == NULL__null)
2181 tokens_buff_remove_last_token (buff);
2182 else
2183 paste_flag = tmp_token_ptr;
2184 }
2185 /* Remove the paste flag if the RHS is a placemarker. */
2186 else if (arg_tokens_count == 0)
2187 paste_flag = tmp_token_ptr;
2188 }
2189 }
2190 else
2191 {
2192 arg_tokens_count = arg->expanded_count;
2193 macro_arg_token_iter_init (&from,
2194 CPP_OPTION (pfile,((pfile)->opts.track_macro_expansion)
2195 track_macro_expansion)((pfile)->opts.track_macro_expansion),
2196 MACRO_ARG_TOKEN_EXPANDED,
2197 arg, arg->expanded);
2198
2199 if (last_token_is (buff, vaopt_start))
2200 {
2201 /* We're expanding an arg at the beginning of __VA_OPT__.
2202 Skip padding. */
2203 while (arg_tokens_count)
2204 {
2205 const cpp_token *t = macro_arg_token_iter_get_token (&from);
2206 if (t->type != CPP_PADDING)
2207 break;
2208 macro_arg_token_iter_forward (&from);
2209 --arg_tokens_count;
2210 }
2211 }
2212 }
2213
2214 /* Padding on the left of an argument (unless RHS of ##). */
2215 if ((!pfile->state.in_directive || pfile->state.directive_wants_padding)
2216 && src != macro->exp.tokens
2217 && !(src[-1].flags & PASTE_LEFT(1 << 3))
2218 && !last_token_is (buff, vaopt_start))
2219 {
2220 const cpp_token *t = padding_token (pfile, src);
2221 unsigned index = expanded_token_index (pfile, macro, src, i);
2222 /* Allocate a virtual location for the padding token and
2223 append the token and its location to BUFF and
2224 VIRT_LOCS. */
2225 tokens_buff_add_token (buff, virt_locs, t,
2226 t->src_loc, t->src_loc,
2227 map, index);
2228 }
2229
2230 if (arg_tokens_count)
2231 {
2232 /* So now we've got the number of tokens that make up the
2233 argument that is going to replace the current parameter
2234 in the macro's replacement list. */
2235 unsigned int j;
2236 for (j = 0; j < arg_tokens_count; ++j)
2237 {
2238 /* So if track_macro_exp is < 2, the user wants to
2239 save extra memory while tracking macro expansion
2240 locations. So in that case here is what we do:
2241
2242 Suppose we have #define SQUARE(A) A * A
2243
2244 And then we do SQUARE(2+3)
2245
2246 Then the tokens 2, +, 3, will have the same location,
2247 saying they come from the expansion of the argument
2248 A.
2249
2250 So that means we are going to ignore the COUNT tokens
2251 resulting from the expansion of the current macro
2252 argument. In other words all the ARG_TOKENS_COUNT tokens
2253 resulting from the expansion of the macro argument will
2254 have the index I. Normally, each of those tokens should
2255 have index I+J. */
2256 unsigned token_index = i;
2257 unsigned index;
2258 if (track_macro_exp > 1)
2259 token_index += j;
2260
2261 index = expanded_token_index (pfile, macro, src, token_index);
2262 const cpp_token *tok = macro_arg_token_iter_get_token (&from);
2263 tokens_buff_add_token (buff, virt_locs, tok,
2264 macro_arg_token_iter_get_location (&from),
2265 src->src_loc, map, index);
2266 macro_arg_token_iter_forward (&from);
2267 }
2268
2269 /* With a non-empty argument on the LHS of ##, the last
2270 token should be flagged PASTE_LEFT. */
2271 if (src->flags & PASTE_LEFT(1 << 3))
2272 paste_flag
2273 = (const cpp_token **) tokens_buff_last_token_ptr (buff);
2274 }
2275 else if (CPP_PEDANTIC (pfile)((pfile)->opts.cpp_pedantic) && ! CPP_OPTION (pfile, c99)((pfile)->opts.c99)
2276 && ! macro->syshdr && ! _cpp_in_system_header (pfile))
2277 {
2278 if (CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus))
2279 cpp_pedwarning (pfile, CPP_W_PEDANTIC,
2280 "invoking macro %s argument %d: "
2281 "empty macro arguments are undefined"
2282 " in ISO C++98",
2283 NODE_NAME (node)(((&(node)->ident))->str), src->val.macro_arg.arg_no);
2284 else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)((pfile)->opts.cpp_warn_c90_c99_compat))
2285 cpp_pedwarning (pfile,
2286 CPP_OPTION (pfile, cpp_warn_c90_c99_compat)((pfile)->opts.cpp_warn_c90_c99_compat) > 0
2287 ? CPP_W_C90_C99_COMPAT : CPP_W_PEDANTIC,
2288 "invoking macro %s argument %d: "
2289 "empty macro arguments are undefined"
2290 " in ISO C90",
2291 NODE_NAME (node)(((&(node)->ident))->str), src->val.macro_arg.arg_no);
2292 }
2293 else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)((pfile)->opts.cpp_warn_c90_c99_compat) > 0
2294 && ! CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus)
2295 && ! macro->syshdr && ! _cpp_in_system_header (pfile))
2296 cpp_warning (pfile, CPP_W_C90_C99_COMPAT,
2297 "invoking macro %s argument %d: "
2298 "empty macro arguments are undefined"
2299 " in ISO C90",
2300 NODE_NAME (node)(((&(node)->ident))->str), src->val.macro_arg.arg_no);
2301
2302 /* Avoid paste on RHS (even case count == 0). */
2303 if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT(1 << 3)))
2304 {
2305 const cpp_token *t = &pfile->avoid_paste;
2306 tokens_buff_add_token (buff, virt_locs,
2307 t, t->src_loc, t->src_loc,
2308 NULL__null, 0);
2309 }
2310
2311 /* Add a new paste flag, or remove an unwanted one. */
2312 if (paste_flag)
2313 copy_paste_flag (pfile, paste_flag, src);
2314
2315 i += arg_tokens_count;
2316 }
2317
2318 if (track_macro_exp)
2319 push_extended_tokens_context (pfile, node, buff, virt_locs, first,
2320 tokens_buff_count (buff));
2321 else
2322 push_ptoken_context (pfile, node, buff, first,
2323 tokens_buff_count (buff));
2324
2325 num_macro_tokens_counter += tokens_buff_count (buff);
2326}
2327
2328/* Return a special padding token, with padding inherited from SOURCE. */
2329static const cpp_token *
2330padding_token (cpp_reader *pfile, const cpp_token *source)
2331{
2332 cpp_token *result = _cpp_temp_token (pfile);
2333
2334 result->type = CPP_PADDING;
2335
2336 /* Data in GCed data structures cannot be made const so far, so we
2337 need a cast here. */
2338 result->val.source = (cpp_token *) source;
2339 result->flags = 0;
2340 return result;
2341}
2342
2343/* Get a new uninitialized context. Create a new one if we cannot
2344 re-use an old one. */
2345static cpp_context *
2346next_context (cpp_reader *pfile)
2347{
2348 cpp_context *result = pfile->context->next;
2349
2350 if (result == 0)
2351 {
2352 result = XNEW (cpp_context)((cpp_context *) xmalloc (sizeof (cpp_context)));
2353 memset (result, 0, sizeof (cpp_context));
2354 result->prev = pfile->context;
2355 result->next = 0;
2356 pfile->context->next = result;
2357 }
2358
2359 pfile->context = result;
2360 return result;
2361}
2362
2363/* Push a list of pointers to tokens. */
2364static void
2365push_ptoken_context (cpp_reader *pfile, cpp_hashnode *macro, _cpp_buff *buff,
2366 const cpp_token **first, unsigned int count)
2367{
2368 cpp_context *context = next_context (pfile);
2369
2370 context->tokens_kind = TOKENS_KIND_INDIRECT;
2371 context->c.macro = macro;
2372 context->buff = buff;
2373 FIRST (context)((context)->u.iso.first).ptoken = first;
2374 LAST (context)((context)->u.iso.last).ptoken = first + count;
2375}
2376
2377/* Push a list of tokens.
2378
2379 A NULL macro means that we should continue the current macro
2380 expansion, in essence. That means that if we are currently in a
2381 macro expansion context, we'll make the new pfile->context refer to
2382 the current macro. */
2383void
2384_cpp_push_token_context (cpp_reader *pfile, cpp_hashnode *macro,
2385 const cpp_token *first, unsigned int count)
2386{
2387 cpp_context *context;
2388
2389 if (macro == NULL__null)
2390 macro = macro_of_context (pfile->context);
2391
2392 context = next_context (pfile);
2393 context->tokens_kind = TOKENS_KIND_DIRECT;
2394 context->c.macro = macro;
2395 context->buff = NULL__null;
2396 FIRST (context)((context)->u.iso.first).token = first;
2397 LAST (context)((context)->u.iso.last).token = first + count;
2398}
2399
2400/* Build a context containing a list of tokens as well as their
2401 virtual locations and push it. TOKENS_BUFF is the buffer that
2402 contains the tokens pointed to by FIRST. If TOKENS_BUFF is
2403 non-NULL, it means that the context owns it, meaning that
2404 _cpp_pop_context will free it as well as VIRT_LOCS_BUFF that
2405 contains the virtual locations.
2406
2407 A NULL macro means that we should continue the current macro
2408 expansion, in essence. That means that if we are currently in a
2409 macro expansion context, we'll make the new pfile->context refer to
2410 the current macro. */
2411static void
2412push_extended_tokens_context (cpp_reader *pfile,
2413 cpp_hashnode *macro,
2414 _cpp_buff *token_buff,
2415 location_t *virt_locs,
2416 const cpp_token **first,
2417 unsigned int count)
2418{
2419 cpp_context *context;
2420 macro_context *m;
2421
2422 if (macro == NULL__null)
2423 macro = macro_of_context (pfile->context);
2424
2425 context = next_context (pfile);
2426 context->tokens_kind = TOKENS_KIND_EXTENDED;
2427 context->buff = token_buff;
2428
2429 m = XNEW (macro_context)((macro_context *) xmalloc (sizeof (macro_context)));
2430 m->macro_node = macro;
2431 m->virt_locs = virt_locs;
2432 m->cur_virt_loc = virt_locs;
2433 context->c.mc = m;
2434 FIRST (context)((context)->u.iso.first).ptoken = first;
2435 LAST (context)((context)->u.iso.last).ptoken = first + count;
2436}
2437
2438/* Push a traditional macro's replacement text. */
2439void
2440_cpp_push_text_context (cpp_reader *pfile, cpp_hashnode *macro,
2441 const uchar *start, size_t len)
2442{
2443 cpp_context *context = next_context (pfile);
2444
2445 context->tokens_kind = TOKENS_KIND_DIRECT;
2446 context->c.macro = macro;
2447 context->buff = NULL__null;
2448 CUR (context)((context)->u.trad.cur) = start;
2449 RLIMIT (context)((context)->u.trad.rlimit) = start + len;
2450 macro->flags |= NODE_DISABLED(1 << 4);
2451}
2452
2453/* Creates a buffer that holds tokens a.k.a "token buffer", usually
2454 for the purpose of storing them on a cpp_context. If VIRT_LOCS is
2455 non-null (which means that -ftrack-macro-expansion is on),
2456 *VIRT_LOCS is set to a newly allocated buffer that is supposed to
2457 hold the virtual locations of the tokens resulting from macro
2458 expansion. */
2459static _cpp_buff*
2460tokens_buff_new (cpp_reader *pfile, size_t len,
2461 location_t **virt_locs)
2462{
2463 size_t tokens_size = len * sizeof (cpp_token *);
2464 size_t locs_size = len * sizeof (location_t);
2465
2466 if (virt_locs != NULL__null)
2467 *virt_locs = XNEWVEC (location_t, locs_size)((location_t *) xmalloc (sizeof (location_t) * (locs_size)));
2468 return _cpp_get_buff (pfile, tokens_size);
2469}
2470
2471/* Returns the number of tokens contained in a token buffer. The
2472 buffer holds a set of cpp_token*. */
2473static size_t
2474tokens_buff_count (_cpp_buff *buff)
2475{
2476 return (BUFF_FRONT (buff)((buff)->cur) - buff->base) / sizeof (cpp_token *);
2477}
2478
2479/* Return a pointer to the last token contained in the token buffer
2480 BUFF. */
2481static const cpp_token **
2482tokens_buff_last_token_ptr (_cpp_buff *buff)
2483{
2484 if (BUFF_FRONT (buff)((buff)->cur) == buff->base)
2485 return NULL__null;
2486 return &((const cpp_token **) BUFF_FRONT (buff)((buff)->cur))[-1];
2487}
2488
2489/* Remove the last token contained in the token buffer TOKENS_BUFF.
2490 If VIRT_LOCS_BUFF is non-NULL, it should point at the buffer
2491 containing the virtual locations of the tokens in TOKENS_BUFF; in
2492 which case the function updates that buffer as well. */
2493static inline void
2494tokens_buff_remove_last_token (_cpp_buff *tokens_buff)
2495
2496{
2497 if (BUFF_FRONT (tokens_buff)((tokens_buff)->cur) > tokens_buff->base)
2498 BUFF_FRONT (tokens_buff)((tokens_buff)->cur) =
2499 (unsigned char *) &((cpp_token **) BUFF_FRONT (tokens_buff)((tokens_buff)->cur))[-1];
2500}
2501
2502/* Insert a token into the token buffer at the position pointed to by
2503 DEST. Note that the buffer is not enlarged so the previous token
2504 that was at *DEST is overwritten. VIRT_LOC_DEST, if non-null,
2505 means -ftrack-macro-expansion is effect; it then points to where to
2506 insert the virtual location of TOKEN. TOKEN is the token to
2507 insert. VIRT_LOC is the virtual location of the token, i.e, the
2508 location possibly encoding its locus across macro expansion. If
2509 TOKEN is an argument of a function-like macro (inside a macro
2510 replacement list), PARM_DEF_LOC is the spelling location of the
2511 macro parameter that TOKEN is replacing, in the replacement list of
2512 the macro. If TOKEN is not an argument of a function-like macro or
2513 if it doesn't come from a macro expansion, then VIRT_LOC can just
2514 be set to the same value as PARM_DEF_LOC. If MAP is non null, it
2515 means TOKEN comes from a macro expansion and MAP is the macro map
2516 associated to the macro. MACRO_TOKEN_INDEX points to the index of
2517 the token in the macro map; it is not considered if MAP is NULL.
2518
2519 Upon successful completion this function returns the a pointer to
2520 the position of the token coming right after the insertion
2521 point. */
2522static inline const cpp_token **
2523tokens_buff_put_token_to (const cpp_token **dest,
2524 location_t *virt_loc_dest,
2525 const cpp_token *token,
2526 location_t virt_loc,
2527 location_t parm_def_loc,
2528 const line_map_macro *map,
2529 unsigned int macro_token_index)
2530{
2531 location_t macro_loc = virt_loc;
2532 const cpp_token **result;
2533
2534 if (virt_loc_dest)
2535 {
2536 /* -ftrack-macro-expansion is on. */
2537 if (map)
2538 macro_loc = linemap_add_macro_token (map, macro_token_index,
2539 virt_loc, parm_def_loc);
2540 *virt_loc_dest = macro_loc;
2541 }
2542 *dest = token;
2543 result = &dest[1];
2544
2545 return result;
2546}
2547
2548/* Adds a token at the end of the tokens contained in BUFFER. Note
2549 that this function doesn't enlarge BUFFER when the number of tokens
2550 reaches BUFFER's size; it aborts in that situation.
2551
2552 TOKEN is the token to append. VIRT_LOC is the virtual location of
2553 the token, i.e, the location possibly encoding its locus across
2554 macro expansion. If TOKEN is an argument of a function-like macro
2555 (inside a macro replacement list), PARM_DEF_LOC is the location of
2556 the macro parameter that TOKEN is replacing. If TOKEN doesn't come
2557 from a macro expansion, then VIRT_LOC can just be set to the same
2558 value as PARM_DEF_LOC. If MAP is non null, it means TOKEN comes
2559 from a macro expansion and MAP is the macro map associated to the
2560 macro. MACRO_TOKEN_INDEX points to the index of the token in the
2561 macro map; It is not considered if MAP is NULL. If VIRT_LOCS is
2562 non-null, it means -ftrack-macro-expansion is on; in which case
2563 this function adds the virtual location DEF_LOC to the VIRT_LOCS
2564 array, at the same index as the one of TOKEN in BUFFER. Upon
2565 successful completion this function returns the a pointer to the
2566 position of the token coming right after the insertion point. */
2567static const cpp_token **
2568tokens_buff_add_token (_cpp_buff *buffer,
2569 location_t *virt_locs,
2570 const cpp_token *token,
2571 location_t virt_loc,
2572 location_t parm_def_loc,
2573 const line_map_macro *map,
2574 unsigned int macro_token_index)
2575{
2576 const cpp_token **result;
2577 location_t *virt_loc_dest = NULL__null;
2578 unsigned token_index =
2579 (BUFF_FRONT (buffer)((buffer)->cur) - buffer->base) / sizeof (cpp_token *);
2580
2581 /* Abort if we pass the end the buffer. */
2582 if (BUFF_FRONT (buffer)((buffer)->cur) > BUFF_LIMIT (buffer)((buffer)->limit))
2583 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2583, __FUNCTION__)
;
2584
2585 if (virt_locs != NULL__null)
2586 virt_loc_dest = &virt_locs[token_index];
2587
2588 result =
2589 tokens_buff_put_token_to ((const cpp_token **) BUFF_FRONT (buffer)((buffer)->cur),
2590 virt_loc_dest, token, virt_loc, parm_def_loc,
2591 map, macro_token_index);
2592
2593 BUFF_FRONT (buffer)((buffer)->cur) = (unsigned char *) result;
2594 return result;
2595}
2596
2597/* Allocate space for the function-like macro argument ARG to store
2598 the tokens resulting from the macro-expansion of the tokens that
2599 make up ARG itself. That space is allocated in ARG->expanded and
2600 needs to be freed using free. */
2601static void
2602alloc_expanded_arg_mem (cpp_reader *pfile, macro_arg *arg, size_t capacity)
2603{
2604 gcc_checking_assert (arg->expanded == NULL((void)(!(arg->expanded == __null && arg->expanded_virt_locs
== __null) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2605, __FUNCTION__), 0 : 0))
2605 && arg->expanded_virt_locs == NULL)((void)(!(arg->expanded == __null && arg->expanded_virt_locs
== __null) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2605, __FUNCTION__), 0 : 0))
;
2606
2607 arg->expanded = XNEWVEC (const cpp_token *, capacity)((const cpp_token * *) xmalloc (sizeof (const cpp_token *) * (
capacity)))
;
2608 if (CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion))
2609 arg->expanded_virt_locs = XNEWVEC (location_t, capacity)((location_t *) xmalloc (sizeof (location_t) * (capacity)));
2610
2611}
2612
2613/* If necessary, enlarge ARG->expanded to so that it can contain SIZE
2614 tokens. */
2615static void
2616ensure_expanded_arg_room (cpp_reader *pfile, macro_arg *arg,
2617 size_t size, size_t *expanded_capacity)
2618{
2619 if (size <= *expanded_capacity)
2620 return;
2621
2622 size *= 2;
2623
2624 arg->expanded =
2625 XRESIZEVEC (const cpp_token *, arg->expanded, size)((const cpp_token * *) xrealloc ((void *) (arg->expanded),
sizeof (const cpp_token *) * (size)))
;
2626 *expanded_capacity = size;
2627
2628 if (CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion))
2629 {
2630 if (arg->expanded_virt_locs == NULL__null)
2631 arg->expanded_virt_locs = XNEWVEC (location_t, size)((location_t *) xmalloc (sizeof (location_t) * (size)));
2632 else
2633 arg->expanded_virt_locs = XRESIZEVEC (location_t,((location_t *) xrealloc ((void *) (arg->expanded_virt_locs
), sizeof (location_t) * (size)))
2634 arg->expanded_virt_locs,((location_t *) xrealloc ((void *) (arg->expanded_virt_locs
), sizeof (location_t) * (size)))
2635 size)((location_t *) xrealloc ((void *) (arg->expanded_virt_locs
), sizeof (location_t) * (size)))
;
2636 }
2637}
2638
2639/* Expand an argument ARG before replacing parameters in a
2640 function-like macro. This works by pushing a context with the
2641 argument's tokens, and then expanding that into a temporary buffer
2642 as if it were a normal part of the token stream. collect_args()
2643 has terminated the argument's tokens with a CPP_EOF so that we know
2644 when we have fully expanded the argument. */
2645static void
2646expand_arg (cpp_reader *pfile, macro_arg *arg)
2647{
2648 size_t capacity;
2649 bool saved_warn_trad;
2650 bool track_macro_exp_p = CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion);
2651
2652 if (arg->count == 0
2653 || arg->expanded != NULL__null)
2654 return;
2655
2656 /* Don't warn about funlike macros when pre-expanding. */
2657 saved_warn_trad = CPP_WTRADITIONAL (pfile)((pfile)->opts.cpp_warn_traditional);
2658 CPP_WTRADITIONAL (pfile)((pfile)->opts.cpp_warn_traditional) = 0;
2659
2660 /* Loop, reading in the tokens of the argument. */
2661 capacity = 256;
2662 alloc_expanded_arg_mem (pfile, arg, capacity);
2663
2664 if (track_macro_exp_p)
2665 push_extended_tokens_context (pfile, NULL__null, NULL__null,
2666 arg->virt_locs,
2667 arg->first,
2668 arg->count + 1);
2669 else
2670 push_ptoken_context (pfile, NULL__null, NULL__null,
2671 arg->first, arg->count + 1);
2672
2673 for (;;)
2674 {
2675 const cpp_token *token;
2676 location_t location;
2677
2678 ensure_expanded_arg_room (pfile, arg, arg->expanded_count + 1,
2679 &capacity);
2680
2681 token = cpp_get_token_1 (pfile, &location);
2682
2683 if (token->type == CPP_EOF)
2684 break;
2685
2686 set_arg_token (arg, token, location,
2687 arg->expanded_count, MACRO_ARG_TOKEN_EXPANDED,
2688 CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion));
2689 arg->expanded_count++;
2690 }
2691
2692 _cpp_pop_context (pfile);
2693
2694 CPP_WTRADITIONAL (pfile)((pfile)->opts.cpp_warn_traditional) = saved_warn_trad;
2695}
2696
2697/* Returns the macro associated to the current context if we are in
2698 the context a macro expansion, NULL otherwise. */
2699static cpp_hashnode*
2700macro_of_context (cpp_context *context)
2701{
2702 if (context == NULL__null)
2703 return NULL__null;
2704
2705 return (context->tokens_kind == TOKENS_KIND_EXTENDED)
2706 ? context->c.mc->macro_node
2707 : context->c.macro;
2708}
2709
2710/* Return TRUE iff we are expanding a macro or are about to start
2711 expanding one. If we are effectively expanding a macro, the
2712 function macro_of_context returns a pointer to the macro being
2713 expanded. */
2714static bool
2715in_macro_expansion_p (cpp_reader *pfile)
2716{
2717 if (pfile == NULL__null)
2718 return false;
2719
2720 return (pfile->about_to_expand_macro_p
2721 || macro_of_context (pfile->context));
2722}
2723
2724/* Pop the current context off the stack, re-enabling the macro if the
2725 context represented a macro's replacement list. Initially the
2726 context structure was not freed so that we can re-use it later, but
2727 now we do free it to reduce peak memory consumption. */
2728void
2729_cpp_pop_context (cpp_reader *pfile)
2730{
2731 cpp_context *context = pfile->context;
2732
2733 /* We should not be popping the base context. */
2734 gcc_assert (context != &pfile->base_context)((void)(!(context != &pfile->base_context) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2734, __FUNCTION__), 0 : 0))
;
2735
2736 if (context->c.macro)
2737 {
2738 cpp_hashnode *macro;
2739 if (context->tokens_kind == TOKENS_KIND_EXTENDED)
2740 {
2741 macro_context *mc = context->c.mc;
2742 macro = mc->macro_node;
2743 /* If context->buff is set, it means the life time of tokens
2744 is bound to the life time of this context; so we must
2745 free the tokens; that means we must free the virtual
2746 locations of these tokens too. */
2747 if (context->buff && mc->virt_locs)
2748 {
2749 free (mc->virt_locs);
2750 mc->virt_locs = NULL__null;
2751 }
2752 free (mc);
2753 context->c.mc = NULL__null;
2754 }
2755 else
2756 macro = context->c.macro;
2757
2758 /* Beware that MACRO can be NULL in cases like when we are
2759 called from expand_arg. In those cases, a dummy context with
2760 tokens is pushed just for the purpose of walking them using
2761 cpp_get_token_1. In that case, no 'macro' field is set into
2762 the dummy context. */
2763 if (macro != NULL__null
2764 /* Several contiguous macro expansion contexts can be
2765 associated to the same macro; that means it's the same
2766 macro expansion that spans across all these (sub)
2767 contexts. So we should re-enable an expansion-disabled
2768 macro only when we are sure we are really out of that
2769 macro expansion. */
2770 && macro_of_context (context->prev) != macro)
2771 macro->flags &= ~NODE_DISABLED(1 << 4);
2772
2773 if (macro == pfile->top_most_macro_node && context->prev == NULL__null)
2774 /* We are popping the context of the top-most macro node. */
2775 pfile->top_most_macro_node = NULL__null;
2776 }
2777
2778 if (context->buff)
2779 {
2780 /* Decrease memory peak consumption by freeing the memory used
2781 by the context. */
2782 _cpp_free_buff (context->buff);
2783 }
2784
2785 pfile->context = context->prev;
2786 /* decrease peak memory consumption by feeing the context. */
2787 pfile->context->next = NULL__null;
2788 free (context);
2789}
2790
2791/* Return TRUE if we reached the end of the set of tokens stored in
2792 CONTEXT, FALSE otherwise. */
2793static inline bool
2794reached_end_of_context (cpp_context *context)
2795{
2796 if (context->tokens_kind == TOKENS_KIND_DIRECT)
2797 return FIRST (context)((context)->u.iso.first).token == LAST (context)((context)->u.iso.last).token;
2798 else if (context->tokens_kind == TOKENS_KIND_INDIRECT
2799 || context->tokens_kind == TOKENS_KIND_EXTENDED)
2800 return FIRST (context)((context)->u.iso.first).ptoken == LAST (context)((context)->u.iso.last).ptoken;
2801 else
2802 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2802, __FUNCTION__)
;
2803}
2804
2805/* Consume the next token contained in the current context of PFILE,
2806 and return it in *TOKEN. It's "full location" is returned in
2807 *LOCATION. If -ftrack-macro-location is in effeect, fFull location"
2808 means the location encoding the locus of the token across macro
2809 expansion; otherwise it's just is the "normal" location of the
2810 token which (*TOKEN)->src_loc. */
2811static inline void
2812consume_next_token_from_context (cpp_reader *pfile,
2813 const cpp_token ** token,
2814 location_t *location)
2815{
2816 cpp_context *c = pfile->context;
2817
2818 if ((c)->tokens_kind == TOKENS_KIND_DIRECT)
2819 {
2820 *token = FIRST (c)((c)->u.iso.first).token;
2821 *location = (*token)->src_loc;
2822 FIRST (c)((c)->u.iso.first).token++;
2823 }
2824 else if ((c)->tokens_kind == TOKENS_KIND_INDIRECT)
2825 {
2826 *token = *FIRST (c)((c)->u.iso.first).ptoken;
2827 *location = (*token)->src_loc;
2828 FIRST (c)((c)->u.iso.first).ptoken++;
2829 }
2830 else if ((c)->tokens_kind == TOKENS_KIND_EXTENDED)
2831 {
2832 macro_context *m = c->c.mc;
2833 *token = *FIRST (c)((c)->u.iso.first).ptoken;
2834 if (m->virt_locs)
2835 {
2836 *location = *m->cur_virt_loc;
2837 m->cur_virt_loc++;
2838 }
2839 else
2840 *location = (*token)->src_loc;
2841 FIRST (c)((c)->u.iso.first).ptoken++;
2842 }
2843 else
2844 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 2844, __FUNCTION__)
;
2845}
2846
2847/* In the traditional mode of the preprocessor, if we are currently in
2848 a directive, the location of a token must be the location of the
2849 start of the directive line. This function returns the proper
2850 location if we are in the traditional mode, and just returns
2851 LOCATION otherwise. */
2852
2853static inline location_t
2854maybe_adjust_loc_for_trad_cpp (cpp_reader *pfile, location_t location)
2855{
2856 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
2857 {
2858 if (pfile->state.in_directive)
2859 return pfile->directive_line;
2860 }
2861 return location;
2862}
2863
2864/* Routine to get a token as well as its location.
2865
2866 Macro expansions and directives are transparently handled,
2867 including entering included files. Thus tokens are post-macro
2868 expansion, and after any intervening directives. External callers
2869 see CPP_EOF only at EOF. Internal callers also see it when meeting
2870 a directive inside a macro call, when at the end of a directive and
2871 state.in_directive is still 1, and at the end of argument
2872 pre-expansion.
2873
2874 LOC is an out parameter; *LOC is set to the location "as expected
2875 by the user". Please read the comment of
2876 cpp_get_token_with_location to learn more about the meaning of this
2877 location. */
2878static const cpp_token*
2879cpp_get_token_1 (cpp_reader *pfile, location_t *location)
2880{
2881 const cpp_token *result;
2882 /* This token is a virtual token that either encodes a location
2883 related to macro expansion or a spelling location. */
2884 location_t virt_loc = 0;
2885 /* pfile->about_to_expand_macro_p can be overriden by indirect calls
2886 to functions that push macro contexts. So let's save it so that
2887 we can restore it when we are about to leave this routine. */
2888 bool saved_about_to_expand_macro = pfile->about_to_expand_macro_p;
2889
2890 for (;;)
5
Loop condition is true. Entering loop body
2891 {
2892 cpp_hashnode *node;
2893 cpp_context *context = pfile->context;
2894
2895 /* Context->prev == 0 <=> base context. */
2896 if (!context->prev)
6
Assuming field 'prev' is non-null
7
Taking false branch
2897 {
2898 result = _cpp_lex_token (pfile);
2899 virt_loc = result->src_loc;
2900 }
2901 else if (!reached_end_of_context (context))
8
Taking true branch
2902 {
2903 consume_next_token_from_context (pfile, &result,
2904 &virt_loc);
2905 if (result->flags & PASTE_LEFT(1 << 3))
9
Assuming the condition is false
10
Taking false branch
2906 {
2907 paste_all_tokens (pfile, result);
2908 if (pfile->state.in_directive)
2909 continue;
2910 result = padding_token (pfile, result);
2911 goto out;
2912 }
2913 }
2914 else
2915 {
2916 if (pfile->context->c.macro)
2917 ++num_expanded_macros_counter;
2918 _cpp_pop_context (pfile);
2919 if (pfile->state.in_directive)
2920 continue;
2921 result = &pfile->avoid_paste;
2922 goto out;
2923 }
2924
2925 if (pfile->state.in_directive && result->type == CPP_COMMENT)
11
Assuming field 'in_directive' is 0
2926 continue;
2927
2928 if (result->type != CPP_NAME)
12
Assuming field 'type' is equal to CPP_NAME
13
Taking false branch
2929 break;
2930
2931 node = result->val.node.node;
2932
2933 if (node->type == NT_VOID || (result->flags & NO_EXPAND(1 << 10)))
14
Assuming field 'type' is not equal to NT_VOID
15
Assuming the condition is false
16
Taking false branch
2934 break;
2935
2936 if (!(node->flags & NODE_USED(1 << 5))
17
Assuming the condition is false
2937 && node->type == NT_USER_MACRO
2938 && !node->value.macro
2939 && !cpp_get_deferred_macro (pfile, node, result->src_loc))
2940 break;
2941
2942 if (!(node->flags & NODE_DISABLED(1 << 4)))
18
Assuming the condition is true
19
Taking true branch
2943 {
2944 int ret = 0;
2945 /* If not in a macro context, and we're going to start an
2946 expansion, record the location and the top level macro
2947 about to be expanded. */
2948 if (!in_macro_expansion_p (pfile))
20
Assuming the condition is false
21
Taking false branch
2949 {
2950 pfile->invocation_location = result->src_loc;
2951 pfile->top_most_macro_node = node;
2952 }
2953 if (pfile->state.prevent_expansion)
22
Assuming field 'prevent_expansion' is 0
23
Taking false branch
2954 break;
2955
2956 /* Conditional macros require that a predicate be evaluated
2957 first. */
2958 if ((node->flags & NODE_CONDITIONAL(1 << 6)) != 0)
24
Assuming the condition is false
25
Taking false branch
2959 {
2960 if (pfile->cb.macro_to_expand)
2961 {
2962 bool whitespace_after;
2963 const cpp_token *peek_tok = cpp_peek_token (pfile, 0);
2964
2965 whitespace_after = (peek_tok->type == CPP_PADDING
2966 || (peek_tok->flags & PREV_WHITE(1 << 0)));
2967 node = pfile->cb.macro_to_expand (pfile, result);
2968 if (node)
2969 ret = enter_macro_context (pfile, node, result, virt_loc);
2970 else if (whitespace_after)
2971 {
2972 /* If macro_to_expand hook returned NULL and it
2973 ate some tokens, see if we don't need to add
2974 a padding token in between this and the
2975 next token. */
2976 peek_tok = cpp_peek_token (pfile, 0);
2977 if (peek_tok->type != CPP_PADDING
2978 && (peek_tok->flags & PREV_WHITE(1 << 0)) == 0)
2979 _cpp_push_token_context (pfile, NULL__null,
2980 padding_token (pfile,
2981 peek_tok), 1);
2982 }
2983 }
2984 }
2985 else
2986 ret = enter_macro_context (pfile, node, result, virt_loc);
26
Calling 'enter_macro_context'
2987 if (ret)
2988 {
2989 if (pfile->state.in_directive || ret == 2)
2990 continue;
2991 result = padding_token (pfile, result);
2992 goto out;
2993 }
2994 }
2995 else
2996 {
2997 /* Flag this token as always unexpandable. FIXME: move this
2998 to collect_args()?. */
2999 cpp_token *t = _cpp_temp_token (pfile);
3000 t->type = result->type;
3001 t->flags = result->flags | NO_EXPAND(1 << 10);
3002 t->val = result->val;
3003 result = t;
3004 }
3005
3006 break;
3007 }
3008
3009 out:
3010 if (location != NULL__null)
3011 {
3012 if (virt_loc == 0)
3013 virt_loc = result->src_loc;
3014 *location = virt_loc;
3015
3016 if (!CPP_OPTION (pfile, track_macro_expansion)((pfile)->opts.track_macro_expansion)
3017 && macro_of_context (pfile->context) != NULL__null)
3018 /* We are in a macro expansion context, are not tracking
3019 virtual location, but were asked to report the location
3020 of the expansion point of the macro being expanded. */
3021 *location = pfile->invocation_location;
3022
3023 *location = maybe_adjust_loc_for_trad_cpp (pfile, *location);
3024 }
3025
3026 pfile->about_to_expand_macro_p = saved_about_to_expand_macro;
3027
3028 if (pfile->state.directive_file_token
3029 && !pfile->state.parsing_args
3030 && !(result->type == CPP_PADDING || result->type == CPP_COMMENT)
3031 && !(15 & --pfile->state.directive_file_token))
3032 {
3033 /* Do header-name frobbery. Concatenate < ... > as approprate.
3034 Do header search if needed, and finally drop the outer <> or
3035 "". */
3036 pfile->state.angled_headers = false;
3037
3038 /* Do angle-header reconstitution. Then do include searching.
3039 We'll always end up with a ""-quoted header-name in that
3040 case. If searching finds nothing, we emit a diagnostic and
3041 an empty string. */
3042 size_t len = 0;
3043 char *fname = NULL__null;
3044
3045 cpp_token *tmp = _cpp_temp_token (pfile);
3046 *tmp = *result;
3047
3048 tmp->type = CPP_HEADER_NAME;
3049 bool need_search = !pfile->state.directive_file_token;
3050 pfile->state.directive_file_token = 0;
3051
3052 bool angle = result->type != CPP_STRING;
3053 if (result->type == CPP_HEADER_NAME
3054 || (result->type == CPP_STRING && result->val.str.text[0] != 'R'))
3055 {
3056 len = result->val.str.len - 2;
3057 fname = XNEWVEC (char, len + 1)((char *) xmalloc (sizeof (char) * (len + 1)));
3058 memcpy (fname, result->val.str.text + 1, len);
3059 fname[len] = 0;
3060 }
3061 else if (result->type == CPP_LESS)
3062 fname = _cpp_bracket_include (pfile);
3063
3064 if (fname)
3065 {
3066 /* We have a header-name. Look it up. This will emit an
3067 unfound diagnostic. Canonicalize the found name. */
3068 const char *found = fname;
3069
3070 if (need_search)
3071 {
3072 found = _cpp_find_header_unit (pfile, fname, angle, tmp->src_loc);
3073 if (!found)
3074 found = "";
3075 len = strlen (found);
3076 }
3077 /* Force a leading './' if it's not absolute. */
3078 bool dotme = (found[0] == '.' ? !IS_DIR_SEPARATOR (found[1])(((found[1]) == '/') || (((found[1]) == '\\') && (0))
)
3079 : found[0] && !IS_ABSOLUTE_PATH (found)(((((found)[0]) == '/') || ((((found)[0]) == '\\') &&
(0))) || ((found)[0] && ((found)[1] == ':') &&
(0)))
);
3080
3081 if (BUFF_ROOM (pfile->u_buff)(size_t) ((pfile->u_buff)->limit - (pfile->u_buff)->
cur)
< len + 1 + dotme * 2)
3082 _cpp_extend_buff (pfile, &pfile->u_buff, len + 1 + dotme * 2);
3083 unsigned char *buf = BUFF_FRONT (pfile->u_buff)((pfile->u_buff)->cur);
3084 size_t pos = 0;
3085
3086 if (dotme)
3087 {
3088 buf[pos++] = '.';
3089 /* Apparently '/' is unconditional. */
3090 buf[pos++] = '/';
3091 }
3092 memcpy (&buf[pos], found, len);
3093 pos += len;
3094 buf[pos] = 0;
3095
3096 tmp->val.str.len = pos;
3097 tmp->val.str.text = buf;
3098
3099 tmp->type = CPP_HEADER_NAME;
3100 XDELETEVEC (fname)free ((void*) (fname));
3101
3102 result = tmp;
3103 }
3104 }
3105
3106 return result;
3107}
3108
3109/* External routine to get a token. Also used nearly everywhere
3110 internally, except for places where we know we can safely call
3111 _cpp_lex_token directly, such as lexing a directive name.
3112
3113 Macro expansions and directives are transparently handled,
3114 including entering included files. Thus tokens are post-macro
3115 expansion, and after any intervening directives. External callers
3116 see CPP_EOF only at EOF. Internal callers also see it when meeting
3117 a directive inside a macro call, when at the end of a directive and
3118 state.in_directive is still 1, and at the end of argument
3119 pre-expansion. */
3120const cpp_token *
3121cpp_get_token (cpp_reader *pfile)
3122{
3123 return cpp_get_token_1 (pfile, NULL__null);
4
Calling 'cpp_get_token_1'
3124}
3125
3126/* Like cpp_get_token, but also returns a virtual token location
3127 separate from the spelling location carried by the returned token.
3128
3129 LOC is an out parameter; *LOC is set to the location "as expected
3130 by the user". This matters when a token results from macro
3131 expansion; in that case the token's spelling location indicates the
3132 locus of the token in the definition of the macro but *LOC
3133 virtually encodes all the other meaningful locuses associated to
3134 the token.
3135
3136 What? virtual location? Yes, virtual location.
3137
3138 If the token results from macro expansion and if macro expansion
3139 location tracking is enabled its virtual location encodes (at the
3140 same time):
3141
3142 - the spelling location of the token
3143
3144 - the locus of the macro expansion point
3145
3146 - the locus of the point where the token got instantiated as part
3147 of the macro expansion process.
3148
3149 You have to use the linemap API to get the locus you are interested
3150 in from a given virtual location.
3151
3152 Note however that virtual locations are not necessarily ordered for
3153 relations '<' and '>'. One must use the function
3154 linemap_location_before_p instead of using the relational operator
3155 '<'.
3156
3157 If macro expansion tracking is off and if the token results from
3158 macro expansion the virtual location is the expansion point of the
3159 macro that got expanded.
3160
3161 When the token doesn't result from macro expansion, the virtual
3162 location is just the same thing as its spelling location. */
3163
3164const cpp_token *
3165cpp_get_token_with_location (cpp_reader *pfile, location_t *loc)
3166{
3167 return cpp_get_token_1 (pfile, loc);
3168}
3169
3170/* Returns true if we're expanding an object-like macro that was
3171 defined in a system header. Just checks the macro at the top of
3172 the stack. Used for diagnostic suppression.
3173 Also return true for builtin macros. */
3174int
3175cpp_sys_macro_p (cpp_reader *pfile)
3176{
3177 cpp_hashnode *node = NULL__null;
3178
3179 if (pfile->context->tokens_kind == TOKENS_KIND_EXTENDED)
3180 node = pfile->context->c.mc->macro_node;
3181 else
3182 node = pfile->context->c.macro;
3183
3184 if (!node)
3185 return false;
3186 if (cpp_builtin_macro_p (node))
3187 return true;
3188 return node->value.macro && node->value.macro->syshdr;
3189}
3190
3191/* Read each token in, until end of the current file. Directives are
3192 transparently processed. */
3193void
3194cpp_scan_nooutput (cpp_reader *pfile)
3195{
3196 /* Request a CPP_EOF token at the end of this file, rather than
3197 transparently continuing with the including file. */
3198 pfile->buffer->return_at_eof = true;
3199
3200 pfile->state.discarding_output++;
3201 pfile->state.prevent_expansion++;
3202
3203 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
1
Assuming field 'traditional' is 0
2
Taking false branch
3204 while (_cpp_read_logical_line_trad (pfile))
3205 ;
3206 else
3207 while (cpp_get_token (pfile)->type != CPP_EOF)
3
Calling 'cpp_get_token'
3208 ;
3209
3210 pfile->state.discarding_output--;
3211 pfile->state.prevent_expansion--;
3212}
3213
3214/* Step back one or more tokens obtained from the lexer. */
3215void
3216_cpp_backup_tokens_direct (cpp_reader *pfile, unsigned int count)
3217{
3218 pfile->lookaheads += count;
3219 while (count--)
3220 {
3221 pfile->cur_token--;
3222 if (pfile->cur_token == pfile->cur_run->base
3223 /* Possible with -fpreprocessed and no leading #line. */
3224 && pfile->cur_run->prev != NULL__null)
3225 {
3226 pfile->cur_run = pfile->cur_run->prev;
3227 pfile->cur_token = pfile->cur_run->limit;
3228 }
3229 }
3230}
3231
3232/* Step back one (or more) tokens. Can only step back more than 1 if
3233 they are from the lexer, and not from macro expansion. */
3234void
3235_cpp_backup_tokens (cpp_reader *pfile, unsigned int count)
3236{
3237 if (pfile->context->prev == NULL__null)
3238 _cpp_backup_tokens_direct (pfile, count);
3239 else
3240 {
3241 if (count != 1)
3242 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3242, __FUNCTION__)
;
3243 if (pfile->context->tokens_kind == TOKENS_KIND_DIRECT)
3244 FIRST (pfile->context)((pfile->context)->u.iso.first).token--;
3245 else if (pfile->context->tokens_kind == TOKENS_KIND_INDIRECT)
3246 FIRST (pfile->context)((pfile->context)->u.iso.first).ptoken--;
3247 else if (pfile->context->tokens_kind == TOKENS_KIND_EXTENDED)
3248 {
3249 FIRST (pfile->context)((pfile->context)->u.iso.first).ptoken--;
3250 if (pfile->context->c.macro)
3251 {
3252 macro_context *m = pfile->context->c.mc;
3253 m->cur_virt_loc--;
3254 gcc_checking_assert (m->cur_virt_loc >= m->virt_locs)((void)(!(m->cur_virt_loc >= m->virt_locs) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3254, __FUNCTION__), 0 : 0))
;
3255 }
3256 else
3257 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3257, __FUNCTION__)
;
3258 }
3259 else
3260 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3260, __FUNCTION__)
;
3261 }
3262}
3263
3264/* #define directive parsing and handling. */
3265
3266/* Returns true if a macro redefinition warning is required. */
3267static bool
3268warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
3269 const cpp_macro *macro2)
3270{
3271 /* Some redefinitions need to be warned about regardless. */
3272 if (node->flags & NODE_WARN(1 << 3))
3273 return true;
3274
3275 /* Suppress warnings for builtins that lack the NODE_WARN flag,
3276 unless Wbuiltin-macro-redefined. */
3277 if (cpp_builtin_macro_p (node))
3278 return CPP_OPTION (pfile, warn_builtin_macro_redefined)((pfile)->opts.warn_builtin_macro_redefined);
3279
3280 /* Redefinitions of conditional (context-sensitive) macros, on
3281 the other hand, must be allowed silently. */
3282 if (node->flags & NODE_CONDITIONAL(1 << 6))
3283 return false;
3284
3285 if (cpp_macro *macro1 = get_deferred_or_lazy_macro (pfile, node, macro2->line))
3286 return cpp_compare_macros (macro1, macro2);
3287 return false;
3288}
3289
3290/* Return TRUE if MACRO1 and MACRO2 differ. */
3291
3292bool
3293cpp_compare_macros (const cpp_macro *macro1, const cpp_macro *macro2)
3294{
3295 /* Redefinition of a macro is allowed if and only if the old and new
3296 definitions are the same. (6.10.3 paragraph 2). */
3297
3298 /* Don't check count here as it can be different in valid
3299 traditional redefinitions with just whitespace differences. */
3300 if (macro1->paramc != macro2->paramc
3301 || macro1->fun_like != macro2->fun_like
3302 || macro1->variadic != macro2->variadic)
3303 return true;
3304
3305 /* Check parameter spellings. */
3306 for (unsigned i = macro1->paramc; i--; )
3307 if (macro1->parm.params[i] != macro2->parm.params[i])
3308 return true;
3309
3310 /* Check the replacement text or tokens. */
3311 if (macro1->kind == cmk_traditional)
3312 return _cpp_expansions_different_trad (macro1, macro2);
3313
3314 if (macro1->count != macro2->count)
3315 return true;
3316
3317 for (unsigned i= macro1->count; i--; )
3318 if (!_cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
3319 return true;
3320
3321 return false;
3322}
3323
3324/* Free the definition of hashnode H. */
3325void
3326_cpp_free_definition (cpp_hashnode *h)
3327{
3328 /* Macros and assertions no longer have anything to free. */
3329 h->type = NT_VOID;
3330 h->value.answers = NULL__null;
3331 h->flags &= ~(NODE_DISABLED(1 << 4) | NODE_USED(1 << 5));
3332}
3333
3334/* Save parameter NODE (spelling SPELLING) to the parameter list of
3335 macro MACRO. Returns true on success, false on failure. */
3336bool
3337_cpp_save_parameter (cpp_reader *pfile, unsigned n, cpp_hashnode *node,
3338 cpp_hashnode *spelling)
3339{
3340 /* Constraint 6.10.3.6 - duplicate parameter names. */
3341 if (node->type == NT_MACRO_ARG)
3342 {
3343 cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"",
3344 NODE_NAME (node)(((&(node)->ident))->str));
3345 return false;
3346 }
3347
3348 unsigned len = (n + 1) * sizeof (struct macro_arg_saved_data);
3349 if (len > pfile->macro_buffer_len)
3350 {
3351 pfile->macro_buffer
3352 = XRESIZEVEC (unsigned char, pfile->macro_buffer, len)((unsigned char *) xrealloc ((void *) (pfile->macro_buffer
), sizeof (unsigned char) * (len)))
;
3353 pfile->macro_buffer_len = len;
3354 }
3355
3356 macro_arg_saved_data *saved = (macro_arg_saved_data *)pfile->macro_buffer;
3357 saved[n].canonical_node = node;
3358 saved[n].value = node->value;
3359 saved[n].type = node->type;
3360
3361 void *base = _cpp_reserve_room (pfile, n * sizeof (cpp_hashnode *),
3362 sizeof (cpp_hashnode *));
3363 ((cpp_hashnode **)base)[n] = spelling;
3364
3365 /* Morph into a macro arg. */
3366 node->type = NT_MACRO_ARG;
3367 /* Index is 1 based. */
3368 node->value.arg_index = n + 1;
3369
3370 return true;
3371}
3372
3373/* Restore the parameters to their previous state. */
3374void
3375_cpp_unsave_parameters (cpp_reader *pfile, unsigned n)
3376{
3377 /* Clear the fast argument lookup indices. */
3378 while (n--)
3379 {
3380 struct macro_arg_saved_data *save =
3381 &((struct macro_arg_saved_data *) pfile->macro_buffer)[n];
3382
3383 struct cpp_hashnode *node = save->canonical_node;
3384 node->type = save->type;
3385 node->value = save->value;
3386 }
3387}
3388
3389/* Check the syntax of the parameters in a MACRO definition. Return
3390 false on failure. Set *N_PTR and *VARADIC_PTR as appropriate.
3391 '(' ')'
3392 '(' parm-list ',' last-parm ')'
3393 '(' last-parm ')'
3394 parm-list: name
3395 | parm-list, name
3396 last-parm: name
3397 | name '...'
3398 | '...'
3399*/
3400
3401static bool
3402parse_params (cpp_reader *pfile, unsigned *n_ptr, bool *varadic_ptr)
3403{
3404 unsigned nparms = 0;
3405 bool ok = false;
3406
3407 for (bool prev_ident = false;;)
3408 {
3409 const cpp_token *token = _cpp_lex_token (pfile);
3410
3411 switch (token->type)
3412 {
3413 case CPP_COMMENT:
3414 /* Allow/ignore comments in parameter lists if we are
3415 preserving comments in macro expansions. */
3416 if (!CPP_OPTION (pfile, discard_comments_in_macro_exp)((pfile)->opts.discard_comments_in_macro_exp))
3417 break;
3418
3419 /* FALLTHRU */
3420 default:
3421 bad:
3422 {
3423 const char *const msgs[5] =
3424 {
3425 N_("expected parameter name, found \"%s\"")"expected parameter name, found \"%s\"",
3426 N_("expected ',' or ')', found \"%s\"")"expected ',' or ')', found \"%s\"",
3427 N_("expected parameter name before end of line")"expected parameter name before end of line",
3428 N_("expected ')' before end of line")"expected ')' before end of line",
3429 N_("expected ')' after \"...\"")"expected ')' after \"...\""
3430 };
3431 unsigned ix = prev_ident;
3432 const unsigned char *as_text = NULL__null;
3433 if (*varadic_ptr)
3434 ix = 4;
3435 else if (token->type == CPP_EOF)
3436 ix += 2;
3437 else
3438 as_text = cpp_token_as_text (pfile, token);
3439 cpp_error (pfile, CPP_DL_ERROR, msgs[ix], as_text);
3440 }
3441 goto out;
3442
3443 case CPP_NAME:
3444 if (prev_ident || *varadic_ptr)
3445 goto bad;
3446 prev_ident = true;
3447
3448 if (!_cpp_save_parameter (pfile, nparms, token->val.node.node,
3449 token->val.node.spelling))
3450 goto out;
3451 nparms++;
3452 break;
3453
3454 case CPP_CLOSE_PAREN:
3455 if (prev_ident || !nparms || *varadic_ptr)
3456 {
3457 ok = true;
3458 goto out;
3459 }
3460
3461 /* FALLTHRU */
3462 case CPP_COMMA:
3463 if (!prev_ident || *varadic_ptr)
3464 goto bad;
3465 prev_ident = false;
3466 break;
3467
3468 case CPP_ELLIPSIS:
3469 if (*varadic_ptr)
3470 goto bad;
3471 *varadic_ptr = true;
3472 if (!prev_ident)
3473 {
3474 /* An ISO bare ellipsis. */
3475 _cpp_save_parameter (pfile, nparms,
3476 pfile->spec_nodes.n__VA_ARGS__,
3477 pfile->spec_nodes.n__VA_ARGS__);
3478 nparms++;
3479 pfile->state.va_args_ok = 1;
3480 if (! CPP_OPTION (pfile, c99)((pfile)->opts.c99)
3481 && CPP_OPTION (pfile, cpp_pedantic)((pfile)->opts.cpp_pedantic)
3482 && CPP_OPTION (pfile, warn_variadic_macros)((pfile)->opts.warn_variadic_macros))
3483 cpp_pedwarning
3484 (pfile, CPP_W_VARIADIC_MACROS,
3485 CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus)
3486 ? N_("anonymous variadic macros were introduced in C++11")"anonymous variadic macros were introduced in C++11"
3487 : N_("anonymous variadic macros were introduced in C99")"anonymous variadic macros were introduced in C99");
3488 else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat)((pfile)->opts.cpp_warn_c90_c99_compat) > 0
3489 && ! CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus))
3490 cpp_error (pfile, CPP_DL_WARNING,
3491 "anonymous variadic macros were introduced in C99");
3492 }
3493 else if (CPP_OPTION (pfile, cpp_pedantic)((pfile)->opts.cpp_pedantic)
3494 && CPP_OPTION (pfile, warn_variadic_macros)((pfile)->opts.warn_variadic_macros))
3495 cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS,
3496 CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus)
3497 ? N_("ISO C++ does not permit named variadic macros")"ISO C++ does not permit named variadic macros"
3498 : N_("ISO C does not permit named variadic macros")"ISO C does not permit named variadic macros");
3499 break;
3500 }
3501 }
3502
3503 out:
3504 *n_ptr = nparms;
3505
3506 return ok;
3507}
3508
3509/* Lex a token from the expansion of MACRO, but mark parameters as we
3510 find them and warn of traditional stringification. */
3511static cpp_macro *
3512lex_expansion_token (cpp_reader *pfile, cpp_macro *macro)
3513{
3514 macro = (cpp_macro *)_cpp_reserve_room (pfile,
3515 sizeof (cpp_macro) - sizeof (cpp_token)
3516 + macro->count * sizeof (cpp_token),
3517 sizeof (cpp_token));
3518 cpp_token *saved_cur_token = pfile->cur_token;
3519 pfile->cur_token = &macro->exp.tokens[macro->count];
3520 cpp_token *token = _cpp_lex_direct (pfile);
3521 pfile->cur_token = saved_cur_token;
3522
3523 /* Is this a parameter? */
3524 if (token->type == CPP_NAME && token->val.node.node->type == NT_MACRO_ARG)
3525 {
3526 /* Morph into a parameter reference. */
3527 cpp_hashnode *spelling = token->val.node.spelling;
3528 token->type = CPP_MACRO_ARG;
3529 token->val.macro_arg.arg_no = token->val.node.node->value.arg_index;
3530 token->val.macro_arg.spelling = spelling;
3531 }
3532 else if (CPP_WTRADITIONAL (pfile)((pfile)->opts.cpp_warn_traditional) && macro->paramc > 0
3533 && (token->type == CPP_STRING || token->type == CPP_CHAR))
3534 check_trad_stringification (pfile, macro, &token->val.str);
3535
3536 return macro;
3537}
3538
3539static cpp_macro *
3540create_iso_definition (cpp_reader *pfile)
3541{
3542 bool following_paste_op = false;
3543 const char *paste_op_error_msg =
3544 N_("'##' cannot appear at either end of a macro expansion")"'##' cannot appear at either end of a macro expansion";
3545 unsigned int num_extra_tokens = 0;
3546 unsigned nparms = 0;
3547 cpp_hashnode **params = NULL__null;
3548 bool varadic = false;
3549 bool ok = false;
3550 cpp_macro *macro = NULL__null;
3551
3552 /* Look at the first token, to see if this is a function-like
3553 macro. */
3554 cpp_token first;
3555 cpp_token *saved_cur_token = pfile->cur_token;
3556 pfile->cur_token = &first;
3557 cpp_token *token = _cpp_lex_direct (pfile);
3558 pfile->cur_token = saved_cur_token;
3559
3560 if (token->flags & PREV_WHITE(1 << 0))
3561 /* Preceeded by space, must be part of expansion. */;
3562 else if (token->type == CPP_OPEN_PAREN)
3563 {
3564 /* An open-paren, get a parameter list. */
3565 if (!parse_params (pfile, &nparms, &varadic))
3566 goto out;
3567
3568 params = (cpp_hashnode **)_cpp_commit_buff
3569 (pfile, sizeof (cpp_hashnode *) * nparms);
3570 token = NULL__null;
3571 }
3572 else if (token->type != CPP_EOF
3573 && !(token->type == CPP_COMMENT
3574 && ! CPP_OPTION (pfile, discard_comments_in_macro_exp)((pfile)->opts.discard_comments_in_macro_exp)))
3575 {
3576 /* While ISO C99 requires whitespace before replacement text
3577 in a macro definition, ISO C90 with TC1 allows characters
3578 from the basic source character set there. */
3579 if (CPP_OPTION (pfile, c99)((pfile)->opts.c99))
3580 cpp_error (pfile, CPP_DL_PEDWARN,
3581 CPP_OPTION (pfile, cplusplus)((pfile)->opts.cplusplus)
3582 ? N_("ISO C++11 requires whitespace after the macro name")"ISO C++11 requires whitespace after the macro name"
3583 : N_("ISO C99 requires whitespace after the macro name")"ISO C99 requires whitespace after the macro name");
3584 else
3585 {
3586 enum cpp_diagnostic_level warntype = CPP_DL_WARNING;
3587 switch (token->type)
3588 {
3589 case CPP_ATSIGN:
3590 case CPP_AT_NAME:
3591 case CPP_OBJC_STRING:
3592 /* '@' is not in basic character set. */
3593 warntype = CPP_DL_PEDWARN;
3594 break;
3595 case CPP_OTHER:
3596 /* Basic character set sans letters, digits and _. */
3597 if (strchr ("!\"#%&'()*+,-./:;<=>?[\\]^{|}~",
3598 token->val.str.text[0]) == NULL__null)
3599 warntype = CPP_DL_PEDWARN;
3600 break;
3601 default:
3602 /* All other tokens start with a character from basic
3603 character set. */
3604 break;
3605 }
3606 cpp_error (pfile, warntype,
3607 "missing whitespace after the macro name");
3608 }
3609 }
3610
3611 macro = _cpp_new_macro (pfile, cmk_macro,
3612 _cpp_reserve_room (pfile, 0, sizeof (cpp_macro)));
3613
3614 if (!token)
3615 {
3616 macro->variadic = varadic;
3617 macro->paramc = nparms;
3618 macro->parm.params = params;
3619 macro->fun_like = true;
3620 }
3621 else
3622 {
3623 /* Preserve the token we peeked, there is already a single slot for it. */
3624 macro->exp.tokens[0] = *token;
3625 token = &macro->exp.tokens[0];
3626 macro->count = 1;
3627 }
3628
3629 for (vaopt_state vaopt_tracker (pfile, macro->variadic, NULL__null);; token = NULL__null)
3630 {
3631 if (!token)
3632 {
3633 macro = lex_expansion_token (pfile, macro);
3634 token = &macro->exp.tokens[macro->count++];
3635 }
3636
3637 /* Check the stringifying # constraint 6.10.3.2.1 of
3638 function-like macros when lexing the subsequent token. */
3639 if (macro->count > 1 && token[-1].type == CPP_HASH && macro->fun_like)
3640 {
3641 if (token->type == CPP_MACRO_ARG
3642 || (macro->variadic
3643 && token->type == CPP_NAME
3644 && token->val.node.node == pfile->spec_nodes.n__VA_OPT__))
3645 {
3646 if (token->flags & PREV_WHITE(1 << 0))
3647 token->flags |= SP_PREV_WHITE(1 << 9);
3648 if (token[-1].flags & DIGRAPH(1 << 1))
3649 token->flags |= SP_DIGRAPH(1 << 8);
3650 token->flags &= ~PREV_WHITE(1 << 0);
3651 token->flags |= STRINGIFY_ARG(1 << 2);
3652 token->flags |= token[-1].flags & PREV_WHITE(1 << 0);
3653 token[-1] = token[0];
3654 macro->count--;
3655 }
3656 /* Let assembler get away with murder. */
3657 else if (CPP_OPTION (pfile, lang)((pfile)->opts.lang) != CLK_ASM)
3658 {
3659 cpp_error (pfile, CPP_DL_ERROR,
3660 "'#' is not followed by a macro parameter");
3661 goto out;
3662 }
3663 }
3664
3665 if (token->type == CPP_EOF)
3666 {
3667 /* Paste operator constraint 6.10.3.3.1:
3668 Token-paste ##, can appear in both object-like and
3669 function-like macros, but not at the end. */
3670 if (following_paste_op)
3671 {
3672 cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
3673 goto out;
3674 }
3675 if (!vaopt_tracker.completed ())
3676 goto out;
3677 break;
3678 }
3679
3680 /* Paste operator constraint 6.10.3.3.1. */
3681 if (token->type == CPP_PASTE)
3682 {
3683 /* Token-paste ##, can appear in both object-like and
3684 function-like macros, but not at the beginning. */
3685 if (macro->count == 1)
3686 {
3687 cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
3688 goto out;
3689 }
3690
3691 if (following_paste_op)
3692 {
3693 /* Consecutive paste operators. This one will be moved
3694 to the end. */
3695 num_extra_tokens++;
3696 token->val.token_no = macro->count - 1;
3697 }
3698 else
3699 {
3700 /* Drop the paste operator. */
3701 --macro->count;
3702 token[-1].flags |= PASTE_LEFT(1 << 3);
3703 if (token->flags & DIGRAPH(1 << 1))
3704 token[-1].flags |= SP_DIGRAPH(1 << 8);
3705 if (token->flags & PREV_WHITE(1 << 0))
3706 token[-1].flags |= SP_PREV_WHITE(1 << 9);
3707 }
3708 following_paste_op = true;
3709 }
3710 else
3711 following_paste_op = false;
3712
3713 if (vaopt_tracker.update (token) == vaopt_state::ERROR)
3714 goto out;
3715 }
3716
3717 /* We're committed to winning now. */
3718 ok = true;
3719
3720 /* Don't count the CPP_EOF. */
3721 macro->count--;
3722
3723 macro = (cpp_macro *)_cpp_commit_buff
3724 (pfile, sizeof (cpp_macro) - sizeof (cpp_token)
3725 + sizeof (cpp_token) * macro->count);
3726
3727 /* Clear whitespace on first token. */
3728 if (macro->count)
3729 macro->exp.tokens[0].flags &= ~PREV_WHITE(1 << 0);
3730
3731 if (num_extra_tokens)
3732 {
3733 /* Place second and subsequent ## or %:%: tokens in sequences of
3734 consecutive such tokens at the end of the list to preserve
3735 information about where they appear, how they are spelt and
3736 whether they are preceded by whitespace without otherwise
3737 interfering with macro expansion. Remember, this is
3738 extremely rare, so efficiency is not a priority. */
3739 cpp_token *temp = (cpp_token *)_cpp_reserve_room
3740 (pfile, 0, num_extra_tokens * sizeof (cpp_token));
3741 unsigned extra_ix = 0, norm_ix = 0;
3742 cpp_token *exp = macro->exp.tokens;
3743 for (unsigned ix = 0; ix != macro->count; ix++)
3744 if (exp[ix].type == CPP_PASTE)
3745 temp[extra_ix++] = exp[ix];
3746 else
3747 exp[norm_ix++] = exp[ix];
3748 memcpy (&exp[norm_ix], temp, num_extra_tokens * sizeof (cpp_token));
3749
3750 /* Record there are extra tokens. */
3751 macro->extra_tokens = 1;
3752 }
3753
3754 out:
3755 pfile->state.va_args_ok = 0;
3756 _cpp_unsave_parameters (pfile, nparms);
3757
3758 return ok ? macro : NULL__null;
3759}
3760
3761cpp_macro *
3762_cpp_new_macro (cpp_reader *pfile, cpp_macro_kind kind, void *placement)
3763{
3764 cpp_macro *macro = (cpp_macro *) placement;
3765
3766 /* Zero init all the fields. This'll tell the compiler know all the
3767 following inits are writing a virgin object. */
3768 memset (macro, 0, offsetof (cpp_macro, exp)__builtin_offsetof(cpp_macro, exp));
3769
3770 macro->line = pfile->directive_line;
3771 macro->parm.params = 0;
3772 macro->lazy = 0;
3773 macro->paramc = 0;
3774 macro->variadic = 0;
3775 macro->used = !CPP_OPTION (pfile, warn_unused_macros)((pfile)->opts.warn_unused_macros);
3776 macro->count = 0;
3777 macro->fun_like = 0;
3778 macro->imported_p = false;
3779 macro->extra_tokens = 0;
3780 /* To suppress some diagnostics. */
3781 macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0;
3782
3783 macro->kind = kind;
3784
3785 return macro;
3786}
3787
3788/* Parse a macro and save its expansion. Returns nonzero on success. */
3789bool
3790_cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
3791{
3792 cpp_macro *macro;
3793
3794 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
3795 macro = _cpp_create_trad_definition (pfile);
3796 else
3797 macro = create_iso_definition (pfile);
3798
3799 if (!macro)
3800 return false;
3801
3802 if (cpp_macro_p (node))
3803 {
3804 if (CPP_OPTION (pfile, warn_unused_macros)((pfile)->opts.warn_unused_macros))
3805 _cpp_warn_if_unused_macro (pfile, node, NULL__null);
3806
3807 if (warn_of_redefinition (pfile, node, macro))
3808 {
3809 const enum cpp_warning_reason reason
3810 = (cpp_builtin_macro_p (node) && !(node->flags & NODE_WARN(1 << 3)))
3811 ? CPP_W_BUILTIN_MACRO_REDEFINED : CPP_W_NONE;
3812
3813 bool warned =
3814 cpp_pedwarning_with_line (pfile, reason,
3815 pfile->directive_line, 0,
3816 "\"%s\" redefined", NODE_NAME (node)(((&(node)->ident))->str));
3817
3818 if (warned && cpp_user_macro_p (node))
3819 cpp_error_with_line (pfile, CPP_DL_NOTE,
3820 node->value.macro->line, 0,
3821 "this is the location of the previous definition");
3822 }
3823 _cpp_free_definition (node);
3824 }
3825
3826 /* Enter definition in hash table. */
3827 node->type = NT_USER_MACRO;
3828 node->value.macro = macro;
3829 if (! ustrncmp (NODE_NAME (node)(((&(node)->ident))->str), DSC ("__STDC_")(const unsigned char *)"__STDC_", sizeof "__STDC_" - 1)
3830 && ustrcmp (NODE_NAME (node)(((&(node)->ident))->str), (const uchar *) "__STDC_FORMAT_MACROS")
3831 /* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are mentioned
3832 in the C standard, as something that one must use in C++.
3833 However DR#593 and C++11 indicate that they play no role in C++.
3834 We special-case them anyway. */
3835 && ustrcmp (NODE_NAME (node)(((&(node)->ident))->str), (const uchar *) "__STDC_LIMIT_MACROS")
3836 && ustrcmp (NODE_NAME (node)(((&(node)->ident))->str), (const uchar *) "__STDC_CONSTANT_MACROS"))
3837 node->flags |= NODE_WARN(1 << 3);
3838
3839 /* If user defines one of the conditional macros, remove the
3840 conditional flag */
3841 node->flags &= ~NODE_CONDITIONAL(1 << 6);
3842
3843 return true;
3844}
3845
3846extern void
3847cpp_define_lazily (cpp_reader *pfile, cpp_hashnode *node, unsigned num)
3848{
3849 cpp_macro *macro = node->value.macro;
3850
3851 gcc_checking_assert (pfile->cb.user_lazy_macro && macro && num < UCHAR_MAX)((void)(!(pfile->cb.user_lazy_macro && macro &&
num < (127*2 +1)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3851, __FUNCTION__), 0 : 0))
;
3852
3853 macro->lazy = num + 1;
3854}
3855
3856/* NODE is a deferred macro, resolve it, returning the definition
3857 (which may be NULL). */
3858cpp_macro *
3859cpp_get_deferred_macro (cpp_reader *pfile, cpp_hashnode *node,
3860 location_t loc)
3861{
3862 gcc_checking_assert (node->type == NT_USER_MACRO)((void)(!(node->type == NT_USER_MACRO) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3862, __FUNCTION__), 0 : 0))
;
3863
3864 node->value.macro = pfile->cb.user_deferred_macro (pfile, loc, node);
3865
3866 if (!node->value.macro)
3867 node->type = NT_VOID;
3868
3869 return node->value.macro;
3870}
3871
3872static cpp_macro *
3873get_deferred_or_lazy_macro (cpp_reader *pfile, cpp_hashnode *node,
3874 location_t loc)
3875{
3876 cpp_macro *macro = node->value.macro;
3877 if (!macro)
3878 {
3879 macro = cpp_get_deferred_macro (pfile, node, loc);
3880 gcc_checking_assert (!macro || !macro->lazy)((void)(!(!macro || !macro->lazy) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3880, __FUNCTION__), 0 : 0))
;
3881 }
3882 else if (macro->lazy)
3883 {
3884 pfile->cb.user_lazy_macro (pfile, macro, macro->lazy - 1);
3885 macro->lazy = 0;
3886 }
3887
3888 return macro;
3889}
3890
3891/* Notify the use of NODE in a macro-aware context (i.e. expanding it,
3892 or testing its existance). Also applies any lazy definition.
3893 Return FALSE if the macro isn't really there. */
3894
3895extern bool
3896_cpp_notify_macro_use (cpp_reader *pfile, cpp_hashnode *node,
3897 location_t loc)
3898{
3899 node->flags |= NODE_USED(1 << 5);
3900 switch (node->type)
3901 {
3902 case NT_USER_MACRO:
3903 if (!get_deferred_or_lazy_macro (pfile, node, loc))
3904 return false;
3905 /* FALLTHROUGH. */
3906
3907 case NT_BUILTIN_MACRO:
3908 if (pfile->cb.used_define)
3909 pfile->cb.used_define (pfile, loc, node);
3910 break;
3911
3912 case NT_VOID:
3913 if (pfile->cb.used_undef)
3914 pfile->cb.used_undef (pfile, loc, node);
3915 break;
3916
3917 default:
3918 abort ()fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3918, __FUNCTION__)
;
3919 }
3920
3921 return true;
3922}
3923
3924/* Warn if a token in STRING matches one of a function-like MACRO's
3925 parameters. */
3926static void
3927check_trad_stringification (cpp_reader *pfile, const cpp_macro *macro,
3928 const cpp_string *string)
3929{
3930 unsigned int i, len;
3931 const uchar *p, *q, *limit;
3932
3933 /* Loop over the string. */
3934 limit = string->text + string->len - 1;
3935 for (p = string->text + 1; p < limit; p = q)
3936 {
3937 /* Find the start of an identifier. */
3938 while (p < limit && !is_idstart (*p)((_sch_istable[(*p) & 0xff] & (unsigned short)(_sch_isidst
)) || ((*p) == '$' && ((pfile)->opts.dollars_in_ident
)))
)
3939 p++;
3940
3941 /* Find the end of the identifier. */
3942 q = p;
3943 while (q < limit && is_idchar (*q)((_sch_istable[(*q) & 0xff] & (unsigned short)(_sch_isidnum
)) || ((*q) == '$' && ((pfile)->opts.dollars_in_ident
)))
)
3944 q++;
3945
3946 len = q - p;
3947
3948 /* Loop over the function macro arguments to see if the
3949 identifier inside the string matches one of them. */
3950 for (i = 0; i < macro->paramc; i++)
3951 {
3952 const cpp_hashnode *node = macro->parm.params[i];
3953
3954 if (NODE_LEN (node)(((&(node)->ident))->len) == len
3955 && !memcmp (p, NODE_NAME (node)(((&(node)->ident))->str), len))
3956 {
3957 cpp_warning (pfile, CPP_W_TRADITIONAL,
3958 "macro argument \"%s\" would be stringified in traditional C",
3959 NODE_NAME (node)(((&(node)->ident))->str));
3960 break;
3961 }
3962 }
3963 }
3964}
3965
3966/* Returns the name, arguments and expansion of a macro, in a format
3967 suitable to be read back in again, and therefore also for DWARF 2
3968 debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION".
3969 Caller is expected to generate the "#define" bit if needed. The
3970 returned text is temporary, and automatically freed later. */
3971const unsigned char *
3972cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node)
3973{
3974 gcc_checking_assert (cpp_user_macro_p (node))((void)(!(cpp_user_macro_p (node)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/libcpp/macro.c"
, 3974, __FUNCTION__), 0 : 0))
;
3975
3976 if (const cpp_macro *macro = get_deferred_or_lazy_macro (pfile, node, 0))
3977 return cpp_macro_definition (pfile, node, macro);
3978 return NULL__null;
3979}
3980
3981const unsigned char *
3982cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node,
3983 const cpp_macro *macro)
3984{
3985 unsigned int i, len;
3986 unsigned char *buffer;
3987
3988 /* Calculate length. */
3989 len = NODE_LEN (node)(((&(node)->ident))->len) * 10 + 2; /* ' ' and NUL. */
3990 if (macro->fun_like)
3991 {
3992 len += 4; /* "()" plus possible final ".." of named
3993 varargs (we have + 1 below). */
3994 for (i = 0; i < macro->paramc; i++)
3995 len += NODE_LEN (macro->parm.params[i])(((&(macro->parm.params[i])->ident))->len) + 1; /* "," */
3996 }
3997
3998 /* This should match below where we fill in the buffer. */
3999 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
4000 len += _cpp_replacement_text_len (macro);
4001 else
4002 {
4003 unsigned int count = macro_real_token_count (macro);
4004 for (i = 0; i < count; i++)
4005 {
4006 const cpp_token *token = &macro->exp.tokens[i];
4007
4008 if (token->type == CPP_MACRO_ARG)
4009 len += NODE_LEN (token->val.macro_arg.spelling)(((&(token->val.macro_arg.spelling)->ident))->len
)
;
4010 else
4011 len += cpp_token_len (token);
4012
4013 if (token->flags & STRINGIFY_ARG(1 << 2))
4014 len++; /* "#" */
4015 if (token->flags & PASTE_LEFT(1 << 3))
4016 len += 3; /* " ##" */
4017 if (token->flags & PREV_WHITE(1 << 0))
4018 len++; /* " " */
4019 }
4020 }
4021
4022 if (len > pfile->macro_buffer_len)
4023 {
4024 pfile->macro_buffer = XRESIZEVEC (unsigned char,((unsigned char *) xrealloc ((void *) (pfile->macro_buffer
), sizeof (unsigned char) * (len)))
4025 pfile->macro_buffer, len)((unsigned char *) xrealloc ((void *) (pfile->macro_buffer
), sizeof (unsigned char) * (len)))
;
4026 pfile->macro_buffer_len = len;
4027 }
4028
4029 /* Fill in the buffer. Start with the macro name. */
4030 buffer = pfile->macro_buffer;
4031 buffer = _cpp_spell_ident_ucns (buffer, node);
4032
4033 /* Parameter names. */
4034 if (macro->fun_like)
4035 {
4036 *buffer++ = '(';
4037 for (i = 0; i < macro->paramc; i++)
4038 {
4039 cpp_hashnode *param = macro->parm.params[i];
4040
4041 if (param != pfile->spec_nodes.n__VA_ARGS__)
4042 {
4043 memcpy (buffer, NODE_NAME (param)(((&(param)->ident))->str), NODE_LEN (param)(((&(param)->ident))->len));
4044 buffer += NODE_LEN (param)(((&(param)->ident))->len);
4045 }
4046
4047 if (i + 1 < macro->paramc)
4048 /* Don't emit a space after the comma here; we're trying
4049 to emit a Dwarf-friendly definition, and the Dwarf spec
4050 forbids spaces in the argument list. */
4051 *buffer++ = ',';
4052 else if (macro->variadic)
4053 *buffer++ = '.', *buffer++ = '.', *buffer++ = '.';
4054 }
4055 *buffer++ = ')';
4056 }
4057
4058 /* The Dwarf spec requires a space after the macro name, even if the
4059 definition is the empty string. */
4060 *buffer++ = ' ';
4061
4062 if (CPP_OPTION (pfile, traditional)((pfile)->opts.traditional))
4063 buffer = _cpp_copy_replacement_text (macro, buffer);
4064 else if (macro->count)
4065 /* Expansion tokens. */
4066 {
4067 unsigned int count = macro_real_token_count (macro);
4068 for (i = 0; i < count; i++)
4069 {
4070 const cpp_token *token = &macro->exp.tokens[i];
4071
4072 if (token->flags & PREV_WHITE(1 << 0))
4073 *buffer++ = ' ';
4074 if (token->flags & STRINGIFY_ARG(1 << 2))
4075 *buffer++ = '#';
4076
4077 if (token->type == CPP_MACRO_ARG)
4078 {
4079 memcpy (buffer,
4080 NODE_NAME (token->val.macro_arg.spelling)(((&(token->val.macro_arg.spelling)->ident))->str
)
,
4081 NODE_LEN (token->val.macro_arg.spelling)(((&(token->val.macro_arg.spelling)->ident))->len
)
);
4082 buffer += NODE_LEN (token->val.macro_arg.spelling)(((&(token->val.macro_arg.spelling)->ident))->len
)
;
4083 }
4084 else
4085 buffer = cpp_spell_token (pfile, token, buffer, true);
4086
4087 if (token->flags & PASTE_LEFT(1 << 3))
4088 {
4089 *buffer++ = ' ';
4090 *buffer++ = '#';
4091 *buffer++ = '#';
4092 /* Next has PREV_WHITE; see _cpp_create_definition. */
4093 }
4094 }
4095 }
4096
4097 *buffer = '\0';
4098 return pfile->macro_buffer;
4099}