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