Branch data Line data Source code
1 : : /* Mainly the interface between cpplib and the C front ends.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : #include "config.h"
21 : : #include "system.h"
22 : : #include "coretypes.h"
23 : : #include "target.h"
24 : : #include "c-common.h"
25 : : #include "timevar.h"
26 : : #include "stringpool.h"
27 : : #include "stor-layout.h"
28 : : #include "c-pragma.h"
29 : : #include "debug.h"
30 : : #include "flags.h"
31 : : #include "file-prefix-map.h" /* remap_macro_filename() */
32 : : #include "langhooks.h"
33 : : #include "attribs.h"
34 : : #include "rich-location.h"
35 : :
36 : : /* We may keep statistics about how long which files took to compile. */
37 : : static int header_time, body_time;
38 : : static splay_tree file_info_tree;
39 : :
40 : : int pending_lang_change; /* If we need to switch languages - C++ only */
41 : : int c_header_level; /* depth in C headers - C++ only */
42 : :
43 : : static tree interpret_integer (const cpp_token *, unsigned int,
44 : : enum overflow_type *);
45 : : static tree interpret_float (const cpp_token *, unsigned int, const char *,
46 : : enum overflow_type *);
47 : : static tree interpret_fixed (const cpp_token *, unsigned int);
48 : : static enum integer_type_kind narrowest_unsigned_type
49 : : (const widest_int &, unsigned int);
50 : : static enum integer_type_kind narrowest_signed_type
51 : : (const widest_int &, unsigned int);
52 : : static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool);
53 : : static tree lex_charconst (const cpp_token *);
54 : : static void update_header_times (const char *);
55 : : static int dump_one_header (splay_tree_node, void *);
56 : : static void cb_line_change (cpp_reader *, const cpp_token *, int);
57 : : static void cb_ident (cpp_reader *, location_t, const cpp_string *);
58 : : static void cb_def_pragma (cpp_reader *, location_t);
59 : : static void cb_define (cpp_reader *, location_t, cpp_hashnode *);
60 : : static void cb_undef (cpp_reader *, location_t, cpp_hashnode *);
61 : :
62 : : void
63 : 198451 : init_c_lex (void)
64 : : {
65 : 198451 : struct c_fileinfo *toplevel;
66 : :
67 : : /* The get_fileinfo data structure must be initialized before
68 : : cpp_read_main_file is called. */
69 : 198451 : toplevel = get_fileinfo ("<top level>");
70 : 198451 : if (flag_detailed_statistics)
71 : : {
72 : 0 : header_time = 0;
73 : 0 : body_time = get_run_time ();
74 : 0 : toplevel->time = body_time;
75 : : }
76 : :
77 : 198451 : struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
78 : :
79 : 198451 : cb->line_change = cb_line_change;
80 : 198451 : cb->ident = cb_ident;
81 : 198451 : cb->def_pragma = cb_def_pragma;
82 : 198451 : cb->valid_pch = c_common_valid_pch;
83 : 198451 : cb->read_pch = c_common_read_pch;
84 : 198451 : cb->has_attribute = c_common_has_attribute;
85 : 198451 : cb->has_builtin = c_common_has_builtin;
86 : 198451 : cb->has_feature = c_common_has_feature;
87 : 198451 : cb->get_source_date_epoch = cb_get_source_date_epoch;
88 : 198451 : cb->get_suggestion = cb_get_suggestion;
89 : 198451 : cb->remap_filename = remap_macro_filename;
90 : :
91 : : /* Set the debug callbacks if we can use them. */
92 : 198451 : if ((debug_info_level == DINFO_LEVEL_VERBOSE
93 : 516 : && dwarf_debuginfo_p ())
94 : 198451 : || flag_dump_go_spec != NULL)
95 : : {
96 : 520 : cb->define = cb_define;
97 : 520 : cb->undef = cb_undef;
98 : : }
99 : 198451 : }
100 : :
101 : : struct c_fileinfo *
102 : 263277356 : get_fileinfo (const char *name)
103 : : {
104 : 263277356 : splay_tree_node n;
105 : 263277356 : struct c_fileinfo *fi;
106 : :
107 : 263277356 : if (!file_info_tree)
108 : 199690 : file_info_tree = splay_tree_new (splay_tree_compare_strings,
109 : : 0,
110 : : splay_tree_delete_pointers);
111 : :
112 : 263277356 : n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
113 : 263277356 : if (n)
114 : 259836542 : return (struct c_fileinfo *) n->value;
115 : :
116 : 3440814 : fi = XNEW (struct c_fileinfo);
117 : 3440814 : fi->time = 0;
118 : 3440814 : fi->interface_only = 0;
119 : 3440814 : fi->interface_unknown = 1;
120 : 3440814 : splay_tree_insert (file_info_tree, (splay_tree_key) name,
121 : : (splay_tree_value) fi);
122 : 3440814 : return fi;
123 : : }
124 : :
125 : : static void
126 : 18572320 : update_header_times (const char *name)
127 : : {
128 : : /* Changing files again. This means currently collected time
129 : : is charged against header time, and body time starts back at 0. */
130 : 18572320 : if (flag_detailed_statistics)
131 : : {
132 : 0 : int this_time = get_run_time ();
133 : 0 : struct c_fileinfo *file = get_fileinfo (name);
134 : 0 : header_time += this_time - body_time;
135 : 0 : file->time += this_time - body_time;
136 : 0 : body_time = this_time;
137 : : }
138 : 18572320 : }
139 : :
140 : : static int
141 : 0 : dump_one_header (splay_tree_node n, void * ARG_UNUSED (dummy))
142 : : {
143 : 0 : print_time ((const char *) n->key,
144 : 0 : ((struct c_fileinfo *) n->value)->time);
145 : 0 : return 0;
146 : : }
147 : :
148 : : void
149 : 0 : dump_time_statistics (void)
150 : : {
151 : 0 : struct c_fileinfo *file = get_fileinfo (LOCATION_FILE (input_location));
152 : 0 : int this_time = get_run_time ();
153 : 0 : file->time += this_time - body_time;
154 : :
155 : 0 : fprintf (stderr, "\n******\n");
156 : 0 : print_time ("header files (total)", header_time);
157 : 0 : print_time ("main file (total)", this_time - body_time);
158 : 0 : fprintf (stderr, "ratio = %g : 1\n",
159 : 0 : (double) header_time / (double) (this_time - body_time));
160 : 0 : fprintf (stderr, "\n******\n");
161 : :
162 : 0 : splay_tree_foreach (file_info_tree, dump_one_header, 0);
163 : 0 : }
164 : :
165 : : static void
166 : 22 : cb_ident (cpp_reader * ARG_UNUSED (pfile),
167 : : location_t ARG_UNUSED (line),
168 : : const cpp_string * ARG_UNUSED (str))
169 : : {
170 : 22 : if (!flag_no_ident)
171 : : {
172 : : /* Convert escapes in the string. */
173 : 22 : cpp_string cstr = { 0, 0 };
174 : 22 : if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING))
175 : : {
176 : 22 : targetm.asm_out.output_ident ((const char *) cstr.text);
177 : 22 : free (CONST_CAST (unsigned char *, cstr.text));
178 : : }
179 : : }
180 : 22 : }
181 : :
182 : : /* Called at the start of every non-empty line. TOKEN is the first
183 : : lexed token on the line. Used for diagnostic line numbers. */
184 : : static void
185 : 1427020172 : cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
186 : : int parsing_args)
187 : : {
188 : 1427020172 : if (token->type != CPP_EOF && !parsing_args)
189 : 1420133298 : input_location = token->src_loc;
190 : 1427020172 : }
191 : :
192 : : void
193 : 18770389 : fe_file_change (const line_map_ordinary *new_map)
194 : : {
195 : 18770389 : if (new_map == NULL)
196 : : return;
197 : :
198 : 18572320 : if (new_map->reason == LC_ENTER)
199 : : {
200 : : /* Don't stack the main buffer on the input stack;
201 : : we already did in compile_file. */
202 : 9059184 : if (!MAIN_FILE_P (new_map))
203 : : {
204 : 8860733 : location_t included_at = linemap_included_from (new_map);
205 : 8860733 : int line = 0;
206 : 8860733 : if (included_at > BUILTINS_LOCATION)
207 : 8860733 : line = SOURCE_LINE (new_map - 1, included_at);
208 : :
209 : 8860733 : input_location = new_map->start_location;
210 : 8860733 : (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
211 : : #ifdef SYSTEM_IMPLICIT_EXTERN_C
212 : : if (c_header_level)
213 : : ++c_header_level;
214 : : else if (LINEMAP_SYSP (new_map) == 2)
215 : : {
216 : : c_header_level = 1;
217 : : ++pending_lang_change;
218 : : }
219 : : #endif
220 : : }
221 : : }
222 : 9513136 : else if (new_map->reason == LC_LEAVE)
223 : : {
224 : : #ifdef SYSTEM_IMPLICIT_EXTERN_C
225 : : if (c_header_level && --c_header_level == 0)
226 : : {
227 : : if (LINEMAP_SYSP (new_map) == 2)
228 : : warning (0, "badly nested C headers from preprocessor");
229 : : --pending_lang_change;
230 : : }
231 : : #endif
232 : 8860730 : input_location = new_map->start_location;
233 : :
234 : 8860730 : (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
235 : : }
236 : :
237 : 18572320 : update_header_times (LINEMAP_FILE (new_map));
238 : 18572320 : input_location = new_map->start_location;
239 : : }
240 : :
241 : : static void
242 : 1811 : cb_def_pragma (cpp_reader *pfile, location_t loc)
243 : : {
244 : : /* Issue a warning message if we have been asked to do so. Ignore
245 : : unknown pragmas in system headers unless an explicit
246 : : -Wunknown-pragmas has been given. */
247 : 1811 : if (warn_unknown_pragmas > in_system_header_at (input_location))
248 : : {
249 : 57 : const unsigned char *space, *name;
250 : 57 : const cpp_token *s;
251 : 57 : location_t fe_loc = loc;
252 : :
253 : 57 : space = name = (const unsigned char *) "";
254 : :
255 : : /* N.B. It's fine to call cpp_get_token () directly here (rather than our
256 : : local wrapper get_token ()), because this callback is not used with
257 : : flag_preprocess_only==true. */
258 : 57 : s = cpp_get_token (pfile);
259 : 57 : if (s->type != CPP_EOF)
260 : : {
261 : 56 : space = cpp_token_as_text (pfile, s);
262 : 56 : s = cpp_get_token (pfile);
263 : 56 : if (s->type == CPP_NAME)
264 : 37 : name = cpp_token_as_text (pfile, s);
265 : : }
266 : :
267 : 57 : warning_at (fe_loc, OPT_Wunknown_pragmas, "ignoring %<#pragma %s %s%>",
268 : : space, name);
269 : : }
270 : 1811 : }
271 : :
272 : : /* #define callback for DWARF and DWARF2 debug info. */
273 : : static void
274 : 249442 : cb_define (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
275 : : {
276 : 249442 : const struct line_map *map = linemap_lookup (line_table, loc);
277 : 249442 : (*debug_hooks->define) (SOURCE_LINE (linemap_check_ordinary (map), loc),
278 : 249442 : (const char *) cpp_macro_definition (pfile, node));
279 : 249442 : }
280 : :
281 : : /* #undef callback for DWARF and DWARF2 debug info. */
282 : : static void
283 : 1292 : cb_undef (cpp_reader *pfile, location_t loc, cpp_hashnode *node)
284 : : {
285 : 1292 : if (lang_hooks.preprocess_undef)
286 : 0 : lang_hooks.preprocess_undef (pfile, loc, node);
287 : :
288 : 1292 : const struct line_map *map = linemap_lookup (line_table, loc);
289 : 1292 : (*debug_hooks->undef) (SOURCE_LINE (linemap_check_ordinary (map), loc),
290 : 1292 : (const char *) NODE_NAME (node));
291 : 1292 : }
292 : :
293 : : /* Wrapper around cpp_get_token_with_location to stream the token to the
294 : : preprocessor so it can output it. This is necessary with
295 : : flag_preprocess_only if we are obtaining tokens here instead of from the loop
296 : : in c-ppoutput.cc, such as while processing a #pragma. */
297 : :
298 : : static const cpp_token *
299 : 11063180261 : get_token (cpp_reader *pfile, location_t *loc = nullptr)
300 : : {
301 : 11063180261 : if (flag_preprocess_only)
302 : : {
303 : 63557 : location_t x;
304 : 63557 : if (!loc)
305 : 0 : loc = &x;
306 : 63557 : const auto tok = cpp_get_token_with_location (pfile, loc);
307 : 63557 : c_pp_stream_token (pfile, tok, *loc);
308 : 63557 : return tok;
309 : : }
310 : : else
311 : 11063116704 : return cpp_get_token_with_location (pfile, loc);
312 : : }
313 : :
314 : : /* Wrapper around cpp_get_token to skip CPP_PADDING tokens
315 : : and not consume CPP_EOF. This does not perform the optional
316 : : streaming in preprocess_only mode, so is suitable to be used
317 : : when processing builtin expansions such as c_common_has_attribute. */
318 : :
319 : : static const cpp_token *
320 : 19966316 : get_token_no_padding (cpp_reader *pfile)
321 : : {
322 : 19966612 : for (;;)
323 : : {
324 : 19966612 : const cpp_token *ret = cpp_peek_token (pfile, 0);
325 : 19966612 : if (ret->type == CPP_EOF)
326 : : return ret;
327 : 19966592 : ret = cpp_get_token (pfile);
328 : 19966592 : if (ret->type != CPP_PADDING)
329 : : return ret;
330 : : }
331 : : }
332 : :
333 : : /* Callback for has_attribute. */
334 : : int
335 : 766055 : c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
336 : : {
337 : 766055 : int result = 0;
338 : 766055 : tree attr_name = NULL_TREE;
339 : 766055 : const cpp_token *token;
340 : :
341 : 766055 : token = get_token_no_padding (pfile);
342 : 766055 : if (token->type != CPP_OPEN_PAREN)
343 : : {
344 : 2 : cpp_error (pfile, CPP_DL_ERROR,
345 : : "missing %<(%> after %<__has_attribute%>");
346 : 2 : return 0;
347 : : }
348 : 766053 : token = get_token_no_padding (pfile);
349 : 766053 : if (token->type == CPP_NAME)
350 : : {
351 : 766049 : attr_name = get_identifier ((const char *)
352 : : cpp_token_as_text (pfile, token));
353 : 766049 : attr_name = canonicalize_attr_name (attr_name);
354 : 766049 : bool have_scope = false;
355 : 766049 : int idx = 0;
356 : 766109 : const cpp_token *nxt_token;
357 : 766109 : do
358 : 766109 : nxt_token = cpp_peek_token (pfile, idx++);
359 : 766109 : while (nxt_token->type == CPP_PADDING);
360 : 766049 : if (!c_dialect_cxx ()
361 : 389685 : && nxt_token->type == CPP_COLON
362 : 2 : && (nxt_token->flags & COLON_SCOPE) != 0)
363 : : {
364 : : const cpp_token *prev_token = nxt_token;
365 : 2 : do
366 : 2 : nxt_token = cpp_peek_token (pfile, idx++);
367 : 2 : while (nxt_token->type == CPP_PADDING);
368 : 2 : if (nxt_token->type == CPP_COLON)
369 : : {
370 : : /* __has_attribute (vendor::attr) in -std=c17 etc. modes.
371 : : :: isn't CPP_SCOPE but 2 CPP_COLON tokens, where the
372 : : first one should have COLON_SCOPE flag to distinguish
373 : : it from : :. */
374 : 2 : have_scope = true;
375 : 2 : get_token_no_padding (pfile); // Eat first colon.
376 : : }
377 : : else
378 : : nxt_token = prev_token;
379 : : }
380 : 766049 : if (nxt_token->type == CPP_SCOPE || have_scope)
381 : : {
382 : 800 : have_scope = true;
383 : 800 : get_token_no_padding (pfile); // Eat scope.
384 : 800 : nxt_token = get_token_no_padding (pfile);
385 : 800 : if (nxt_token->type == CPP_NAME)
386 : : {
387 : 799 : tree attr_ns = attr_name;
388 : 799 : tree attr_id
389 : 799 : = get_identifier ((const char *)
390 : : cpp_token_as_text (pfile, nxt_token));
391 : 799 : attr_id = canonicalize_attr_name (attr_id);
392 : : /* OpenMP attributes need special handling. */
393 : 703 : if ((flag_openmp || flag_openmp_simd)
394 : 192 : && is_attribute_p ("omp", attr_ns)
395 : 991 : && (is_attribute_p ("directive", attr_id)
396 : 144 : || is_attribute_p ("sequence", attr_id)
397 : 96 : || is_attribute_p ("decl", attr_id)))
398 : : result = 1;
399 : 655 : if (result)
400 : : attr_name = NULL_TREE;
401 : : else
402 : 655 : attr_name = build_tree_list (attr_ns, attr_id);
403 : : }
404 : : else
405 : : {
406 : 1 : cpp_error (pfile, CPP_DL_ERROR,
407 : : "attribute identifier required after scope");
408 : 1 : attr_name = NULL_TREE;
409 : : }
410 : : }
411 : : else
412 : : {
413 : : /* Some standard attributes need special handling. */
414 : 765249 : if (c_dialect_cxx ())
415 : : {
416 : 375643 : if (is_attribute_p ("noreturn", attr_name))
417 : : result = 200809;
418 : 375594 : else if (is_attribute_p ("deprecated", attr_name))
419 : : result = 201309;
420 : 354868 : else if (is_attribute_p ("maybe_unused", attr_name)
421 : 354868 : || is_attribute_p ("fallthrough", attr_name))
422 : : result = 201603;
423 : 354403 : else if (is_attribute_p ("no_unique_address", attr_name)
424 : 342685 : || is_attribute_p ("likely", attr_name)
425 : 697082 : || is_attribute_p ("unlikely", attr_name))
426 : : result = 201803;
427 : 342673 : else if (is_attribute_p ("nodiscard", attr_name))
428 : : result = 201907;
429 : 342664 : else if (is_attribute_p ("assume", attr_name))
430 : : result = 202207;
431 : 332336 : else if (is_attribute_p ("init_priority", attr_name))
432 : : {
433 : : /* The (non-standard) init_priority attribute is always
434 : : included in the attribute table, but we don't want to
435 : : advertise the attribute unless the target actually
436 : : supports init priorities. */
437 : : result = SUPPORTS_INIT_PRIORITY ? 1 : 0;
438 : : attr_name = NULL_TREE;
439 : : }
440 : : }
441 : : else
442 : : {
443 : 389606 : if (is_attribute_p ("deprecated", attr_name)
444 : 365271 : || is_attribute_p ("fallthrough", attr_name)
445 : 365117 : || is_attribute_p ("maybe_unused", attr_name)
446 : 365115 : || is_attribute_p ("nodiscard", attr_name)
447 : 365113 : || is_attribute_p ("noreturn", attr_name)
448 : 365099 : || is_attribute_p ("_Noreturn", attr_name)
449 : 365097 : || is_attribute_p ("reproducible", attr_name)
450 : 754701 : || is_attribute_p ("unsequenced", attr_name))
451 : : result = 202311;
452 : : }
453 : : if (result)
454 : : attr_name = NULL_TREE;
455 : : }
456 : 688046 : if (attr_name && (have_scope || !std_syntax))
457 : : {
458 : 688041 : init_attributes ();
459 : 688041 : const struct attribute_spec *attr = lookup_attribute_spec (attr_name);
460 : 688041 : if (attr)
461 : 697592 : result = 1;
462 : : }
463 : : }
464 : : else
465 : : {
466 : 4 : cpp_error (pfile, CPP_DL_ERROR,
467 : : "macro %<__has_attribute%> requires an identifier");
468 : 4 : return 0;
469 : : }
470 : :
471 : 766049 : if (get_token_no_padding (pfile)->type != CPP_CLOSE_PAREN)
472 : 3 : cpp_error (pfile, CPP_DL_ERROR,
473 : : "missing %<)%> after %<__has_attribute%>");
474 : :
475 : : return result;
476 : : }
477 : :
478 : : /* Helper for __has_{builtin,feature,extension}. */
479 : :
480 : : static const char *
481 : 5888831 : c_common_lex_availability_macro (cpp_reader *pfile, const char *builtin)
482 : : {
483 : 5888831 : const cpp_token *token = get_token_no_padding (pfile);
484 : 5888831 : if (token->type != CPP_OPEN_PAREN)
485 : : {
486 : 4 : cpp_error (pfile, CPP_DL_ERROR,
487 : : "missing %<(%> after %<__has_%s%>", builtin);
488 : 4 : return 0;
489 : : }
490 : :
491 : 5888827 : const char *name = "";
492 : 5888827 : token = get_token_no_padding (pfile);
493 : 5888827 : if (token->type == CPP_NAME)
494 : : {
495 : 5888795 : name = (const char *) cpp_token_as_text (pfile, token);
496 : 5888795 : token = get_token_no_padding (pfile);
497 : 5888795 : if (token->type != CPP_CLOSE_PAREN)
498 : : {
499 : 16 : cpp_error (pfile, CPP_DL_ERROR,
500 : : "expected %<)%> after %qs", name);
501 : 16 : name = "";
502 : : }
503 : : }
504 : : else
505 : : {
506 : 32 : cpp_error (pfile, CPP_DL_ERROR,
507 : : "macro %<__has_%s%> requires an identifier", builtin);
508 : 32 : if (token->type == CPP_CLOSE_PAREN)
509 : : return 0;
510 : : }
511 : :
512 : : /* Consume tokens up to the closing parenthesis, including any nested
513 : : pairs of parentheses, to avoid confusing redundant errors. */
514 : 5888927 : for (unsigned nparen = 1; ; token = get_token_no_padding (pfile))
515 : : {
516 : 5888927 : if (token->type == CPP_OPEN_PAREN)
517 : 24 : ++nparen;
518 : 5888903 : else if (token->type == CPP_CLOSE_PAREN)
519 : 5888827 : --nparen;
520 : 76 : else if (token->type == CPP_EOF)
521 : : break;
522 : 5888915 : if (!nparen)
523 : : break;
524 : : }
525 : :
526 : : return name;
527 : : }
528 : :
529 : : /* Callback for has_builtin. */
530 : :
531 : : int
532 : 5767123 : c_common_has_builtin (cpp_reader *pfile)
533 : : {
534 : 5767123 : const char *name = c_common_lex_availability_macro (pfile, "builtin");
535 : 5767123 : if (!name)
536 : : return 0;
537 : :
538 : 5767115 : return names_builtin_p (name);
539 : : }
540 : :
541 : : /* Callback for has_feature. STRICT_P is true for has_feature and false
542 : : for has_extension. */
543 : :
544 : : int
545 : 121708 : c_common_has_feature (cpp_reader *pfile, bool strict_p)
546 : : {
547 : 121708 : const char *builtin = strict_p ? "feature" : "extension";
548 : 121708 : const char *name = c_common_lex_availability_macro (pfile, builtin);
549 : 121708 : if (!name)
550 : : return 0;
551 : :
552 : : /* If -pedantic-errors is given, __has_extension is equivalent to
553 : : __has_feature. */
554 : 121708 : strict_p |= flag_pedantic_errors;
555 : 121708 : return has_feature_p (name, strict_p);
556 : : }
557 : :
558 : :
559 : : /* Read a token and return its type. Fill *VALUE with its value, if
560 : : applicable. Fill *CPP_FLAGS with the token's flags, if it is
561 : : non-NULL. */
562 : :
563 : : enum cpp_ttype
564 : 10002487837 : c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
565 : : int lex_flags)
566 : : {
567 : 10002487837 : const cpp_token *tok;
568 : 10002487837 : enum cpp_ttype type;
569 : 10002487837 : unsigned char add_flags = 0;
570 : 10002487837 : enum overflow_type overflow = OT_NONE;
571 : :
572 : 10002487837 : timevar_push (TV_CPP);
573 : 11063180075 : retry:
574 : 11063180075 : tok = get_token (parse_in, loc);
575 : 11063179894 : type = tok->type;
576 : :
577 : 11063180038 : retry_after_at:
578 : 11063180038 : switch (type)
579 : : {
580 : 1060691901 : case CPP_PADDING:
581 : 1060691901 : goto retry;
582 : :
583 : 4616499203 : case CPP_NAME:
584 : 4616499203 : *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
585 : 4616499203 : break;
586 : :
587 : 140350564 : case CPP_NUMBER:
588 : 140350564 : {
589 : 140350564 : const char *suffix = NULL;
590 : 140350564 : unsigned int flags = cpp_classify_number (parse_in, tok, &suffix, *loc);
591 : :
592 : 140350564 : switch (flags & CPP_N_CATEGORY)
593 : : {
594 : 174 : case CPP_N_INVALID:
595 : : /* cpplib has issued an error. */
596 : 174 : *value = error_mark_node;
597 : 174 : break;
598 : :
599 : 135797214 : case CPP_N_INTEGER:
600 : : /* C++ uses '0' to mark virtual functions as pure.
601 : : Set PURE_ZERO to pass this information to the C++ parser. */
602 : 135797214 : if (tok->val.str.len == 1 && *tok->val.str.text == '0')
603 : : add_flags = PURE_ZERO | DECIMAL_INT;
604 : 103863505 : else if ((flags & CPP_N_INTEGER) && (flags & CPP_N_DECIMAL))
605 : : /* -Wxor-used-as-pow is only active for LHS of ^ expressed
606 : : as a decimal integer. */
607 : 89596959 : add_flags = DECIMAL_INT;
608 : 135797214 : *value = interpret_integer (tok, flags, &overflow);
609 : 135797214 : break;
610 : :
611 : 4553176 : case CPP_N_FLOATING:
612 : 4553176 : *value = interpret_float (tok, flags, suffix, &overflow);
613 : 4553176 : break;
614 : :
615 : 0 : default:
616 : 0 : gcc_unreachable ();
617 : : }
618 : :
619 : 140350564 : if (flags & CPP_N_USERDEF)
620 : : {
621 : 90118 : char *str;
622 : 90118 : tree literal;
623 : 90118 : tree suffix_id = get_identifier (suffix);
624 : 90118 : int len = tok->val.str.len - strlen (suffix);
625 : : /* If this is going to be used as a C string to pass to a
626 : : raw literal operator, we need to add a trailing NUL. */
627 : 180236 : tree num_string = build_string (len + 1,
628 : 90118 : (const char *) tok->val.str.text);
629 : 90118 : TREE_TYPE (num_string) = char_array_type_node;
630 : 90118 : num_string = fix_string_type (num_string);
631 : 90118 : str = CONST_CAST (char *, TREE_STRING_POINTER (num_string));
632 : 90118 : str[len] = '\0';
633 : 90118 : literal = build_userdef_literal (suffix_id, *value, overflow,
634 : : num_string);
635 : 90118 : *value = literal;
636 : : }
637 : : }
638 : 140350564 : break;
639 : :
640 : 3 : case CPP_ATSIGN:
641 : : /* An @ may give the next token special significance in Objective-C. */
642 : 3 : if (c_dialect_objc ())
643 : : {
644 : 0 : location_t atloc = *loc;
645 : 0 : location_t newloc;
646 : :
647 : 0 : retry_at:
648 : 0 : tok = get_token (parse_in, &newloc);
649 : 0 : type = tok->type;
650 : 0 : switch (type)
651 : : {
652 : 0 : case CPP_PADDING:
653 : 0 : goto retry_at;
654 : :
655 : 0 : case CPP_STRING:
656 : 0 : case CPP_WSTRING:
657 : 0 : case CPP_STRING16:
658 : 0 : case CPP_STRING32:
659 : 0 : case CPP_UTF8STRING:
660 : 0 : type = lex_string (tok, value, true, true);
661 : 0 : break;
662 : :
663 : 0 : case CPP_NAME:
664 : 0 : *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
665 : 0 : if (OBJC_IS_AT_KEYWORD (C_RID_CODE (*value))
666 : : || OBJC_IS_CXX_KEYWORD (C_RID_CODE (*value)))
667 : : {
668 : 0 : type = CPP_AT_NAME;
669 : : /* Note the complication: if we found an OBJC_CXX
670 : : keyword, for example, 'class', we will be
671 : : returning a token of type CPP_AT_NAME and rid
672 : : code RID_CLASS (not RID_AT_CLASS). The language
673 : : parser needs to convert that to RID_AT_CLASS.
674 : : However, we've now spliced the '@' together with the
675 : : keyword that follows; Adjust the location so that we
676 : : get a source range covering the composite.
677 : : */
678 : 0 : *loc = make_location (atloc, atloc, newloc);
679 : 0 : break;
680 : : }
681 : : /* FALLTHROUGH */
682 : :
683 : 0 : default:
684 : : /* ... or not. */
685 : 0 : error_at (atloc, "stray %<@%> in program");
686 : 0 : *loc = newloc;
687 : 0 : goto retry_after_at;
688 : : }
689 : 0 : break;
690 : : }
691 : :
692 : : /* FALLTHROUGH */
693 : 23 : case CPP_HASH:
694 : 23 : case CPP_PASTE:
695 : 23 : {
696 : 23 : unsigned char name[8];
697 : :
698 : 23 : *cpp_spell_token (parse_in, tok, name, true) = 0;
699 : :
700 : 23 : error_at (*loc, "stray %qs in program", name);
701 : : }
702 : :
703 : 23 : goto retry;
704 : :
705 : 130 : case CPP_OTHER:
706 : 130 : {
707 : 130 : cppchar_t c = tok->val.str.text[0];
708 : :
709 : 130 : if (c == '"' || c == '\'')
710 : 25 : error_at (*loc, "missing terminating %c character", (int) c);
711 : 105 : else if (ISGRAPH (c))
712 : 97 : error_at (*loc, "stray %qc in program", (int) c);
713 : : else
714 : : {
715 : 8 : rich_location rich_loc (line_table, *loc);
716 : 8 : rich_loc.set_escape_on_output (true);
717 : 8 : error_at (&rich_loc, "stray %<\\%o%> in program", (int) c);
718 : 8 : }
719 : : }
720 : 130 : goto retry;
721 : :
722 : 110 : case CPP_CHAR_USERDEF:
723 : 110 : case CPP_WCHAR_USERDEF:
724 : 110 : case CPP_CHAR16_USERDEF:
725 : 110 : case CPP_CHAR32_USERDEF:
726 : 110 : case CPP_UTF8CHAR_USERDEF:
727 : 110 : {
728 : 110 : tree literal;
729 : 110 : cpp_token temp_tok = *tok;
730 : 110 : const char *suffix = cpp_get_userdef_suffix (tok);
731 : 110 : temp_tok.val.str.len -= strlen (suffix);
732 : 110 : temp_tok.type = cpp_userdef_char_remove_type (type);
733 : 110 : literal = build_userdef_literal (get_identifier (suffix),
734 : : lex_charconst (&temp_tok),
735 : : OT_NONE, NULL_TREE);
736 : 110 : *value = literal;
737 : : }
738 : 110 : break;
739 : :
740 : 5817287 : case CPP_CHAR:
741 : 5817287 : case CPP_WCHAR:
742 : 5817287 : case CPP_CHAR16:
743 : 5817287 : case CPP_CHAR32:
744 : 5817287 : case CPP_UTF8CHAR:
745 : 5817287 : *value = lex_charconst (tok);
746 : 5817287 : break;
747 : :
748 : 273032 : case CPP_STRING_USERDEF:
749 : 273032 : case CPP_WSTRING_USERDEF:
750 : 273032 : case CPP_STRING16_USERDEF:
751 : 273032 : case CPP_STRING32_USERDEF:
752 : 273032 : case CPP_UTF8STRING_USERDEF:
753 : 273032 : {
754 : 273032 : tree literal, string;
755 : 273032 : const char *suffix = cpp_get_userdef_suffix (tok);
756 : 546064 : string = build_string (tok->val.str.len - strlen (suffix),
757 : 273032 : (const char *) tok->val.str.text);
758 : 273032 : literal = build_userdef_literal (get_identifier (suffix),
759 : : string, OT_NONE, NULL_TREE);
760 : 273032 : *value = literal;
761 : : }
762 : 273032 : break;
763 : :
764 : 50377729 : case CPP_STRING:
765 : 50377729 : case CPP_WSTRING:
766 : 50377729 : case CPP_STRING16:
767 : 50377729 : case CPP_STRING32:
768 : 50377729 : case CPP_UTF8STRING:
769 : 50377729 : if ((lex_flags & C_LEX_STRING_NO_JOIN) == 0)
770 : : {
771 : 18 : type = lex_string (tok, value, false,
772 : : (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
773 : 18 : break;
774 : : }
775 : 50377711 : *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
776 : 50377711 : break;
777 : :
778 : 7343814 : case CPP_PRAGMA:
779 : 7343814 : *value = build_int_cst (integer_type_node, tok->val.pragma);
780 : 7343814 : break;
781 : :
782 : 815 : case CPP_HEADER_NAME:
783 : 815 : *value = build_string (tok->val.str.len, (const char *)tok->val.str.text);
784 : 815 : break;
785 : :
786 : 358 : case CPP_EMBED:
787 : 358 : *value = make_node (RAW_DATA_CST);
788 : 358 : TREE_TYPE (*value) = integer_type_node;
789 : 358 : RAW_DATA_LENGTH (*value) = tok->val.str.len;
790 : 358 : if (pch_file)
791 : : {
792 : : /* When writing PCH headers, copy the data over, such that
793 : : the owner is a STRING_CST. */
794 : 6 : int off = 0;
795 : 6 : if (tok->val.str.len <= INT_MAX - 2)
796 : : /* See below. */
797 : 6 : off = 1;
798 : 12 : tree owner = build_string (tok->val.str.len + 2 * off,
799 : 6 : (const char *) tok->val.str.text - off);
800 : 6 : TREE_TYPE (owner) = build_array_type_nelts (unsigned_char_type_node,
801 : 6 : tok->val.str.len);
802 : 6 : RAW_DATA_OWNER (*value) = owner;
803 : 6 : RAW_DATA_POINTER (*value) = TREE_STRING_POINTER (owner) + off;
804 : : }
805 : : else
806 : : {
807 : : /* Otherwise add another dummy RAW_DATA_CST as owner which
808 : : indicates the data is owned by libcpp. */
809 : 352 : RAW_DATA_POINTER (*value) = (const char *) tok->val.str.text;
810 : 352 : tree owner = make_node (RAW_DATA_CST);
811 : 352 : TREE_TYPE (owner) = integer_type_node;
812 : 352 : RAW_DATA_LENGTH (owner) = tok->val.str.len;
813 : 352 : RAW_DATA_POINTER (owner) = (const char *) tok->val.str.text;
814 : 352 : if (tok->val.str.len <= INT_MAX - 2)
815 : : {
816 : : /* The preprocessor surrounds at least smaller CPP_EMBEDs
817 : : in between CPP_NUMBER CPP_COMMA before and
818 : : CPP_COMMA CPP_NUMBER after, so the actual libcpp buffer
819 : : holds those 2 extra bytes around it. Don't do that if
820 : : CPP_EMBED is at the maximum ~ 2GB size. */
821 : 352 : RAW_DATA_LENGTH (owner) += 2;
822 : 352 : RAW_DATA_POINTER (owner)--;
823 : : }
824 : 352 : RAW_DATA_OWNER (*value) = owner;
825 : : }
826 : : break;
827 : :
828 : : /* This token should not be visible outside cpplib. */
829 : 0 : case CPP_MACRO_ARG:
830 : 0 : gcc_unreachable ();
831 : :
832 : : /* CPP_COMMENT will appear when compiling with -C. Ignore, except
833 : : when it is a FALLTHROUGH comment, in that case set
834 : : PREV_FALLTHROUGH flag on the next non-comment token. */
835 : 328 : case CPP_COMMENT:
836 : 328 : if (tok->flags & PREV_FALLTHROUGH)
837 : : {
838 : 168 : do
839 : : {
840 : 168 : tok = get_token (parse_in, loc);
841 : 168 : type = tok->type;
842 : : }
843 : 168 : while (type == CPP_PADDING || type == CPP_COMMENT);
844 : 144 : add_flags |= PREV_FALLTHROUGH;
845 : 144 : goto retry_after_at;
846 : : }
847 : 184 : goto retry;
848 : :
849 : 5181824744 : default:
850 : 5181824744 : *value = NULL_TREE;
851 : 5181824744 : break;
852 : : }
853 : :
854 : 10002487656 : if (cpp_flags)
855 : 10002487656 : *cpp_flags = tok->flags | add_flags;
856 : :
857 : 10002487656 : timevar_pop (TV_CPP);
858 : :
859 : 10002487656 : return type;
860 : : }
861 : :
862 : : /* Returns the narrowest C-visible unsigned type, starting with the
863 : : minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if
864 : : there isn't one. */
865 : :
866 : : static enum integer_type_kind
867 : 135778581 : narrowest_unsigned_type (const widest_int &val, unsigned int flags)
868 : : {
869 : 135778581 : int itk;
870 : :
871 : 135778581 : if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
872 : : itk = itk_unsigned_int;
873 : 3415040 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
874 : : itk = itk_unsigned_long;
875 : : else
876 : 1113918 : itk = itk_unsigned_long_long;
877 : :
878 : 135930702 : for (; itk < itk_none; itk += 2 /* skip unsigned types */)
879 : : {
880 : 135930702 : tree upper;
881 : :
882 : 135930702 : if (integer_types[itk] == NULL_TREE)
883 : 0 : continue;
884 : 135930702 : upper = TYPE_MAX_VALUE (integer_types[itk]);
885 : :
886 : 135930702 : if (wi::geu_p (wi::to_widest (upper), val))
887 : 135778581 : return (enum integer_type_kind) itk;
888 : : }
889 : :
890 : : return itk_none;
891 : : }
892 : :
893 : : /* Ditto, but narrowest signed type. */
894 : : static enum integer_type_kind
895 : 132614442 : narrowest_signed_type (const widest_int &val, unsigned int flags)
896 : : {
897 : 132614442 : int itk;
898 : :
899 : 132614442 : if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
900 : : itk = itk_int;
901 : 1182309 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
902 : : itk = itk_long;
903 : : else
904 : 283996 : itk = itk_long_long;
905 : :
906 : 132807073 : for (; itk < itk_none; itk += 2 /* skip signed types */)
907 : : {
908 : 132805975 : tree upper;
909 : :
910 : 132805975 : if (integer_types[itk] == NULL_TREE)
911 : 4392 : continue;
912 : 132801583 : upper = TYPE_MAX_VALUE (integer_types[itk]);
913 : :
914 : 132801583 : if (wi::geu_p (wi::to_widest (upper), val))
915 : 132613344 : return (enum integer_type_kind) itk;
916 : : }
917 : :
918 : : return itk_none;
919 : : }
920 : :
921 : : /* Interpret TOKEN, an integer with FLAGS as classified by cpplib. */
922 : : static tree
923 : 135797214 : interpret_integer (const cpp_token *token, unsigned int flags,
924 : : enum overflow_type *overflow)
925 : : {
926 : 135797214 : tree value, type;
927 : 135797214 : enum integer_type_kind itk;
928 : 135797214 : cpp_num integer;
929 : 135797214 : HOST_WIDE_INT ival[3];
930 : :
931 : 135797214 : *overflow = OT_NONE;
932 : :
933 : 135797214 : if (UNLIKELY (flags & CPP_N_BITINT))
934 : : {
935 : 18633 : unsigned int suffix_len = 2 + ((flags & CPP_N_UNSIGNED) ? 1 : 0);
936 : 18633 : int max_bits_per_digit = 4; // ceil (log2 (10))
937 : 18633 : unsigned int prefix_len = 0;
938 : 18633 : bool hex = false;
939 : 18633 : const int bitint_maxwidth = WIDE_INT_MAX_PRECISION - 1;
940 : 18633 : if ((flags & CPP_N_RADIX) == CPP_N_OCTAL)
941 : : {
942 : 947 : max_bits_per_digit = 3;
943 : 947 : prefix_len = 1;
944 : 947 : if (token->val.str.len > 2
945 : 947 : && (token->val.str.text[1] == 'o'
946 : 946 : || token->val.str.text[1] == 'O'))
947 : 18633 : prefix_len = 2;
948 : : }
949 : 17686 : else if ((flags & CPP_N_RADIX) == CPP_N_HEX)
950 : : {
951 : : max_bits_per_digit = 4;
952 : : prefix_len = 2;
953 : : hex = true;
954 : : }
955 : 17527 : else if ((flags & CPP_N_RADIX) == CPP_N_BINARY)
956 : : {
957 : 1 : max_bits_per_digit = 1;
958 : 1 : prefix_len = 2;
959 : : }
960 : 18633 : int max_digits
961 : 18633 : = TYPE_PRECISION (intmax_type_node) >> max_bits_per_digit;
962 : 18633 : const int max_buf = 128;
963 : 18633 : if (max_digits > max_buf)
964 : : max_digits = max_buf;
965 : :
966 : 18633 : widest_int wval;
967 : 18633 : unsigned int prec;
968 : 18633 : gcc_checking_assert (token->val.str.len > prefix_len + suffix_len
969 : : || token->val.str.len == 1 + suffix_len);
970 : 18633 : if (token->val.str.len - (prefix_len + suffix_len)
971 : 18633 : <= (unsigned) max_digits)
972 : : {
973 : 2841 : integer = cpp_interpret_integer (parse_in, token,
974 : : (flags & CPP_N_RADIX)
975 : : | CPP_N_UNSIGNED);
976 : 2841 : ival[0] = integer.low;
977 : 2841 : ival[1] = integer.high;
978 : 2841 : ival[2] = 0;
979 : 2841 : wval = widest_int::from_array (ival, 3);
980 : : }
981 : : else
982 : : {
983 : 15792 : unsigned char buf[3 + max_buf];
984 : 15792 : memcpy (buf, token->val.str.text, prefix_len);
985 : 15792 : wval = 0U;
986 : 15792 : const unsigned char *p = token->val.str.text + prefix_len;
987 : 15792 : cpp_token tok = *token;
988 : 15792 : tok.val.str.text = buf;
989 : 15792 : if (!prefix_len)
990 : 15646 : max_digits = 19;
991 : 178978 : do
992 : : {
993 : 97385 : unsigned char *q = buf + prefix_len;
994 : 1360387 : do
995 : : {
996 : 1360387 : unsigned char c = *p++;
997 : 1360387 : if (ISDIGIT (c) || (hex && ISXDIGIT (c)))
998 : : {
999 : 1329919 : *q++ = c;
1000 : 1329919 : if (q == buf + prefix_len + max_digits)
1001 : : break;
1002 : : }
1003 : 30468 : else if (c != '\'')
1004 : : {
1005 : : --p;
1006 : : break;
1007 : : }
1008 : : }
1009 : : while (1);
1010 : 97385 : if (q == buf + prefix_len)
1011 : : break;
1012 : : else
1013 : : {
1014 : 81593 : wi::overflow_type wioverflow;
1015 : 81593 : *q = '\0';
1016 : 81593 : tok.val.str.len = q - buf;
1017 : 81593 : if (wval == 0)
1018 : : ;
1019 : 65774 : else if (prefix_len)
1020 : : {
1021 : 1660 : prec = wi::min_precision (wval, UNSIGNED);
1022 : 1660 : unsigned HOST_WIDE_INT shift
1023 : 1660 : = (tok.val.str.len - prefix_len) * max_bits_per_digit;
1024 : 1660 : if (prec + shift > bitint_maxwidth)
1025 : 0 : goto bitint_overflow;
1026 : 1689 : wval = wi::lshift (wval, shift);
1027 : : }
1028 : : else
1029 : : {
1030 : 64114 : static unsigned HOST_WIDE_INT tens[]
1031 : : = { 1U, 10U, 100U, 1000U,
1032 : : HOST_WIDE_INT_UC (10000),
1033 : : HOST_WIDE_INT_UC (100000),
1034 : : HOST_WIDE_INT_UC (1000000),
1035 : : HOST_WIDE_INT_UC (10000000),
1036 : : HOST_WIDE_INT_UC (100000000),
1037 : : HOST_WIDE_INT_UC (1000000000),
1038 : : HOST_WIDE_INT_UC (10000000000),
1039 : : HOST_WIDE_INT_UC (100000000000),
1040 : : HOST_WIDE_INT_UC (1000000000000),
1041 : : HOST_WIDE_INT_UC (10000000000000),
1042 : : HOST_WIDE_INT_UC (100000000000000),
1043 : : HOST_WIDE_INT_UC (1000000000000000),
1044 : : HOST_WIDE_INT_UC (10000000000000000),
1045 : : HOST_WIDE_INT_UC (100000000000000000),
1046 : : HOST_WIDE_INT_UC (1000000000000000000),
1047 : : HOST_WIDE_INT_UC (10000000000000000000) };
1048 : 64114 : widest_int ten = tens[q - buf];
1049 : 64114 : wval = wi::umul (wval, ten, &wioverflow);
1050 : 64114 : if (wioverflow)
1051 : 0 : goto bitint_overflow;
1052 : 64114 : }
1053 : 81593 : integer = cpp_interpret_integer (parse_in, &tok,
1054 : : (flags & CPP_N_RADIX)
1055 : : | CPP_N_UNSIGNED);
1056 : 81593 : ival[0] = integer.low;
1057 : 81593 : ival[1] = integer.high;
1058 : 81593 : ival[2] = 0;
1059 : 81593 : if (prefix_len)
1060 : 1862 : wval = wval + widest_int::from_array (ival, 3);
1061 : : else
1062 : : {
1063 : 79760 : widest_int addend = widest_int::from_array (ival, 3);
1064 : 79760 : wval = wi::add (wval, addend, UNSIGNED, &wioverflow);
1065 : 79760 : if (wioverflow)
1066 : 0 : goto bitint_overflow;
1067 : 79760 : }
1068 : : }
1069 : 81593 : }
1070 : : while (1);
1071 : : }
1072 : :
1073 : 18633 : prec = wi::min_precision (wval, UNSIGNED);
1074 : 18633 : if (prec == 0)
1075 : : prec = 1;
1076 : 18633 : if ((flags & CPP_N_UNSIGNED) == 0)
1077 : 13644 : ++prec;
1078 : 18633 : if (prec > bitint_maxwidth)
1079 : : {
1080 : 0 : bitint_overflow:
1081 : 0 : if ((flags & CPP_N_UNSIGNED) != 0)
1082 : 0 : error ("integer constant is too large for "
1083 : : "%<unsigned _BitInt(%d)%> type", bitint_maxwidth);
1084 : : else
1085 : 0 : error ("integer constant is too large for "
1086 : : "%<_BitInt(%d)%> type", bitint_maxwidth);
1087 : 0 : return integer_zero_node;
1088 : : }
1089 : :
1090 : 18633 : struct bitint_info info;
1091 : 18633 : if (!targetm.c.bitint_type_info (prec, &info))
1092 : : {
1093 : 0 : sorry ("%<_BitInt(%d)%> is not supported on this target", prec);
1094 : 0 : return integer_zero_node;
1095 : : }
1096 : :
1097 : 18633 : type = build_bitint_type (prec, (flags & CPP_N_UNSIGNED) != 0);
1098 : 18633 : return wide_int_to_tree (type, wval);
1099 : 18633 : }
1100 : :
1101 : 135778581 : integer = cpp_interpret_integer (parse_in, token, flags);
1102 : 135778581 : if (integer.overflow)
1103 : 20 : *overflow = OT_OVERFLOW;
1104 : :
1105 : 135778581 : ival[0] = integer.low;
1106 : 135778581 : ival[1] = integer.high;
1107 : 135778581 : ival[2] = 0;
1108 : 271557162 : widest_int wval = widest_int::from_array (ival, 3);
1109 : :
1110 : : /* The type of a constant with a U suffix is straightforward. */
1111 : 135778581 : if (flags & CPP_N_UNSIGNED)
1112 : 3164139 : itk = narrowest_unsigned_type (wval, flags);
1113 : : else
1114 : : {
1115 : : /* The type of a potentially-signed integer constant varies
1116 : : depending on the base it's in, the standard in use, and the
1117 : : length suffixes. */
1118 : 132614442 : enum integer_type_kind itk_u
1119 : 132614442 : = narrowest_unsigned_type (wval, flags);
1120 : 132614442 : enum integer_type_kind itk_s
1121 : 132614442 : = narrowest_signed_type (wval, flags);
1122 : :
1123 : : /* In both C89 and C99, octal and hex constants may be signed or
1124 : : unsigned, whichever fits tighter. We do not warn about this
1125 : : choice differing from the traditional choice, as the constant
1126 : : is probably a bit pattern and either way will work. */
1127 : 132614442 : if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
1128 : 13431734 : itk = MIN (itk_u, itk_s);
1129 : : else
1130 : : {
1131 : : /* In C99, decimal constants are always signed.
1132 : : In C89, decimal constants that don't fit in long have
1133 : : undefined behavior; we try to make them unsigned long.
1134 : : In GCC's extended C89, that last is true of decimal
1135 : : constants that don't fit in long long, too. */
1136 : :
1137 : 119182708 : itk = itk_s;
1138 : 119182708 : if (itk_s > itk_u && itk_s > itk_long)
1139 : : {
1140 : 27 : if (!flag_isoc99)
1141 : : {
1142 : 15 : if (itk_u < itk_unsigned_long)
1143 : : itk_u = itk_unsigned_long;
1144 : 15 : itk = itk_u;
1145 : 15 : warning (0, "this decimal constant is unsigned only in ISO C90");
1146 : : }
1147 : : else
1148 : 12 : warning (OPT_Wtraditional,
1149 : : "this decimal constant would be unsigned in ISO C90");
1150 : : }
1151 : : }
1152 : : }
1153 : :
1154 : 135778581 : if (itk == itk_none)
1155 : : /* cpplib has already issued a warning for overflow. */
1156 : 0 : type = ((flags & CPP_N_UNSIGNED)
1157 : 0 : ? widest_unsigned_literal_type_node
1158 : : : widest_integer_literal_type_node);
1159 : 135778581 : else if (flags & CPP_N_SIZE_T)
1160 : : {
1161 : : /* itk refers to fundamental types not aliased size types. */
1162 : 24 : if (flags & CPP_N_UNSIGNED)
1163 : 16 : type = size_type_node;
1164 : : else
1165 : 8 : type = signed_size_type_node;
1166 : : }
1167 : : else
1168 : : {
1169 : 135778557 : type = integer_types[itk];
1170 : 135778557 : if (itk > itk_unsigned_long
1171 : 1129760 : && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
1172 : 15842 : emit_diagnostic
1173 : 33520 : ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
1174 : : ? DK_PEDWARN : DK_WARNING,
1175 : : input_location, OPT_Wlong_long,
1176 : : (flags & CPP_N_UNSIGNED)
1177 : : ? "integer constant is too large for %<unsigned long%> type"
1178 : : : "integer constant is too large for %<long%> type");
1179 : : }
1180 : :
1181 : 135778581 : value = wide_int_to_tree (type, wval);
1182 : :
1183 : : /* Convert imaginary to a complex type. */
1184 : 135778581 : if (flags & CPP_N_IMAGINARY)
1185 : 3133 : value = build_complex (NULL_TREE, build_int_cst (type, 0), value);
1186 : :
1187 : 135778581 : return value;
1188 : : }
1189 : :
1190 : : /* Interpret TOKEN, a floating point number with FLAGS as classified
1191 : : by cpplib. For C++11 SUFFIX may contain a user-defined literal suffix. */
1192 : : static tree
1193 : 4553176 : interpret_float (const cpp_token *token, unsigned int flags,
1194 : : const char *suffix, enum overflow_type *overflow)
1195 : : {
1196 : 4553176 : tree type;
1197 : 4553176 : tree const_type;
1198 : 4553176 : tree value;
1199 : 4553176 : REAL_VALUE_TYPE real;
1200 : 4553176 : REAL_VALUE_TYPE real_trunc;
1201 : 4553176 : char *copy;
1202 : 4553176 : size_t copylen;
1203 : :
1204 : 4553176 : *overflow = OT_NONE;
1205 : :
1206 : : /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64
1207 : : pragma has been used and is either double or _Decimal64. Types
1208 : : that are not allowed with decimal float default to double. */
1209 : 4553176 : if (flags & CPP_N_DEFAULT)
1210 : : {
1211 : 2516350 : flags ^= CPP_N_DEFAULT;
1212 : 2516350 : flags |= CPP_N_MEDIUM;
1213 : :
1214 : 2516350 : if (((flags & CPP_N_HEX) == 0) && ((flags & CPP_N_IMAGINARY) == 0))
1215 : : {
1216 : 2491829 : warning (OPT_Wunsuffixed_float_constants,
1217 : : "unsuffixed floating constant");
1218 : 2491829 : if (float_const_decimal64_p ())
1219 : 23 : flags |= CPP_N_DFLOAT;
1220 : : }
1221 : : }
1222 : :
1223 : : /* Decode _Fract and _Accum. */
1224 : 4553176 : if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM)
1225 : 54 : return interpret_fixed (token, flags);
1226 : :
1227 : : /* Decode type based on width and properties. */
1228 : 4553122 : if (flags & CPP_N_DFLOAT)
1229 : 16261 : if (!targetm.decimal_float_supported_p ())
1230 : : {
1231 : 0 : error ("decimal floating-point not supported for this target");
1232 : 0 : return error_mark_node;
1233 : : }
1234 : 16261 : else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1235 : 5049 : type = dfloat128_type_node;
1236 : 11212 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
1237 : 5618 : type = dfloat32_type_node;
1238 : 5594 : else if ((flags & CPP_N_FLOATNX) != 0)
1239 : 81 : type = dfloat64x_type_node;
1240 : : else
1241 : 5513 : type = dfloat64_type_node;
1242 : : else
1243 : 4536861 : if (flags & CPP_N_WIDTH_MD)
1244 : : {
1245 : 77771 : char suffix;
1246 : 77771 : machine_mode mode;
1247 : :
1248 : 77771 : if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W)
1249 : : suffix = 'w';
1250 : : else
1251 : 77735 : suffix = 'q';
1252 : :
1253 : 77771 : mode = targetm.c.mode_for_suffix (suffix);
1254 : 77771 : if (mode == VOIDmode)
1255 : : {
1256 : 0 : error ("unsupported non-standard suffix on floating constant");
1257 : :
1258 : 0 : return error_mark_node;
1259 : : }
1260 : : else
1261 : 77771 : pedwarn (input_location, OPT_Wpedantic, "non-standard suffix on floating constant");
1262 : :
1263 : 77771 : type = c_common_type_for_mode (mode, 0);
1264 : : /* For Q suffix, prefer float128t_type_node (__float128) type
1265 : : over float128_type_node (_Float128) type if they are distinct. */
1266 : 77771 : if (type == float128_type_node && float128t_type_node)
1267 : 77771 : type = float128t_type_node;
1268 : 77771 : gcc_assert (type);
1269 : : }
1270 : 4459090 : else if ((flags & (CPP_N_FLOATN | CPP_N_FLOATNX)) != 0)
1271 : : {
1272 : 378244 : unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
1273 : 378244 : bool extended = (flags & CPP_N_FLOATNX) != 0;
1274 : 378244 : type = NULL_TREE;
1275 : 898203 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
1276 : 898203 : if (floatn_nx_types[i].n == (int) n
1277 : 380950 : && floatn_nx_types[i].extended == extended)
1278 : : {
1279 : 378244 : type = FLOATN_NX_TYPE_NODE (i);
1280 : 378244 : break;
1281 : : }
1282 : 378244 : if (type == NULL_TREE)
1283 : : {
1284 : 0 : error ("unsupported non-standard suffix on floating constant");
1285 : 0 : return error_mark_node;
1286 : : }
1287 : 378244 : else if (!c_dialect_cxx ())
1288 : : {
1289 : 92258 : if (warn_c11_c23_compat > 0)
1290 : : {
1291 : 12 : if (pedantic && !flag_isoc23)
1292 : 0 : pedwarn (input_location, OPT_Wc11_c23_compat,
1293 : : "non-standard suffix on floating constant "
1294 : : "before C23");
1295 : : else
1296 : 12 : warning (OPT_Wc11_c23_compat,
1297 : : "non-standard suffix on floating constant "
1298 : : "before C23");
1299 : : }
1300 : 92246 : else if (warn_c11_c23_compat != 0 && pedantic && !flag_isoc23)
1301 : 40 : pedwarn (input_location, OPT_Wpedantic,
1302 : : "non-standard suffix on floating constant "
1303 : : "before C23");
1304 : : }
1305 : 285986 : else if (!extended)
1306 : : {
1307 : 285870 : if (cxx_dialect < cxx23 && pedantic)
1308 : 1274 : pedwarn (input_location, OPT_Wc__23_extensions,
1309 : : "%<f%d%> or %<F%d%> suffix on floating constant only "
1310 : : "available with %<-std=c++23%> or %<-std=gnu++23%>",
1311 : : n, n);
1312 : : }
1313 : : else
1314 : 116 : pedwarn (input_location, OPT_Wpedantic,
1315 : : "non-standard suffix on floating constant");
1316 : : }
1317 : 4080846 : else if ((flags & CPP_N_BFLOAT16) != 0)
1318 : : {
1319 : 101447 : type = bfloat16_type_node;
1320 : 101447 : if (type == NULL_TREE)
1321 : : {
1322 : 0 : error ("unsupported non-standard suffix on floating constant");
1323 : 0 : return error_mark_node;
1324 : : }
1325 : 101447 : if (!c_dialect_cxx ())
1326 : 352 : pedwarn (input_location, OPT_Wpedantic,
1327 : : "non-standard suffix on floating constant");
1328 : 101095 : else if (cxx_dialect < cxx23 && pedantic)
1329 : 2551 : pedwarn (input_location, OPT_Wc__23_extensions,
1330 : : "%<bf16%> or %<BF16%> suffix on floating constant only "
1331 : : "available with %<-std=c++23%> or %<-std=gnu++23%>");
1332 : : }
1333 : 3979399 : else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1334 : 1049106 : type = long_double_type_node;
1335 : 2930293 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
1336 : 2516467 : || flag_single_precision_constant)
1337 : 414014 : type = float_type_node;
1338 : : else
1339 : 2516279 : type = double_type_node;
1340 : :
1341 : 4553122 : const_type = excess_precision_type (type);
1342 : 4553122 : if (!const_type)
1343 : 4414630 : const_type = type;
1344 : :
1345 : : /* Copy the constant to a nul-terminated buffer. If the constant
1346 : : has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
1347 : : can't handle them. */
1348 : 4553122 : copylen = token->val.str.len;
1349 : 4553122 : if (flags & CPP_N_USERDEF)
1350 : 31770 : copylen -= strlen (suffix);
1351 : 4521352 : else if (flags & CPP_N_DFLOAT)
1352 : : {
1353 : 16261 : if (ISDIGIT (token->val.str.text[copylen - 1]))
1354 : 146 : copylen -= (flags & CPP_N_LARGE) ? 4 : 3;
1355 : 16178 : else if ((flags & CPP_N_FLOATNX) != 0)
1356 : 81 : copylen -= 4;
1357 : : else
1358 : 16097 : copylen -= 2;
1359 : : }
1360 : : else
1361 : : {
1362 : 4505091 : if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
1363 : : /* Must be an F or L or machine defined suffix. */
1364 : 1988624 : copylen--;
1365 : 4505091 : if (flags & CPP_N_IMAGINARY)
1366 : : /* I or J suffix. */
1367 : 51252 : copylen--;
1368 : 4505091 : if (flags & CPP_N_FLOATNX)
1369 : 2706 : copylen--;
1370 : 4505091 : if (flags & (CPP_N_FLOATN | CPP_N_FLOATNX))
1371 : : {
1372 : 378244 : unsigned int n = (flags & CPP_N_WIDTH_FLOATN_NX) >> CPP_FLOATN_SHIFT;
1373 : 1219923 : while (n > 0)
1374 : : {
1375 : 841679 : copylen--;
1376 : 841679 : n /= 10;
1377 : : }
1378 : : }
1379 : : }
1380 : :
1381 : 4553122 : copy = (char *) alloca (copylen + 1);
1382 : 4553122 : if (c_dialect_cxx () ? cxx_dialect > cxx11 : flag_isoc23)
1383 : : {
1384 : : size_t maxlen = 0;
1385 : 52173374 : for (size_t i = 0; i < copylen; ++i)
1386 : 47808864 : if (token->val.str.text[i] != '\'')
1387 : 47808808 : copy[maxlen++] = token->val.str.text[i];
1388 : 4364510 : copy[maxlen] = '\0';
1389 : : }
1390 : : else
1391 : : {
1392 : 188612 : memcpy (copy, token->val.str.text, copylen);
1393 : 188612 : copy[copylen] = '\0';
1394 : : }
1395 : :
1396 : 4553122 : real_from_string3 (&real, copy, TYPE_MODE (const_type));
1397 : 4553122 : if (const_type != type)
1398 : : /* Diagnosing if the result of converting the value with excess
1399 : : precision to the semantic type would overflow (with associated
1400 : : double rounding) is more appropriate than diagnosing if the
1401 : : result of converting the string directly to the semantic type
1402 : : would overflow. */
1403 : 138492 : real_convert (&real_trunc, TYPE_MODE (type), &real);
1404 : :
1405 : : /* Both C and C++ require a diagnostic for a floating constant
1406 : : outside the range of representable values of its type. Since we
1407 : : have __builtin_inf* to produce an infinity, this is now a
1408 : : mandatory pedwarn if the target does not support infinities. */
1409 : 4553122 : if (REAL_VALUE_ISINF (real)
1410 : 4553122 : || (const_type != type && REAL_VALUE_ISINF (real_trunc)))
1411 : : {
1412 : 58 : *overflow = OT_OVERFLOW;
1413 : 58 : if (!(flags & CPP_N_USERDEF))
1414 : : {
1415 : 188 : if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
1416 : 0 : pedwarn (input_location, 0,
1417 : : "floating constant exceeds range of %qT", type);
1418 : : else
1419 : 49 : warning (OPT_Woverflow,
1420 : : "floating constant exceeds range of %qT", type);
1421 : : }
1422 : : }
1423 : : /* We also give a warning if the value underflows. */
1424 : 4553064 : else if (real_equal (&real, &dconst0)
1425 : 4553064 : || (const_type != type
1426 : 50383 : && real_equal (&real_trunc, &dconst0)))
1427 : : {
1428 : 1209385 : REAL_VALUE_TYPE realvoidmode;
1429 : 1209385 : int oflow = real_from_string (&realvoidmode, copy);
1430 : 1209385 : *overflow = (oflow == 0 ? OT_NONE
1431 : 21 : : (oflow < 0 ? OT_UNDERFLOW : OT_OVERFLOW));
1432 : 1209385 : if (!(flags & CPP_N_USERDEF))
1433 : : {
1434 : 1177864 : if (oflow < 0 || !real_equal (&realvoidmode, &dconst0))
1435 : 30 : warning (OPT_Woverflow, "floating constant truncated to zero");
1436 : : }
1437 : : }
1438 : :
1439 : : /* Create a node with determined type and value. */
1440 : 4553122 : value = build_real (const_type, real);
1441 : 4553122 : if (flags & CPP_N_IMAGINARY)
1442 : : {
1443 : 51252 : value = build_complex (NULL_TREE,
1444 : : fold_convert (const_type,
1445 : : integer_zero_node), value);
1446 : 51252 : if (type != const_type)
1447 : : {
1448 : 58 : const_type = TREE_TYPE (value);
1449 : 58 : type = build_complex_type (type);
1450 : : }
1451 : : }
1452 : :
1453 : 4553122 : if (type != const_type)
1454 : 138492 : value = build1_loc (token->src_loc, EXCESS_PRECISION_EXPR, type, value);
1455 : :
1456 : : return value;
1457 : : }
1458 : :
1459 : : /* Interpret TOKEN, a fixed-point number with FLAGS as classified
1460 : : by cpplib. */
1461 : :
1462 : : static tree
1463 : 54 : interpret_fixed (const cpp_token *token, unsigned int flags)
1464 : : {
1465 : 54 : tree type;
1466 : 54 : tree value;
1467 : 54 : FIXED_VALUE_TYPE fixed;
1468 : 54 : char *copy;
1469 : 54 : size_t copylen;
1470 : :
1471 : 54 : copylen = token->val.str.len;
1472 : :
1473 : 54 : if (flags & CPP_N_FRACT) /* _Fract. */
1474 : : {
1475 : 36 : if (flags & CPP_N_UNSIGNED) /* Unsigned _Fract. */
1476 : : {
1477 : 0 : if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1478 : : {
1479 : 0 : type = unsigned_long_long_fract_type_node;
1480 : 0 : copylen -= 4;
1481 : : }
1482 : 0 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
1483 : : {
1484 : 0 : type = unsigned_long_fract_type_node;
1485 : 0 : copylen -= 3;
1486 : : }
1487 : 0 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
1488 : : {
1489 : 0 : type = unsigned_short_fract_type_node;
1490 : 0 : copylen -= 3;
1491 : : }
1492 : : else
1493 : : {
1494 : 0 : type = unsigned_fract_type_node;
1495 : 0 : copylen -= 2;
1496 : : }
1497 : : }
1498 : : else /* Signed _Fract. */
1499 : : {
1500 : 36 : if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1501 : : {
1502 : 0 : type = long_long_fract_type_node;
1503 : 0 : copylen -= 3;
1504 : : }
1505 : 36 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
1506 : : {
1507 : 0 : type = long_fract_type_node;
1508 : 0 : copylen -= 2;
1509 : : }
1510 : 36 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
1511 : : {
1512 : 0 : type = short_fract_type_node;
1513 : 0 : copylen -= 2;
1514 : : }
1515 : : else
1516 : : {
1517 : 36 : type = fract_type_node;
1518 : 36 : copylen --;
1519 : : }
1520 : : }
1521 : : }
1522 : : else /* _Accum. */
1523 : : {
1524 : 18 : if (flags & CPP_N_UNSIGNED) /* Unsigned _Accum. */
1525 : : {
1526 : 0 : if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1527 : : {
1528 : 0 : type = unsigned_long_long_accum_type_node;
1529 : 0 : copylen -= 4;
1530 : : }
1531 : 0 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
1532 : : {
1533 : 0 : type = unsigned_long_accum_type_node;
1534 : 0 : copylen -= 3;
1535 : : }
1536 : 0 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
1537 : : {
1538 : 0 : type = unsigned_short_accum_type_node;
1539 : 0 : copylen -= 3;
1540 : : }
1541 : : else
1542 : : {
1543 : 0 : type = unsigned_accum_type_node;
1544 : 0 : copylen -= 2;
1545 : : }
1546 : : }
1547 : : else /* Signed _Accum. */
1548 : : {
1549 : 18 : if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
1550 : : {
1551 : 0 : type = long_long_accum_type_node;
1552 : 0 : copylen -= 3;
1553 : : }
1554 : 18 : else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
1555 : : {
1556 : 0 : type = long_accum_type_node;
1557 : 0 : copylen -= 2;
1558 : : }
1559 : 18 : else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
1560 : : {
1561 : 0 : type = short_accum_type_node;
1562 : 0 : copylen -= 2;
1563 : : }
1564 : : else
1565 : : {
1566 : 18 : type = accum_type_node;
1567 : 18 : copylen --;
1568 : : }
1569 : : }
1570 : : }
1571 : :
1572 : 54 : copy = (char *) alloca (copylen + 1);
1573 : 54 : memcpy (copy, token->val.str.text, copylen);
1574 : 54 : copy[copylen] = '\0';
1575 : :
1576 : 54 : fixed_from_string (&fixed, copy, SCALAR_TYPE_MODE (type));
1577 : :
1578 : : /* Create a node with determined type and value. */
1579 : 54 : value = build_fixed (type, fixed);
1580 : :
1581 : 54 : return value;
1582 : : }
1583 : :
1584 : : /* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
1585 : : UTF8STRING tokens into a tree, performing string constant
1586 : : concatenation. TOK is the first of these. VALP is the location to
1587 : : write the string into. OBJC_STRING indicates whether an '@' token
1588 : : preceded the incoming token (in that case, the strings can either
1589 : : be ObjC strings, preceded by a single '@', or normal strings, not
1590 : : preceded by '@'. The result will be a CPP_OBJC_STRING). Returns
1591 : : the CPP token type of the result (CPP_STRING, CPP_WSTRING,
1592 : : CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
1593 : :
1594 : : This is unfortunately more work than it should be. If any of the
1595 : : strings in the series has an L prefix, the result is a wide string
1596 : : (6.4.5p4). Whether or not the result is a wide string affects the
1597 : : meaning of octal and hexadecimal escapes (6.4.4.4p6,9). But escape
1598 : : sequences do not continue across the boundary between two strings in
1599 : : a series (6.4.5p7), so we must not lose the boundaries. Therefore
1600 : : cpp_interpret_string takes a vector of cpp_string structures, which
1601 : : we must arrange to provide. */
1602 : :
1603 : : static enum cpp_ttype
1604 : 18 : lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
1605 : : {
1606 : 18 : tree value;
1607 : 18 : size_t concats = 0;
1608 : 18 : struct obstack str_ob;
1609 : 18 : struct obstack loc_ob;
1610 : 18 : cpp_string istr;
1611 : 18 : enum cpp_ttype type = tok->type;
1612 : :
1613 : : /* Try to avoid the overhead of creating and destroying an obstack
1614 : : for the common case of just one string. */
1615 : 18 : cpp_string str = tok->val.str;
1616 : 18 : location_t init_loc = tok->src_loc;
1617 : 18 : cpp_string *strs = &str;
1618 : 18 : location_t *locs = NULL;
1619 : :
1620 : : /* objc_at_sign_was_seen is only used when doing Objective-C string
1621 : : concatenation. It is 'true' if we have seen an '@' before the
1622 : : current string, and 'false' if not. We must see exactly one or
1623 : : zero '@' before each string. */
1624 : 18 : bool objc_at_sign_was_seen = false;
1625 : :
1626 : 18 : retry:
1627 : 18 : tok = get_token (parse_in);
1628 : 18 : switch (tok->type)
1629 : : {
1630 : 0 : case CPP_PADDING:
1631 : 0 : goto retry;
1632 : 0 : case CPP_ATSIGN:
1633 : 0 : if (objc_string)
1634 : : {
1635 : 0 : if (objc_at_sign_was_seen)
1636 : 0 : error ("repeated %<@%> before Objective-C string");
1637 : :
1638 : 0 : objc_at_sign_was_seen = true;
1639 : 0 : goto retry;
1640 : : }
1641 : : /* FALLTHROUGH */
1642 : :
1643 : 18 : default:
1644 : 18 : break;
1645 : :
1646 : 0 : case CPP_WSTRING:
1647 : 0 : case CPP_STRING16:
1648 : 0 : case CPP_STRING32:
1649 : 0 : case CPP_UTF8STRING:
1650 : 0 : if (type != tok->type)
1651 : : {
1652 : 0 : if (type == CPP_STRING)
1653 : 0 : type = tok->type;
1654 : : else
1655 : 0 : error ("unsupported non-standard concatenation of string literals");
1656 : : }
1657 : : /* FALLTHROUGH */
1658 : :
1659 : 0 : case CPP_STRING:
1660 : 0 : if (!concats)
1661 : : {
1662 : 0 : gcc_obstack_init (&str_ob);
1663 : 0 : gcc_obstack_init (&loc_ob);
1664 : 0 : obstack_grow (&str_ob, &str, sizeof (cpp_string));
1665 : 0 : obstack_grow (&loc_ob, &init_loc, sizeof (location_t));
1666 : : }
1667 : :
1668 : 0 : concats++;
1669 : 0 : obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
1670 : 0 : obstack_grow (&loc_ob, &tok->src_loc, sizeof (location_t));
1671 : :
1672 : 0 : if (objc_string)
1673 : 0 : objc_at_sign_was_seen = false;
1674 : 0 : goto retry;
1675 : : }
1676 : :
1677 : : /* It is an error if we saw a '@' with no following string. */
1678 : 18 : if (objc_at_sign_was_seen)
1679 : 0 : error ("stray %<@%> in program");
1680 : :
1681 : : /* We have read one more token than we want. */
1682 : 18 : _cpp_backup_tokens (parse_in, 1);
1683 : 18 : if (concats)
1684 : : {
1685 : 0 : strs = XOBFINISH (&str_ob, cpp_string *);
1686 : 0 : locs = XOBFINISH (&loc_ob, location_t *);
1687 : : }
1688 : :
1689 : 18 : if (concats && !objc_string && !in_system_header_at (input_location))
1690 : 0 : warning (OPT_Wtraditional,
1691 : : "traditional C rejects string constant concatenation");
1692 : :
1693 : 18 : if ((translate
1694 : 18 : ? cpp_interpret_string : cpp_interpret_string_notranslate)
1695 : 18 : (parse_in, strs, concats + 1, &istr, type))
1696 : : {
1697 : 18 : value = build_string (istr.len, (const char *) istr.text);
1698 : 18 : free (CONST_CAST (unsigned char *, istr.text));
1699 : 18 : if (concats)
1700 : : {
1701 : 0 : gcc_assert (locs);
1702 : 0 : gcc_assert (g_string_concat_db);
1703 : 0 : g_string_concat_db->record_string_concatenation (concats + 1, locs);
1704 : : }
1705 : : }
1706 : : else
1707 : : {
1708 : : /* Callers cannot generally handle error_mark_node in this context,
1709 : : so return the empty string instead. cpp_interpret_string has
1710 : : issued an error. */
1711 : 0 : switch (type)
1712 : : {
1713 : 0 : default:
1714 : 0 : case CPP_STRING:
1715 : 0 : case CPP_UTF8STRING:
1716 : 0 : if (type == CPP_UTF8STRING && flag_char8_t)
1717 : : {
1718 : 0 : value = build_string (TYPE_PRECISION (char8_type_node)
1719 : 0 : / TYPE_PRECISION (char_type_node),
1720 : : ""); /* char8_t is 8 bits */
1721 : : }
1722 : : else
1723 : 0 : value = build_string (1, "");
1724 : : break;
1725 : 0 : case CPP_STRING16:
1726 : 0 : value = build_string (TYPE_PRECISION (char16_type_node)
1727 : 0 : / TYPE_PRECISION (char_type_node),
1728 : : "\0"); /* char16_t is 16 bits */
1729 : 0 : break;
1730 : 0 : case CPP_STRING32:
1731 : 0 : value = build_string (TYPE_PRECISION (char32_type_node)
1732 : 0 : / TYPE_PRECISION (char_type_node),
1733 : : "\0\0\0"); /* char32_t is 32 bits */
1734 : 0 : break;
1735 : 0 : case CPP_WSTRING:
1736 : 0 : value = build_string (TYPE_PRECISION (wchar_type_node)
1737 : 0 : / TYPE_PRECISION (char_type_node),
1738 : : "\0\0\0"); /* widest supported wchar_t
1739 : : is 32 bits */
1740 : 0 : break;
1741 : : }
1742 : : }
1743 : :
1744 : 18 : switch (type)
1745 : : {
1746 : 18 : default:
1747 : 18 : case CPP_STRING:
1748 : 18 : TREE_TYPE (value) = char_array_type_node;
1749 : 18 : break;
1750 : 0 : case CPP_UTF8STRING:
1751 : 0 : if (flag_char8_t)
1752 : 0 : TREE_TYPE (value) = char8_array_type_node;
1753 : : else
1754 : 0 : TREE_TYPE (value) = char_array_type_node;
1755 : : break;
1756 : 0 : case CPP_STRING16:
1757 : 0 : TREE_TYPE (value) = char16_array_type_node;
1758 : 0 : break;
1759 : 0 : case CPP_STRING32:
1760 : 0 : TREE_TYPE (value) = char32_array_type_node;
1761 : 0 : break;
1762 : 0 : case CPP_WSTRING:
1763 : 0 : TREE_TYPE (value) = wchar_array_type_node;
1764 : : }
1765 : 18 : *valp = fix_string_type (value);
1766 : :
1767 : 18 : if (concats)
1768 : : {
1769 : 0 : obstack_free (&str_ob, 0);
1770 : 0 : obstack_free (&loc_ob, 0);
1771 : : }
1772 : :
1773 : 18 : return objc_string ? CPP_OBJC_STRING : type;
1774 : : }
1775 : :
1776 : : /* Converts a (possibly wide) character constant token into a tree. */
1777 : : static tree
1778 : 5817397 : lex_charconst (const cpp_token *token)
1779 : : {
1780 : 5817397 : cppchar_t result;
1781 : 5817397 : tree type, value;
1782 : 5817397 : unsigned int chars_seen;
1783 : 5817397 : int unsignedp = 0;
1784 : :
1785 : 5817397 : result = cpp_interpret_charconst (parse_in, token,
1786 : : &chars_seen, &unsignedp);
1787 : :
1788 : 5817397 : if (token->type == CPP_WCHAR)
1789 : 413405 : type = wchar_type_node;
1790 : 5403992 : else if (token->type == CPP_CHAR32)
1791 : 580 : type = char32_type_node;
1792 : 5403412 : else if (token->type == CPP_CHAR16)
1793 : 19172 : type = char16_type_node;
1794 : 5384240 : else if (token->type == CPP_UTF8CHAR)
1795 : : {
1796 : 195 : if (flag_char8_t)
1797 : 161 : type = char8_type_node;
1798 : : else
1799 : 34 : type = char_type_node;
1800 : : }
1801 : : /* In C, a character constant has type 'int'.
1802 : : In C++ 'char', but multi-char charconsts have type 'int'. */
1803 : 5384045 : else if (!c_dialect_cxx () || chars_seen > 1)
1804 : 112332 : type = integer_type_node;
1805 : : else
1806 : 5271713 : type = char_type_node;
1807 : :
1808 : : /* Cast to cppchar_signed_t to get correct sign-extension of RESULT
1809 : : before possibly widening to HOST_WIDE_INT for build_int_cst. */
1810 : 5817397 : if (unsignedp || (cppchar_signed_t) result >= 0)
1811 : 5815837 : value = build_int_cst (type, result);
1812 : : else
1813 : 1560 : value = build_int_cst (type, (cppchar_signed_t) result);
1814 : :
1815 : 5817397 : return value;
1816 : : }
1817 : :
1818 : : /* Helper function for c_parser_peek_conflict_marker
1819 : : and cp_lexer_peek_conflict_marker.
1820 : : Given a possible conflict marker token of kind TOK1_KIND
1821 : : consisting of a pair of characters, get the token kind for the
1822 : : standalone final character. */
1823 : :
1824 : : enum cpp_ttype
1825 : 100 : conflict_marker_get_final_tok_kind (enum cpp_ttype tok1_kind)
1826 : : {
1827 : 100 : switch (tok1_kind)
1828 : : {
1829 : 0 : default: gcc_unreachable ();
1830 : : case CPP_LSHIFT:
1831 : : /* "<<" and '<' */
1832 : : return CPP_LESS;
1833 : :
1834 : 31 : case CPP_EQ_EQ:
1835 : : /* "==" and '=' */
1836 : 31 : return CPP_EQ;
1837 : :
1838 : 35 : case CPP_RSHIFT:
1839 : : /* ">>" and '>' */
1840 : 35 : return CPP_GREATER;
1841 : : }
1842 : : }
|