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