Line data Source code
1 : /* C/ObjC/C++ command line option handling.
2 : Copyright (C) 2002-2026 Free Software Foundation, Inc.
3 : Contributed by Neil Booth.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #define INCLUDE_VECTOR
22 : #include "config.h"
23 : #include "system.h"
24 : #include "coretypes.h"
25 : #include "tm.h"
26 : #include "target.h"
27 : #include "c-target.h"
28 : #include "c-common.h"
29 : #include "memmodel.h"
30 : #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
31 : #include "diagnostic.h"
32 : #include "c-pragma.h"
33 : #include "flags.h"
34 : #include "toplev.h"
35 : #include "langhooks.h"
36 : #include "diagnostics/macro-unwinding.h" /* for virt_loc_aware_diagnostic_finalizer */
37 : #include "intl.h"
38 : #include "cppdefault.h"
39 : #include "incpath.h"
40 : #include "debug.h" /* For debug_hooks. */
41 : #include "opts.h"
42 : #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
43 : #include "mkdeps.h"
44 : #include "dumpfile.h"
45 : #include "file-prefix-map.h" /* add_*_prefix_map() */
46 : #include "context.h"
47 : #include "diagnostics/text-sink.h"
48 :
49 : #ifndef DOLLARS_IN_IDENTIFIERS
50 : # define DOLLARS_IN_IDENTIFIERS true
51 : #endif
52 :
53 : #ifndef TARGET_SYSTEM_ROOT
54 : # define TARGET_SYSTEM_ROOT NULL
55 : #endif
56 :
57 : #ifndef TARGET_OPTF
58 : #define TARGET_OPTF(ARG)
59 : #endif
60 :
61 : /* CPP's options. */
62 : cpp_options *cpp_opts;
63 :
64 : /* Input filename. */
65 : static const char *this_input_filename;
66 :
67 : /* Filename and stream for preprocessed output. */
68 : static const char *out_fname;
69 : static FILE *out_stream;
70 :
71 : /* Append dependencies to deps_file. */
72 : static bool deps_append;
73 :
74 : /* If dependency switches (-MF etc.) have been given. */
75 : static bool deps_seen;
76 :
77 : /* If -v seen. */
78 : static bool verbose;
79 :
80 : /* Dependency output file. */
81 : static const char *deps_file;
82 :
83 : /* Structured dependency output file. */
84 : static const char *fdeps_file;
85 :
86 : /* The prefix given by -iprefix, if any. */
87 : static const char *iprefix;
88 :
89 : /* The multilib directory given by -imultilib, if any. */
90 : static const char *imultilib;
91 :
92 : /* The system root, if any. Overridden by -isysroot. */
93 : static const char *sysroot = TARGET_SYSTEM_ROOT;
94 :
95 : /* Zero disables all standard directories for headers. */
96 : static bool std_inc = true;
97 :
98 : /* Zero disables the C++-specific standard directories for headers. */
99 : static bool std_cxx_inc = true;
100 :
101 : /* If the quote chain has been split by -I-. */
102 : static bool quote_chain_split;
103 :
104 : /* Number of deferred options. */
105 : static size_t deferred_count;
106 :
107 : /* Number of deferred options scanned for -include. */
108 : static size_t include_cursor;
109 :
110 : /* Whether any standard preincluded header has been preincluded. */
111 : static bool done_preinclude;
112 :
113 : static void handle_OPT_d (const char *);
114 : static void set_std_cxx98 (int);
115 : static void set_std_cxx11 (int);
116 : static void set_std_cxx14 (int);
117 : static void set_std_cxx17 (int);
118 : static void set_std_cxx20 (int);
119 : static void set_std_cxx23 (int);
120 : static void set_std_cxx26 (int);
121 : static void set_std_cxx29 (int);
122 : static void set_std_c89 (int, int);
123 : static void set_std_c99 (int);
124 : static void set_std_c11 (int);
125 : static void set_std_c17 (int);
126 : static void set_std_c23 (int);
127 : static void set_std_c2y (int);
128 : static void check_deps_environment_vars (void);
129 : static void handle_deferred_opts (void);
130 : static void sanitize_cpp_opts (void);
131 : static void add_prefixed_path (const char *, incpath_kind);
132 : static void push_command_line_include (void);
133 : static void cb_file_change (cpp_reader *, const line_map_ordinary *);
134 : static void cb_dir_change (cpp_reader *, const char *);
135 : static void c_finish_options (void);
136 :
137 : #ifndef STDC_0_IN_SYSTEM_HEADERS
138 : #define STDC_0_IN_SYSTEM_HEADERS 0
139 : #endif
140 :
141 : /* Holds switches parsed by c_common_handle_option (), but whose
142 : handling is deferred to c_common_post_options (). */
143 : static void defer_opt (enum opt_code, const char *);
144 : static struct deferred_opt
145 : {
146 : enum opt_code code;
147 : const char *arg;
148 : } *deferred_opts;
149 :
150 :
151 : extern const unsigned int
152 : c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
153 :
154 : /* Defer option CODE with argument ARG. */
155 : static void
156 183864 : defer_opt (enum opt_code code, const char *arg)
157 : {
158 183864 : deferred_opts[deferred_count].code = code;
159 183864 : deferred_opts[deferred_count].arg = arg;
160 183864 : deferred_count++;
161 0 : }
162 :
163 : /* Return language mask for option parsing. */
164 : unsigned int
165 7176517 : c_common_option_lang_mask (void)
166 : {
167 7176517 : static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
168 :
169 7176517 : return lang_flags[c_language];
170 : }
171 :
172 : /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
173 : static void
174 352718 : c_diagnostic_text_finalizer (diagnostics::text_sink &text_output,
175 : const diagnostics::diagnostic_info *diagnostic,
176 : enum diagnostics::kind)
177 : {
178 352718 : pretty_printer *const pp = text_output.get_printer ();
179 352718 : char *saved_prefix = pp_take_prefix (pp);
180 352718 : pp_set_prefix (pp, text_output.build_indent_prefix (false));
181 352718 : pp_newline (pp);
182 352718 : diagnostic_show_locus (&text_output.get_context (),
183 352718 : text_output.get_source_printing_options (),
184 352718 : diagnostic->m_richloc, diagnostic->m_kind, pp);
185 : /* By default print macro expansion contexts in the diagnostic
186 : finalizer -- for tokens resulting from macro expansion. */
187 352718 : diagnostics::virt_loc_aware_text_finalizer (text_output, diagnostic);
188 352718 : pp_set_prefix (pp, saved_prefix);
189 352718 : pp_flush (pp);
190 352718 : }
191 :
192 : /* Common default settings for diagnostics. */
193 : void
194 215695 : c_common_diagnostics_set_defaults (diagnostics::context *context)
195 : {
196 215695 : diagnostics::text_finalizer (context) = c_diagnostic_text_finalizer;
197 215695 : context->set_permissive_option (OPT_fpermissive);
198 215695 : }
199 :
200 : /* Input charset configuration for diagnostics. */
201 : static const char *
202 66507 : c_common_input_charset_cb (const char * /*filename*/)
203 : {
204 66507 : const char *cs = cpp_opts->input_charset;
205 66507 : return cpp_input_conversion_is_trivial (cs) ? nullptr : cs;
206 : }
207 :
208 : /* Whether options from all C-family languages should be accepted
209 : quietly. */
210 : static bool accept_all_c_family_options = false;
211 :
212 : /* Return whether to complain about a wrong-language option. */
213 : bool
214 365 : c_common_complain_wrong_lang_p (const struct cl_option *option)
215 : {
216 365 : if (accept_all_c_family_options
217 6 : && (option->flags & c_family_lang_mask))
218 6 : return false;
219 :
220 : return true;
221 : }
222 :
223 : /* Initialize options structure OPTS. */
224 : void
225 50341971 : c_common_init_options_struct (struct gcc_options *opts)
226 : {
227 50341971 : opts->x_flag_exceptions = c_dialect_cxx ();
228 50341971 : opts->x_warn_pointer_arith = c_dialect_cxx ();
229 50341971 : opts->x_warn_write_strings = c_dialect_cxx ();
230 50341971 : opts->x_flag_warn_unused_result = true;
231 :
232 : /* By default, C99-like requirements for complex multiply and divide. */
233 50341971 : opts->x_flag_complex_method = 2;
234 50341971 : }
235 :
236 : /* Common initialization before calling option handlers. */
237 : void
238 215695 : c_common_init_options (unsigned int decoded_options_count,
239 : struct cl_decoded_option *decoded_options)
240 : {
241 215695 : unsigned int i;
242 215695 : struct cpp_callbacks *cb;
243 :
244 215695 : g_string_concat_db
245 215695 : = new (ggc_alloc <string_concat_db> ()) string_concat_db ();
246 :
247 330329 : parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX : CLK_GNUC89,
248 : ident_hash, line_table, ident_hash_extra);
249 215695 : cb = cpp_get_callbacks (parse_in);
250 215695 : cb->diagnostic = c_cpp_diagnostic;
251 :
252 215695 : cpp_opts = cpp_get_options (parse_in);
253 215695 : cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
254 215695 : cpp_opts->objc = c_dialect_objc ();
255 215695 : cpp_opts->deps.modules = true;
256 :
257 : /* Reset to avoid warnings on internal definitions. We set it just
258 : before passing on command-line options to cpplib. */
259 215695 : cpp_opts->warn_dollars = 0;
260 :
261 215695 : deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
262 :
263 215695 : if (c_language == clk_c)
264 : {
265 : /* The default for C is gnu23. */
266 114634 : set_std_c23 (false /* ISO */);
267 :
268 : /* If preprocessing assembly language, accept any of the C-family
269 : front end options since the driver may pass them through. */
270 2933508 : for (i = 1; i < decoded_options_count; i++)
271 2705221 : if (decoded_options[i].opt_index == OPT_lang_asm)
272 : {
273 981 : accept_all_c_family_options = true;
274 981 : break;
275 : }
276 : }
277 :
278 : /* Set C++ standard to C++20 if not specified on the command line. */
279 215695 : if (c_dialect_cxx ())
280 101061 : set_std_cxx20 (/*ISO*/false);
281 :
282 215695 : global_dc->get_source_printing_options ().colorize_source_p = true;
283 215695 : }
284 :
285 : /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
286 : form of an -f or -W option was given. Returns false if the switch was
287 : invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
288 : bool
289 3426623 : c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
290 : int kind, location_t loc,
291 : const struct cl_option_handlers *handlers)
292 : {
293 3426623 : const struct cl_option *option = &cl_options[scode];
294 3426623 : enum opt_code code = (enum opt_code) scode;
295 3426623 : bool result = true;
296 :
297 : /* Prevent resetting the language standard to a C dialect when the driver
298 : has already determined that we're looking at assembler input. */
299 3426623 : bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
300 :
301 3426623 : switch (code)
302 : {
303 1481915 : default:
304 1481915 : if (cl_options[code].flags & c_family_lang_mask)
305 : {
306 1481915 : if ((option->flags & CL_TARGET)
307 1481915 : && ! targetcm.handle_c_option (scode, arg, value))
308 : result = false;
309 : break;
310 : }
311 : result = false;
312 : break;
313 :
314 428 : case OPT__output_pch:
315 428 : pch_file = arg;
316 428 : break;
317 :
318 10 : case OPT_A:
319 10 : defer_opt (code, arg);
320 10 : break;
321 :
322 13 : case OPT_C:
323 13 : cpp_opts->discard_comments = 0;
324 13 : break;
325 :
326 11 : case OPT_CC:
327 11 : cpp_opts->discard_comments = 0;
328 11 : cpp_opts->discard_comments_in_macro_exp = 0;
329 11 : break;
330 :
331 168158 : case OPT_D:
332 168158 : defer_opt (code, arg);
333 168158 : break;
334 :
335 25 : case OPT_H:
336 25 : cpp_opts->print_include_names = 1;
337 25 : break;
338 :
339 : case OPT_F:
340 : TARGET_OPTF (xstrdup (arg));
341 : break;
342 :
343 571307 : case OPT_I:
344 571307 : if (strcmp (arg, "-"))
345 571307 : add_path (xstrdup (arg), INC_BRACKET, 0, true);
346 : else
347 : {
348 0 : if (quote_chain_split)
349 0 : error ("%<-I-%> specified twice");
350 0 : quote_chain_split = true;
351 0 : split_quote_chain ();
352 0 : inform (input_location, "obsolete option %<-I-%> used, "
353 : "please use %<-iquote%> instead");
354 : }
355 : break;
356 :
357 31 : case OPT_M:
358 31 : case OPT_MM:
359 : /* When doing dependencies with -M or -MM, suppress normal
360 : preprocessed output, but still do -dM etc. as software
361 : depends on this. Preprocessed output does occur if -MD, -MMD
362 : or environment var dependency generation is used. */
363 31 : cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM : DEPS_USER);
364 31 : flag_no_output = 1;
365 31 : break;
366 :
367 5896 : case OPT_MD:
368 5896 : case OPT_MMD:
369 5896 : cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM : DEPS_USER);
370 5896 : cpp_opts->deps.need_preprocessor_output = true;
371 5896 : deps_file = arg;
372 5896 : break;
373 :
374 51 : case OPT_fdeps_format_:
375 : /* https://wg21.link/p1689r5 */
376 51 : if (!strcmp (arg, "p1689r5"))
377 48 : cpp_opts->deps.fdeps_format = FDEPS_FMT_P1689R5;
378 : else
379 3 : error ("%<-fdeps-format=%> unknown format %qs", arg);
380 : break;
381 :
382 63 : case OPT_fdeps_file_:
383 63 : deps_seen = true;
384 63 : fdeps_file = arg;
385 63 : break;
386 :
387 63 : case OPT_fdeps_target_:
388 63 : deps_seen = true;
389 63 : defer_opt (code, arg);
390 63 : break;
391 :
392 5843 : case OPT_MF:
393 5843 : deps_seen = true;
394 5843 : deps_file = arg;
395 5843 : break;
396 :
397 6 : case OPT_MG:
398 6 : deps_seen = true;
399 6 : cpp_opts->deps.missing_files = true;
400 6 : break;
401 :
402 5825 : case OPT_MP:
403 5825 : deps_seen = true;
404 5825 : cpp_opts->deps.phony_targets = true;
405 5825 : break;
406 :
407 0 : case OPT_Mmodules:
408 : /* Do not set deps_seen, so the user can unconditionally turn
409 : this on or off. */
410 0 : cpp_opts->deps.modules = true;
411 0 : break;
412 :
413 3 : case OPT_Mno_modules:
414 : /* Do not set deps_seen, so the user can unconditionally turn
415 : this on or off. */
416 3 : cpp_opts->deps.modules = false;
417 3 : break;
418 :
419 5892 : case OPT_MQ:
420 5892 : case OPT_MT:
421 5892 : deps_seen = true;
422 5892 : defer_opt (code, arg);
423 5892 : break;
424 :
425 43 : case OPT_P:
426 43 : flag_no_line_commands = 1;
427 43 : break;
428 :
429 61 : case OPT_U:
430 61 : defer_opt (code, arg);
431 61 : break;
432 :
433 11057 : case OPT_Wall:
434 : /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
435 :
436 11057 : cpp_opts->warn_num_sign_change = value;
437 11057 : break;
438 :
439 11147 : case OPT_Wunknown_pragmas:
440 : /* Set to greater than 1, so that even unknown pragmas in
441 : system headers will be warned about. */
442 : /* ??? There is no way to handle this automatically for now. */
443 11147 : warn_unknown_pragmas = value * 2;
444 11147 : break;
445 :
446 4017 : case OPT_ansi:
447 4017 : if (!c_dialect_cxx ())
448 3871 : set_std_c89 (false, true);
449 : else
450 146 : set_std_cxx98 (true);
451 : break;
452 :
453 1633 : case OPT_d:
454 1633 : handle_OPT_d (arg);
455 1633 : break;
456 :
457 12810 : case OPT_Wabi_:
458 12810 : warn_abi = true;
459 12810 : if (value == 1)
460 : {
461 0 : warning (0, "%<-Wabi=1%> is not supported, using =2");
462 0 : value = 2;
463 : }
464 12810 : warn_abi_version = value;
465 12810 : break;
466 :
467 18 : case OPT_fcanonical_system_headers:
468 18 : cpp_opts->canonical_system_headers = value;
469 18 : break;
470 :
471 12 : case OPT_fcond_mismatch:
472 12 : if (!c_dialect_cxx ())
473 : {
474 12 : flag_cond_mismatch = value;
475 12 : break;
476 : }
477 0 : warning (0, "switch %qs is no longer supported", option->opt_text);
478 0 : break;
479 :
480 308 : case OPT_fbuiltin_:
481 308 : if (value)
482 : result = false;
483 : else
484 308 : disable_builtin_function (arg);
485 : break;
486 :
487 1102 : case OPT_fdirectives_only:
488 1102 : cpp_opts->directives_only = value;
489 1102 : break;
490 :
491 7 : case OPT_fdollars_in_identifiers:
492 7 : cpp_opts->dollars_in_ident = value;
493 7 : break;
494 :
495 8 : case OPT_fmacro_prefix_map_:
496 8 : add_macro_prefix_map (arg);
497 8 : break;
498 :
499 689 : case OPT_ffreestanding:
500 689 : value = !value;
501 : /* Fall through. */
502 697 : case OPT_fhosted:
503 697 : flag_hosted = value;
504 697 : flag_no_builtin = !value;
505 697 : break;
506 :
507 0 : case OPT_fconstant_string_class_:
508 0 : constant_string_class_name = arg;
509 0 : break;
510 :
511 0 : case OPT_fextended_identifiers:
512 0 : cpp_opts->extended_identifiers = value;
513 0 : break;
514 :
515 4 : case OPT_fmax_include_depth_:
516 4 : cpp_opts->max_include_depth = value;
517 4 : break;
518 :
519 4 : case OPT_foperator_names:
520 4 : cpp_opts->operator_names = value;
521 4 : break;
522 :
523 0 : case OPT_fpch_deps:
524 0 : cpp_opts->restore_pch_deps = value;
525 0 : break;
526 :
527 498 : case OPT_fpch_preprocess:
528 498 : flag_pch_preprocess = value;
529 498 : break;
530 :
531 1152 : case OPT_fpermissive:
532 1152 : flag_permissive = value;
533 1152 : global_dc->m_permissive = value;
534 1152 : break;
535 :
536 550 : case OPT_fpreprocessed:
537 550 : cpp_opts->preprocessed = value;
538 550 : break;
539 :
540 2 : case OPT_fdebug_cpp:
541 2 : cpp_opts->debug = value;
542 2 : break;
543 :
544 1 : case OPT_ftrack_macro_expansion:
545 1 : if (value)
546 0 : value = 2;
547 : /* Fall Through. */
548 :
549 483 : case OPT_ftrack_macro_expansion_:
550 483 : if (arg && *arg != '\0')
551 482 : cpp_opts->track_macro_expansion = value;
552 : else
553 1 : cpp_opts->track_macro_expansion = 2;
554 : break;
555 :
556 135 : case OPT_fexec_charset_:
557 135 : cpp_opts->narrow_charset = arg;
558 135 : break;
559 :
560 2 : case OPT_fwide_exec_charset_:
561 2 : cpp_opts->wide_charset = arg;
562 2 : break;
563 :
564 106 : case OPT_finput_charset_:
565 106 : cpp_opts->input_charset = arg;
566 106 : cpp_opts->cpp_input_charset_explicit = 1;
567 106 : break;
568 :
569 29 : case OPT_ftemplate_depth_:
570 29 : max_tinst_depth = value;
571 29 : break;
572 :
573 21 : case OPT_fvisibility_inlines_hidden:
574 21 : visibility_options.inlines_hidden = value;
575 21 : break;
576 :
577 22 : case OPT_femit_struct_debug_baseonly:
578 22 : set_struct_debug_option (&global_options, loc, "base");
579 22 : break;
580 :
581 8 : case OPT_femit_struct_debug_reduced:
582 8 : set_struct_debug_option (&global_options, loc,
583 : "dir:ord:sys,dir:gen:any,ind:base");
584 8 : break;
585 :
586 12 : case OPT_femit_struct_debug_detailed_:
587 12 : set_struct_debug_option (&global_options, loc, arg);
588 12 : break;
589 :
590 17 : case OPT_fext_numeric_literals:
591 17 : cpp_opts->ext_numeric_literals = value;
592 17 : break;
593 :
594 4 : case OPT_idirafter:
595 4 : add_path (xstrdup (arg), INC_AFTER, 0, true);
596 4 : break;
597 :
598 9680 : case OPT_imacros:
599 9680 : case OPT_include:
600 9680 : defer_opt (code, arg);
601 9680 : break;
602 :
603 5344 : case OPT_imultilib:
604 5344 : imultilib = arg;
605 5344 : break;
606 :
607 212337 : case OPT_iprefix:
608 212337 : iprefix = arg;
609 212337 : break;
610 :
611 2918 : case OPT_iquote:
612 2918 : add_path (xstrdup (arg), INC_QUOTE, 0, true);
613 2918 : break;
614 :
615 0 : case OPT_isysroot:
616 0 : sysroot = arg;
617 0 : break;
618 :
619 475379 : case OPT_isystem:
620 475379 : add_path (xstrdup (arg), INC_SYSTEM, 0, true);
621 475379 : break;
622 :
623 0 : case OPT_iwithprefix:
624 0 : add_prefixed_path (arg, INC_SYSTEM);
625 0 : break;
626 :
627 0 : case OPT_iwithprefixbefore:
628 0 : add_prefixed_path (arg, INC_BRACKET);
629 0 : break;
630 :
631 94 : case OPT__embed_dir_:
632 94 : add_path (xstrdup (arg), INC_EMBED, 0, true);
633 94 : break;
634 :
635 981 : case OPT_lang_asm:
636 981 : cpp_set_lang (parse_in, CLK_ASM);
637 981 : cpp_opts->dollars_in_ident = false;
638 981 : break;
639 :
640 60 : case OPT_nostdinc:
641 60 : std_inc = false;
642 60 : break;
643 :
644 113187 : case OPT_nostdinc__:
645 113187 : std_cxx_inc = false;
646 113187 : break;
647 :
648 214986 : case OPT_o:
649 214986 : if (!out_fname)
650 214986 : out_fname = arg;
651 : else
652 0 : error ("output filename specified twice");
653 : break;
654 :
655 0 : case OPT_print_objc_runtime_info:
656 0 : print_struct_values = 1;
657 0 : break;
658 :
659 2 : case OPT_remap:
660 2 : cpp_opts->remap = 1;
661 2 : break;
662 :
663 14256 : case OPT_std_c__98:
664 14256 : case OPT_std_gnu__98:
665 14256 : if (!preprocessing_asm_p)
666 14256 : set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
667 : break;
668 :
669 5790 : case OPT_std_c__11:
670 5790 : case OPT_std_gnu__11:
671 5790 : if (!preprocessing_asm_p)
672 5790 : set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
673 : break;
674 :
675 1339 : case OPT_std_c__14:
676 1339 : case OPT_std_gnu__14:
677 1339 : if (!preprocessing_asm_p)
678 1339 : set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
679 : break;
680 :
681 4273 : case OPT_std_c__17:
682 4273 : case OPT_std_gnu__17:
683 4273 : if (!preprocessing_asm_p)
684 4273 : set_std_cxx17 (code == OPT_std_c__17 /* ISO */);
685 : break;
686 :
687 32601 : case OPT_std_c__20:
688 32601 : case OPT_std_gnu__20:
689 32601 : if (!preprocessing_asm_p)
690 32601 : set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
691 : break;
692 :
693 2216 : case OPT_std_c__23:
694 2216 : case OPT_std_gnu__23:
695 2216 : if (!preprocessing_asm_p)
696 2216 : set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
697 : break;
698 :
699 1428 : case OPT_std_c__26:
700 1428 : case OPT_std_gnu__26:
701 1428 : if (!preprocessing_asm_p)
702 1428 : set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
703 : break;
704 :
705 24331 : case OPT_std_c__29:
706 24331 : case OPT_std_gnu__29:
707 24331 : if (!preprocessing_asm_p)
708 24331 : set_std_cxx29 (code == OPT_std_c__29 /* ISO */);
709 : break;
710 :
711 191 : case OPT_std_c90:
712 191 : case OPT_std_iso9899_199409:
713 191 : if (!preprocessing_asm_p)
714 191 : set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
715 : break;
716 :
717 2953 : case OPT_std_gnu90:
718 2953 : if (!preprocessing_asm_p)
719 2953 : set_std_c89 (false /* c94 */, false /* ISO */);
720 : break;
721 :
722 588 : case OPT_std_c99:
723 588 : if (!preprocessing_asm_p)
724 587 : set_std_c99 (true /* ISO */);
725 : break;
726 :
727 640 : case OPT_std_gnu99:
728 640 : if (!preprocessing_asm_p)
729 640 : set_std_c99 (false /* ISO */);
730 : break;
731 :
732 515 : case OPT_std_c11:
733 515 : if (!preprocessing_asm_p)
734 515 : set_std_c11 (true /* ISO */);
735 : break;
736 :
737 3725 : case OPT_std_gnu11:
738 3725 : if (!preprocessing_asm_p)
739 3725 : set_std_c11 (false /* ISO */);
740 : break;
741 :
742 43 : case OPT_std_c17:
743 43 : if (!preprocessing_asm_p)
744 43 : set_std_c17 (true /* ISO */);
745 : break;
746 :
747 778 : case OPT_std_gnu17:
748 778 : if (!preprocessing_asm_p)
749 778 : set_std_c17 (false /* ISO */);
750 : break;
751 :
752 982 : case OPT_std_c23:
753 982 : if (!preprocessing_asm_p)
754 982 : set_std_c23 (true /* ISO */);
755 : break;
756 :
757 213 : case OPT_std_gnu23:
758 213 : if (!preprocessing_asm_p)
759 213 : set_std_c23 (false /* ISO */);
760 : break;
761 :
762 205 : case OPT_std_c2y:
763 205 : if (!preprocessing_asm_p)
764 205 : set_std_c2y (true /* ISO */);
765 : break;
766 :
767 11 : case OPT_std_gnu2y:
768 11 : if (!preprocessing_asm_p)
769 11 : set_std_c2y (false /* ISO */);
770 : break;
771 :
772 21 : case OPT_trigraphs:
773 21 : cpp_opts->trigraphs = 1;
774 21 : break;
775 :
776 2927 : case OPT_traditional_cpp:
777 2927 : cpp_opts->traditional = 1;
778 2927 : break;
779 :
780 0 : case OPT_fsearch_include_path:
781 0 : cpp_opts->main_search = CMS_user;
782 0 : break;
783 :
784 6 : case OPT_fsearch_include_path_:
785 6 : if (!strcmp (arg, "user"))
786 0 : cpp_opts->main_search = CMS_user;
787 6 : else if (!strcmp (arg, "system"))
788 6 : cpp_opts->main_search = CMS_system;
789 : else
790 0 : error ("invalid argument %qs to %<-fsearch-include-path%>", arg);
791 : break;
792 :
793 114 : case OPT_v:
794 114 : verbose = true;
795 114 : break;
796 : }
797 :
798 3426623 : switch (c_language)
799 : {
800 1458197 : case clk_c:
801 1458197 : C_handle_option_auto (&global_options, &global_options_set,
802 : scode, arg, value,
803 : c_family_lang_mask, kind,
804 : loc, handlers, global_dc);
805 1458197 : break;
806 :
807 0 : case clk_objc:
808 0 : ObjC_handle_option_auto (&global_options, &global_options_set,
809 : scode, arg, value,
810 : c_family_lang_mask, kind,
811 : loc, handlers, global_dc);
812 0 : break;
813 :
814 1968426 : case clk_cxx:
815 1968426 : CXX_handle_option_auto (&global_options, &global_options_set,
816 : scode, arg, value,
817 : c_family_lang_mask, kind,
818 : loc, handlers, global_dc);
819 1968426 : break;
820 :
821 0 : case clk_objcxx:
822 0 : ObjCXX_handle_option_auto (&global_options, &global_options_set,
823 : scode, arg, value,
824 : c_family_lang_mask, kind,
825 : loc, handlers, global_dc);
826 0 : break;
827 :
828 0 : default:
829 0 : gcc_unreachable ();
830 : }
831 :
832 3426623 : cpp_handle_option_auto (&global_options, scode, cpp_opts);
833 3426623 : return result;
834 : }
835 :
836 : /* Default implementation of TARGET_HANDLE_C_OPTION. */
837 :
838 : bool
839 0 : default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
840 : const char *arg ATTRIBUTE_UNUSED,
841 : int value ATTRIBUTE_UNUSED)
842 : {
843 0 : return false;
844 : }
845 :
846 : /* Post-switch processing. */
847 : bool
848 215615 : c_common_post_options (const char **pfilename)
849 : {
850 : /* Canonicalize the input and output filenames. */
851 215615 : if (in_fnames == NULL)
852 : {
853 0 : in_fnames = XNEWVEC (const char *, 1);
854 0 : in_fnames[0] = "";
855 : }
856 215615 : else if (strcmp (in_fnames[0], "-") == 0)
857 : {
858 407 : if (pch_file)
859 0 : error ("cannot use %<-%> as input filename for a precompiled header");
860 :
861 407 : in_fnames[0] = "";
862 : }
863 :
864 215615 : if (out_fname == NULL || !strcmp (out_fname, "-"))
865 709 : out_fname = "";
866 :
867 215615 : if (cpp_opts->deps.style == DEPS_NONE)
868 209688 : check_deps_environment_vars ();
869 :
870 215615 : handle_deferred_opts ();
871 :
872 215615 : sanitize_cpp_opts ();
873 :
874 : /* Don't register include chains if under -fpreprocessed since we might not
875 : have correct sysroot this mode, and this may cause file permission
876 : issue. */
877 215615 : if (!cpp_opts->preprocessed)
878 215065 : register_include_chains (parse_in, sysroot, iprefix, imultilib,
879 215065 : std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
880 :
881 : #ifdef C_COMMON_OVERRIDE_OPTIONS
882 : /* Some machines may reject certain combinations of C
883 : language-specific options. */
884 : C_COMMON_OVERRIDE_OPTIONS;
885 : #endif
886 :
887 215615 : if (flag_excess_precision == EXCESS_PRECISION_DEFAULT)
888 367108 : flag_excess_precision = (flag_iso ? EXCESS_PRECISION_STANDARD
889 : : EXCESS_PRECISION_FAST);
890 :
891 : /* ISO C restricts floating-point expression contraction to within
892 : source-language expressions (-ffp-contract=on, currently an alias
893 : for -ffp-contract=off). */
894 215615 : if (flag_iso
895 60794 : && !c_dialect_cxx ()
896 6352 : && (OPTION_SET_P (flag_fp_contract_mode)
897 : == (enum fp_contract_mode) 0)
898 6352 : && flag_unsafe_math_optimizations == 0)
899 6347 : flag_fp_contract_mode = FP_CONTRACT_OFF;
900 :
901 : /* C language modes before C99 enable -fpermissive by default, but
902 : only if -pedantic-errors is not specified. Also treat
903 : -fno-permissive as a subset of -pedantic-errors that does not
904 : reject certain GNU extensions also present the defaults for later
905 : language modes. */
906 215615 : if (!c_dialect_cxx ()
907 114555 : && !flag_isoc99
908 6973 : && !global_dc->m_pedantic_errors
909 5938 : && !OPTION_SET_P (flag_permissive))
910 : {
911 5937 : flag_permissive = 1;
912 5937 : global_dc->m_permissive = 1;
913 : }
914 :
915 : /* If we are compiling C, and we are outside of a standards mode,
916 : we can permit the new values from ISO/IEC TS 18661-3 for
917 : FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
918 : the set specified in ISO C99/C11. */
919 215615 : if (!flag_iso
920 154821 : && !c_dialect_cxx ()
921 108203 : && (OPTION_SET_P (flag_permitted_flt_eval_methods)
922 : == PERMITTED_FLT_EVAL_METHODS_DEFAULT))
923 108202 : flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_TS_18661;
924 : else
925 107413 : flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
926 :
927 215615 : if (cxx_dialect >= cxx26)
928 : {
929 25713 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
930 : flag_auto_var_init, AUTO_INIT_CXX26);
931 25713 : if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED)
932 25709 : flag_auto_var_init
933 25709 : = auto_init_type (flag_auto_var_init | AUTO_INIT_CXX26);
934 : }
935 :
936 : /* The -Wtrivial-auto-var-init warning is useless for C++, where we always
937 : add .DEFERRED_INIT calls when some (vacuous) initializers are bypassed
938 : through jumps from switch condition to case/default label. */
939 215615 : if (c_dialect_cxx ())
940 101060 : warn_trivial_auto_var_init = 0;
941 :
942 : /* C23 Annex F does not permit certain built-in functions to raise
943 : "inexact". */
944 215615 : if (flag_isoc23)
945 101294 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
946 : flag_fp_int_builtin_inexact, 0);
947 :
948 : /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
949 : inline semantics are not supported in GNU89 or C89 mode. */
950 215615 : if (flag_gnu89_inline == -1)
951 215171 : flag_gnu89_inline = !flag_isoc99;
952 444 : else if (!flag_gnu89_inline && !flag_isoc99)
953 1 : error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
954 :
955 : /* Default to ObjC sjlj exception handling if NeXT runtime < v2. */
956 215615 : if (flag_objc_sjlj_exceptions < 0)
957 431230 : flag_objc_sjlj_exceptions = (flag_next_runtime && flag_objc_abi < 2);
958 215615 : if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
959 0 : flag_exceptions = 1;
960 :
961 : /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
962 : pattern recognition. */
963 215615 : if (flag_no_builtin)
964 784 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
965 : flag_tree_loop_distribute_patterns, 0);
966 :
967 : /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
968 : It is never enabled in C++, as the minimum limit is not normative
969 : in that standard. */
970 215615 : if (c_dialect_cxx ())
971 101060 : warn_overlength_strings = 0;
972 :
973 : /* Wmain is enabled by default in C++ but not in C. */
974 : /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
975 : even if -Wall or -Wpedantic was given (warn_main will be 2 if set
976 : by -Wall, 1 if set by -Wmain). */
977 215615 : if (warn_main == -1)
978 259670 : warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
979 59058 : else if (warn_main == 2)
980 58707 : warn_main = flag_hosted ? 1 : 0;
981 :
982 : /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
983 : yet been set, it is disabled by default. In C++, it is enabled
984 : by default. */
985 215615 : if (warn_enum_compare == -1)
986 205971 : warn_enum_compare = c_dialect_cxx () ? 1 : 0;
987 :
988 : /* For C++26 default to -Wkeyword-macro if -Wpedantic. */
989 215615 : if (cxx_dialect >= cxx26 && pedantic)
990 : {
991 16264 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
992 : warn_keyword_macro, 1);
993 16264 : if (warn_keyword_macro)
994 16263 : cpp_opts->cpp_warn_keyword_macro = warn_keyword_macro;
995 : }
996 :
997 : /* -Wpacked-bitfield-compat is on by default for the C languages. The
998 : warning is issued in stor-layout.cc which is not part of the front-end so
999 : we need to selectively turn it on here. */
1000 215615 : if (warn_packed_bitfield_compat == -1)
1001 215607 : warn_packed_bitfield_compat = 1;
1002 :
1003 : /* Special format checking options don't work without -Wformat; warn if
1004 : they are used. */
1005 215615 : if (!warn_format)
1006 : {
1007 204211 : warning (OPT_Wformat_y2k,
1008 : "%<-Wformat-y2k%> ignored without %<-Wformat%>");
1009 204211 : warning (OPT_Wformat_extra_args,
1010 : "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
1011 204211 : warning (OPT_Wformat_zero_length,
1012 : "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
1013 204211 : warning (OPT_Wformat_nonliteral,
1014 : "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
1015 204211 : warning (OPT_Wformat_contains_nul,
1016 : "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
1017 204211 : warning (OPT_Wformat_security,
1018 : "%<-Wformat-security%> ignored without %<-Wformat%>");
1019 : }
1020 :
1021 : /* -Wimplicit-function-declaration is enabled by default for C99. */
1022 215615 : if (warn_implicit_function_declaration == -1)
1023 207163 : warn_implicit_function_declaration = flag_isoc99;
1024 :
1025 : /* -Wimplicit-int is enabled by default for C99. */
1026 215615 : if (warn_implicit_int == -1)
1027 207220 : warn_implicit_int = flag_isoc99;
1028 :
1029 : /* -Wold-style-definition is enabled by default for C23. */
1030 215615 : if (warn_old_style_definition == -1)
1031 211316 : warn_old_style_definition = flag_isoc23;
1032 :
1033 : /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
1034 215615 : if (warn_shift_overflow == -1)
1035 409822 : warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
1036 :
1037 : /* -Wmissing-parameter-name is enabled by -pedantic before C23,
1038 : and for -Wc11-c23-compat. */
1039 215615 : if (warn_missing_parameter_name == -1)
1040 215612 : warn_missing_parameter_name
1041 50348 : = ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
1042 266005 : || warn_c11_c23_compat > 0);
1043 :
1044 : /* Likewise for -Wfree-labels. */
1045 215615 : if (warn_free_labels == -1)
1046 50348 : warn_free_labels = ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
1047 266005 : || warn_c11_c23_compat > 0);
1048 :
1049 215615 : if (warn_deprecated_non_prototype == -1)
1050 215610 : warn_deprecated_non_prototype = warn_c11_c23_compat > 0;
1051 :
1052 : /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
1053 : modes. */
1054 215615 : if (warn_shift_negative_value == -1)
1055 431190 : warn_shift_negative_value = (extra_warnings
1056 7871 : && (cxx_dialect >= cxx11 || flag_isoc99)
1057 431556 : && cxx_dialect < cxx20);
1058 :
1059 : /* -Wregister is enabled by default in C++17. */
1060 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_register,
1061 : cxx_dialect >= cxx17);
1062 :
1063 : /* Explicit -Wdeprecated turns on warnings from later standards. */
1064 1685832 : auto deprecated_in = [&](enum cxx_dialect d)
1065 : {
1066 1470217 : if (OPTION_SET_P (warn_deprecated)) return !!warn_deprecated;
1067 1468729 : return (warn_deprecated && cxx_dialect >= d);
1068 : };
1069 :
1070 : /* -Wcomma-subscript is enabled by default in C++20. */
1071 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1072 : warn_comma_subscript,
1073 : cxx_dialect >= cxx23
1074 : || deprecated_in (cxx20));
1075 :
1076 : /* -Wvolatile is enabled by default in C++20. */
1077 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile,
1078 : deprecated_in (cxx20));
1079 :
1080 : /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */
1081 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1082 : warn_deprecated_enum_enum_conv,
1083 : deprecated_in (cxx20));
1084 :
1085 : /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */
1086 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1087 : warn_deprecated_enum_float_conv,
1088 : deprecated_in (cxx20));
1089 :
1090 : /* -Wdeprecated-literal-operator is enabled by default in C++23. */
1091 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1092 : warn_deprecated_literal_operator,
1093 : deprecated_in (cxx23));
1094 :
1095 : /* -Warray-compare is enabled by default in C++20. */
1096 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1097 : warn_array_compare,
1098 : warn_array_compare || deprecated_in (cxx20));
1099 :
1100 : /* -Wdeprecated-variadic-comma-omission is enabled by default in C++26. */
1101 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1102 : warn_deprecated_variadic_comma_omission,
1103 : deprecated_in (cxx26));
1104 :
1105 : /* -Wtemplate-id-cdtor is enabled by default in C++20. */
1106 292407 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1107 : warn_template_id_cdtor,
1108 : cxx_dialect >= cxx20 || warn_cxx20_compat);
1109 :
1110 : /* Declone C++ 'structors if -Os. */
1111 215615 : if (flag_declone_ctor_dtor == -1)
1112 215578 : flag_declone_ctor_dtor = optimize_size;
1113 :
1114 215615 : if (flag_abi_compat_version == 1)
1115 : {
1116 0 : warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
1117 0 : flag_abi_compat_version = 2;
1118 : }
1119 :
1120 : /* Change flag_abi_version to be the actual current ABI level, for the
1121 : benefit of c_cpp_builtins, and to make comparison simpler. */
1122 215615 : const int latest_abi_version = 21;
1123 : /* Possibly different for non-default ABI fixes within a release. */
1124 215615 : const int default_abi_version = latest_abi_version;
1125 : /* Generate compatibility aliases for ABI v18 (GCC 13) by default. */
1126 215615 : const int abi_compat_default = 18;
1127 :
1128 215615 : if (flag_abi_version > latest_abi_version)
1129 0 : warning (0, "%<-fabi-version=%d%> is not supported, using =%d",
1130 : flag_abi_version, latest_abi_version);
1131 :
1132 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1133 : flag_abi_version, default_abi_version);
1134 :
1135 : #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
1136 215615 : clamp (flag_abi_version);
1137 : /* Don't clamp warn_abi_version, let it be 0 or out of bounds. */
1138 215615 : clamp (flag_abi_compat_version);
1139 : #undef clamp
1140 :
1141 : /* Default -Wabi= or -fabi-compat-version= from each other. */
1142 215615 : if (warn_abi_version == -1 && flag_abi_compat_version != -1)
1143 197 : warn_abi_version = flag_abi_compat_version;
1144 215418 : else if (flag_abi_compat_version == -1 && warn_abi_version != -1)
1145 12763 : flag_abi_compat_version = warn_abi_version;
1146 202655 : else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
1147 : {
1148 202610 : warn_abi_version = 0;
1149 202610 : if (flag_abi_version == default_abi_version)
1150 202375 : flag_abi_compat_version = abi_compat_default;
1151 : else
1152 235 : flag_abi_compat_version = latest_abi_version;
1153 : }
1154 :
1155 : /* Allow warnings vs ABI versions beyond what we currently support. */
1156 215615 : if (warn_abi_version == 0)
1157 202625 : warn_abi_version = 1000;
1158 :
1159 : /* By default, enable the new inheriting constructor semantics along with ABI
1160 : 11. New and old should coexist fine, but it is a change in what
1161 : artificial symbols are generated. */
1162 430974 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1163 : flag_new_inheriting_ctors,
1164 : abi_version_at_least (11));
1165 :
1166 : /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
1167 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_new_ttp,
1168 : cxx_dialect >= cxx17);
1169 :
1170 : /* C++11 guarantees forward progress. */
1171 404942 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
1172 : optimize >= 2 && cxx_dialect >= cxx11);
1173 :
1174 : /* It's OK to discard calls to pure/const functions that might throw. */
1175 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1176 : flag_delete_dead_exceptions, true);
1177 :
1178 215615 : if (cxx_dialect >= cxx11)
1179 : {
1180 : /* If we're allowing C++0x constructs, don't warn about C++98
1181 : identifiers which are keywords in C++0x. */
1182 86728 : warn_cxx11_compat = 0;
1183 86728 : cpp_opts->cpp_warn_cxx11_compat = 0;
1184 :
1185 86728 : if (warn_narrowing == -1)
1186 84505 : warn_narrowing = 1;
1187 :
1188 : /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
1189 : for -std=c++{11,14,17,20,23,26} default to
1190 : -fno-ext-numeric-literals. */
1191 86728 : if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
1192 45477 : cpp_opts->ext_numeric_literals = 0;
1193 : }
1194 128887 : else if (warn_narrowing == -1)
1195 128391 : warn_narrowing = 0;
1196 :
1197 215615 : if (cxx_dialect >= cxx20)
1198 : {
1199 : /* Don't warn about C++20 compatibility changes in C++20 or later. */
1200 75364 : warn_cxx20_compat = 0;
1201 75364 : cpp_opts->cpp_warn_cxx20_compat = 0;
1202 : }
1203 215615 : if (cxx_dialect >= cxx26)
1204 : /* Don't warn about C++26 compatibility changes in C++26 or later. */
1205 25713 : warn_cxx26_compat = 0;
1206 :
1207 : /* C++17 has stricter evaluation order requirements; let's use some of them
1208 : for earlier C++ as well, so chaining works as expected. */
1209 215615 : if (c_dialect_cxx ()
1210 101060 : && flag_strong_eval_order == -1)
1211 122472 : flag_strong_eval_order = (cxx_dialect >= cxx17 ? 2 : 1);
1212 :
1213 215615 : if (flag_implicit_constexpr && cxx_dialect < cxx14)
1214 0 : flag_implicit_constexpr = false;
1215 :
1216 : /* Global sized deallocation is new in C++14. */
1217 215615 : if (flag_sized_deallocation == -1)
1218 215608 : flag_sized_deallocation = (cxx_dialect >= cxx14);
1219 :
1220 : /* Pedwarn about invalid constexpr functions before C++23. */
1221 215615 : if (warn_invalid_constexpr == -1)
1222 215595 : warn_invalid_constexpr = (cxx_dialect < cxx23);
1223 :
1224 : /* char8_t support is implicitly enabled in C++20 and C23. */
1225 215615 : if (flag_char8_t == -1)
1226 392108 : flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc23;
1227 215615 : cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char;
1228 :
1229 215615 : cpp_opts->cpp_tabstop = global_dc->get_column_options ().m_tabstop;
1230 :
1231 215615 : if (flag_extern_tls_init)
1232 : {
1233 215613 : if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
1234 : {
1235 : /* Lazy TLS initialization for a variable in another TU requires
1236 : alias and weak reference support. */
1237 : if (flag_extern_tls_init > 0)
1238 : sorry ("external TLS initialization functions not supported "
1239 : "on this target");
1240 :
1241 : flag_extern_tls_init = 0;
1242 : }
1243 : else
1244 215613 : flag_extern_tls_init = 1;
1245 : }
1246 :
1247 : /* Enable by default only for C++ and C++ with ObjC extensions. */
1248 215615 : if (warn_return_type == -1 && c_dialect_cxx ())
1249 97483 : warn_return_type = 1;
1250 :
1251 : /* C++20 is the final version of concepts. We still use -fconcepts
1252 : to know when concepts are enabled. */
1253 215615 : if (cxx_dialect >= cxx20)
1254 75364 : flag_concepts = 1;
1255 :
1256 : /* Coroutines are also a C++20 feature. */
1257 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1258 : flag_coroutines, cxx_dialect >= cxx20);
1259 :
1260 : /* Enable lifetime extension of range based for temporaries for C++23. */
1261 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1262 : flag_range_for_ext_temps, cxx_dialect >= cxx23);
1263 :
1264 : /* Contracts are in C++26. Keep lang_specific_driver in sync. */
1265 215615 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1266 : flag_contracts, cxx_dialect >= cxx26);
1267 :
1268 : /* EnabledBy unfortunately can't specify value to use if set and
1269 : LangEnabledBy can't specify multiple options with &&. For -Wunused
1270 : or -Wunused -Wextra we want these to default to 3 unless user specified
1271 : some other level explicitly. */
1272 215615 : if (warn_unused_but_set_parameter == 1)
1273 7715 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1274 : warn_unused_but_set_parameter, 3);
1275 215615 : if (warn_unused_but_set_variable == 1)
1276 10603 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1277 : warn_unused_but_set_variable, 3);
1278 :
1279 : /* -fimmediate-escalation has no effect when immediate functions are not
1280 : supported. */
1281 215615 : if (flag_immediate_escalation && cxx_dialect < cxx20)
1282 140251 : flag_immediate_escalation = 0;
1283 :
1284 215615 : if (flag_reflection && cxx_dialect < cxx26)
1285 0 : error ("%<-freflection%> only supported with %<-std=c++26%> or "
1286 : "%<-std=gnu++26%>");
1287 :
1288 215615 : if (num_in_fnames > 1)
1289 0 : error ("too many filenames given; type %<%s %s%> for usage",
1290 : progname, "--help");
1291 :
1292 215615 : if (flag_preprocess_only)
1293 : {
1294 : /* Open the output now. We must do so even if flag_no_output is
1295 : on, because there may be other output than from the actual
1296 : preprocessing (e.g. from -dM). */
1297 7229 : if (out_fname[0] == '\0')
1298 709 : out_stream = stdout;
1299 : else
1300 6520 : out_stream = fopen (out_fname, "w");
1301 :
1302 7229 : if (out_stream == NULL)
1303 0 : fatal_error (input_location, "opening output file %s: %m", out_fname);
1304 :
1305 7229 : init_pp_output (out_stream);
1306 : }
1307 : else
1308 : {
1309 208386 : init_c_lex ();
1310 :
1311 : /* When writing a PCH file, avoid reading some other PCH file,
1312 : because the default address space slot then can't be used
1313 : for the output PCH file. */
1314 208386 : if (pch_file)
1315 : {
1316 428 : c_common_no_more_pch ();
1317 : /* Only -g0 and -gdwarf* are supported with PCH, for other
1318 : debug formats we warn here and refuse to load any PCH files. */
1319 428 : if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1320 0 : warning (OPT_Wdeprecated,
1321 : "the %qs debug info cannot be used with "
1322 : "pre-compiled headers",
1323 : debug_set_names (write_symbols & ~DWARF2_DEBUG));
1324 : /* Let libcpp know that the main file is a header so it won't
1325 : complain about things like #include_next and #pragma once. */
1326 428 : cpp_opts->main_search = CMS_header;
1327 : }
1328 207958 : else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1329 336 : c_common_no_more_pch ();
1330 :
1331 : /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1332 208386 : input_location = UNKNOWN_LOCATION;
1333 : }
1334 :
1335 215615 : struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
1336 215615 : cb->file_change = cb_file_change;
1337 215615 : cb->dir_change = cb_dir_change;
1338 215615 : if (lang_hooks.preprocess_options)
1339 101060 : lang_hooks.preprocess_options (parse_in);
1340 215615 : cpp_post_options (parse_in);
1341 215615 : init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
1342 : /* For C++23 and explicit -finput-charset=UTF-8, turn on -Winvalid-utf8
1343 : by default and make it a pedwarn unless -Wno-invalid-utf8. */
1344 215615 : if (cxx_dialect >= cxx23
1345 27926 : && cpp_opts->cpp_input_charset_explicit
1346 28 : && strcmp (cpp_opts->input_charset, "UTF-8") == 0
1347 26 : && (cpp_opts->cpp_warn_invalid_utf8
1348 21 : || !global_options_set.x_warn_invalid_utf8))
1349 : {
1350 23 : global_options.x_warn_invalid_utf8 = 1;
1351 34 : cpp_opts->cpp_warn_invalid_utf8 = cpp_opts->cpp_pedantic ? 2 : 1;
1352 : }
1353 :
1354 : /* Let diagnostics infrastructure know how to convert input files the same
1355 : way libcpp will do it, namely using the configured input charset and
1356 : skipping a UTF-8 BOM if present. */
1357 215615 : diagnostic_initialize_input_context (global_dc,
1358 : c_common_input_charset_cb, true);
1359 215615 : input_location = UNKNOWN_LOCATION;
1360 :
1361 431230 : *pfilename = this_input_filename
1362 431230 : = cpp_read_main_file (parse_in, in_fnames[0],
1363 : /* We'll inject preamble pieces if this is
1364 : not preprocessed. */
1365 215615 : !cpp_opts->preprocessed);
1366 :
1367 : /* Don't do any compilation or preprocessing if there is no input file. */
1368 215615 : if (this_input_filename == NULL)
1369 : {
1370 0 : errorcount++;
1371 0 : return false;
1372 : }
1373 :
1374 215615 : if (flag_working_directory
1375 42169 : && flag_preprocess_only && !flag_no_line_commands)
1376 2258 : pp_dir_change (parse_in, get_src_pwd ());
1377 :
1378 : /* Disable LTO output when outputting a precompiled header. */
1379 215615 : if (pch_file && flag_lto)
1380 : {
1381 0 : flag_lto = 0;
1382 0 : flag_generate_lto = 0;
1383 : }
1384 :
1385 215615 : return flag_preprocess_only;
1386 : }
1387 :
1388 : /* Front end initialization common to C, ObjC and C++. */
1389 : bool
1390 215401 : c_common_init (void)
1391 : {
1392 : /* Set up preprocessor arithmetic. Must be done after call to
1393 : c_common_nodes_and_builtins for type nodes to be good. */
1394 215401 : cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1395 215401 : cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1396 215401 : cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1397 215401 : cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1398 215401 : cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1399 215401 : cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1400 :
1401 : /* This can't happen until after wchar_precision and bytes_big_endian
1402 : are known. */
1403 215401 : cpp_init_iconv (parse_in);
1404 :
1405 215401 : if (version_flag)
1406 : {
1407 111 : int i;
1408 111 : fputs ("Compiler executable checksum: ", stderr);
1409 1998 : for (i = 0; i < 16; i++)
1410 1776 : fprintf (stderr, "%02x", executable_checksum[i]);
1411 111 : putc ('\n', stderr);
1412 : }
1413 :
1414 : /* Has to wait until now so that cpplib has its hash table. */
1415 215401 : init_pragma ();
1416 :
1417 215401 : if (flag_preprocess_only)
1418 : {
1419 7224 : c_init_preprocess ();
1420 7224 : c_finish_options ();
1421 7224 : preprocess_file (parse_in);
1422 7224 : return false;
1423 : }
1424 :
1425 : return true;
1426 : }
1427 :
1428 : /* Initialize the integrated preprocessor after debug output has been
1429 : initialized; loop over each input file. */
1430 : void
1431 208177 : c_common_parse_file (void)
1432 : {
1433 208177 : auto dumps = g->get_dumps ();
1434 208177 : for (unsigned int i = 0;;)
1435 : {
1436 208177 : c_finish_options ();
1437 : /* Open the dump file to use for the original dump output
1438 : here, to be used during parsing for the current file. */
1439 208177 : dumps->dump_start (TDI_original, &dump_flags);
1440 208177 : pch_init ();
1441 208177 : push_file_scope ();
1442 208177 : c_parse_file ();
1443 207885 : pop_file_scope ();
1444 : /* And end the main input file, if the debug writer wants it */
1445 207885 : if (debug_hooks->start_end_main_source_file)
1446 39721 : (*debug_hooks->end_source_file) (0);
1447 207885 : if (++i >= num_in_fnames)
1448 : break;
1449 0 : cpp_undef_all (parse_in);
1450 0 : cpp_clear_file_cache (parse_in);
1451 0 : this_input_filename
1452 0 : = cpp_read_main_file (parse_in, in_fnames[i]);
1453 : /* If an input file is missing, abandon further compilation.
1454 : cpplib has issued a diagnostic. */
1455 0 : if (!this_input_filename)
1456 : break;
1457 0 : dumps->dump_finish (TDI_original);
1458 : }
1459 :
1460 207885 : c_parse_final_cleanups ();
1461 207871 : dumps->dump_finish (TDI_original);
1462 207871 : }
1463 :
1464 : /* Common finish hook for the C, ObjC and C++ front ends. */
1465 : void
1466 214900 : c_common_finish (void)
1467 : {
1468 214900 : FILE *deps_stream = NULL;
1469 214900 : FILE *fdeps_stream = NULL;
1470 :
1471 : /* Note that we write the dependencies even if there are errors. This is
1472 : useful for handling outdated generated headers that now trigger errors
1473 : (for example, with #error) which would be resolved by re-generating
1474 : them. In a sense, this complements -MG. */
1475 214900 : if (cpp_opts->deps.style != DEPS_NONE)
1476 : {
1477 : /* If -M or -MM was seen without -MF, default output to the
1478 : output stream. */
1479 5922 : if (!deps_file)
1480 25 : deps_stream = out_stream;
1481 5897 : else if (deps_file[0] == '-' && deps_file[1] == '\0')
1482 0 : deps_stream = stdout;
1483 : else
1484 : {
1485 11794 : deps_stream = fopen (deps_file, deps_append ? "a" : "w");
1486 5897 : if (!deps_stream)
1487 0 : fatal_error (input_location, "opening dependency file %s: %m",
1488 : deps_file);
1489 : }
1490 : }
1491 :
1492 : /* When we call cpp_finish (), it may generate some diagnostics using
1493 : locations it remembered from the preprocessing phase, e.g. for
1494 : -Wunused-macros. So inform c_cpp_diagnostic () not to override those
1495 : locations with input_location, which would be incorrect now. */
1496 214900 : override_libcpp_locations = false;
1497 :
1498 214900 : if (cpp_opts->deps.fdeps_format != FDEPS_FMT_NONE)
1499 : {
1500 36 : if (!fdeps_file)
1501 0 : fdeps_stream = out_stream;
1502 36 : else if (fdeps_file[0] == '-' && fdeps_file[1] == '\0')
1503 0 : fdeps_stream = stdout;
1504 : else
1505 : {
1506 36 : fdeps_stream = fopen (fdeps_file, "w");
1507 36 : if (!fdeps_stream)
1508 0 : fatal_error (input_location, "opening dependency file %s: %m",
1509 : fdeps_file);
1510 : }
1511 36 : if (fdeps_stream == deps_stream && fdeps_stream != stdout)
1512 0 : fatal_error (input_location, "%<-MF%> and %<-fdeps-file=%> cannot share an output file %s: %m",
1513 0 : fdeps_file ? fdeps_file : out_fname);
1514 : }
1515 :
1516 : /* For performance, avoid tearing down cpplib's internal structures
1517 : with cpp_destroy (). */
1518 214900 : cpp_finish (parse_in, deps_stream, fdeps_stream);
1519 :
1520 5922 : if (deps_stream && deps_stream != out_stream && deps_stream != stdout
1521 220797 : && (ferror (deps_stream) || fclose (deps_stream)))
1522 0 : fatal_error (input_location, "closing dependency file %s: %m", deps_file);
1523 :
1524 214900 : if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1525 0 : fatal_error (input_location, "when writing output to %s: %m", out_fname);
1526 214900 : }
1527 :
1528 : /* Either of two environment variables can specify output of
1529 : dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1530 : DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1531 : and DEPS_TARGET is the target to mention in the deps. They also
1532 : result in dependency information being appended to the output file
1533 : rather than overwriting it, and like Sun's compiler
1534 : SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1535 : static void
1536 209688 : check_deps_environment_vars (void)
1537 : {
1538 209688 : char *spec;
1539 :
1540 209688 : spec = getenv ("DEPENDENCIES_OUTPUT");
1541 209688 : if (spec)
1542 0 : cpp_opts->deps.style = DEPS_USER;
1543 : else
1544 : {
1545 209688 : spec = getenv ("SUNPRO_DEPENDENCIES");
1546 209688 : if (spec)
1547 : {
1548 0 : cpp_opts->deps.style = DEPS_SYSTEM;
1549 0 : cpp_opts->deps.ignore_main_file = true;
1550 : }
1551 : }
1552 :
1553 0 : if (spec)
1554 : {
1555 : /* Find the space before the DEPS_TARGET, if there is one. */
1556 0 : char *s = strchr (spec, ' ');
1557 0 : if (s)
1558 : {
1559 : /* Let the caller perform MAKE quoting. */
1560 0 : defer_opt (OPT_MT, s + 1);
1561 0 : *s = '\0';
1562 : }
1563 :
1564 : /* Command line -MF overrides environment variables and default. */
1565 0 : if (!deps_file)
1566 0 : deps_file = spec;
1567 :
1568 0 : deps_append = 1;
1569 0 : deps_seen = true;
1570 : }
1571 209688 : }
1572 :
1573 : /* Handle deferred command line switches. */
1574 : static void
1575 215615 : handle_deferred_opts (void)
1576 : {
1577 : /* Avoid allocating the deps buffer if we don't need it.
1578 : (This flag may be true without there having been -MT or -MQ
1579 : options, but we'll still need the deps buffer.) */
1580 215615 : if (!deps_seen)
1581 : return;
1582 :
1583 5926 : if (mkdeps *deps = cpp_get_deps (parse_in))
1584 35050 : for (unsigned i = 0; i < deferred_count; i++)
1585 : {
1586 29148 : struct deferred_opt *opt = &deferred_opts[i];
1587 :
1588 29148 : if (opt->code == OPT_MT || opt->code == OPT_MQ)
1589 5892 : deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1590 23256 : else if (opt->code == OPT_fdeps_target_)
1591 42 : fdeps_add_target (deps, opt->arg, true);
1592 : }
1593 : }
1594 :
1595 : /* These settings are appropriate for GCC, but not necessarily so for
1596 : cpplib as a library. */
1597 : static void
1598 215615 : sanitize_cpp_opts (void)
1599 : {
1600 : /* If we don't know what style of dependencies to output, complain
1601 : if any other dependency switches have been given. */
1602 215615 : if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1603 24 : error ("to generate dependencies you must specify either %<-M%> "
1604 : "or %<-MM%>");
1605 :
1606 : /* -dM and dependencies suppress normal output; do it here so that
1607 : the last -d[MDN] switch overrides earlier ones. */
1608 215615 : if (flag_dump_macros == 'M')
1609 80 : flag_no_output = 1;
1610 :
1611 : /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1612 : to perform proper macro expansion. */
1613 215615 : if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1614 80 : flag_dump_macros = 'D';
1615 :
1616 : /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1617 : -dM since at least glibc relies on -M -dM to work. */
1618 : /* Also, flag_no_output implies flag_no_line_commands, always. */
1619 215615 : if (flag_no_output)
1620 : {
1621 110 : if (flag_dump_macros != 'M')
1622 30 : flag_dump_macros = 0;
1623 110 : flag_dump_includes = 0;
1624 110 : flag_no_line_commands = 1;
1625 : }
1626 215505 : else if (cpp_opts->deps.missing_files)
1627 1 : error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
1628 :
1629 215615 : cpp_opts->unsigned_char = !flag_signed_char;
1630 215615 : cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1631 :
1632 : /* Wlong-long is disabled by default. It is enabled by:
1633 : [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1634 : [-Wpedantic | -Wtraditional] -std=non-c99
1635 :
1636 : Either -Wlong-long or -Wno-long-long override any other settings.
1637 : ??? These conditions should be handled in c.opt. */
1638 215615 : if (warn_long_long == -1)
1639 : {
1640 164512 : warn_long_long = ((pedantic || warn_traditional)
1641 168346 : && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1642 168322 : cpp_opts->cpp_warn_long_long = warn_long_long;
1643 : }
1644 :
1645 : /* If we're generating preprocessor output, emit current directory
1646 : if explicitly requested or if debugging information is enabled.
1647 : ??? Maybe we should only do it for debugging formats that
1648 : actually output the current directory? */
1649 215615 : if (flag_working_directory == -1)
1650 214307 : flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1651 :
1652 215615 : if (warn_implicit_fallthrough < 5)
1653 215615 : cpp_opts->cpp_warn_implicit_fallthrough = warn_implicit_fallthrough;
1654 : else
1655 4 : cpp_opts->cpp_warn_implicit_fallthrough = 0;
1656 :
1657 215615 : if (cpp_opts->directives_only)
1658 : {
1659 121 : if (cpp_warn_unused_macros)
1660 4 : error ("%<-fdirectives-only%> is incompatible "
1661 : "with %<-Wunused-macros%>");
1662 121 : if (cpp_opts->traditional)
1663 1 : error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
1664 : }
1665 215615 : }
1666 :
1667 : /* Add include path with a prefix at the front of its name. */
1668 : static void
1669 0 : add_prefixed_path (const char *suffix, incpath_kind chain)
1670 : {
1671 0 : char *path;
1672 0 : const char *prefix;
1673 0 : size_t prefix_len, suffix_len;
1674 :
1675 0 : suffix_len = strlen (suffix);
1676 0 : prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1677 0 : prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1678 :
1679 0 : path = (char *) xmalloc (prefix_len + suffix_len + 1);
1680 0 : memcpy (path, prefix, prefix_len);
1681 0 : memcpy (path + prefix_len, suffix, suffix_len);
1682 0 : path[prefix_len + suffix_len] = '\0';
1683 :
1684 0 : add_path (path, chain, 0, false);
1685 0 : }
1686 :
1687 : /* Handle -D, -U, -A, -imacros, and the first -include. */
1688 : static void
1689 215401 : c_finish_options (void)
1690 : {
1691 215401 : if (!cpp_opts->preprocessed)
1692 : {
1693 214851 : const line_map_ordinary *bltin_map
1694 214851 : = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1695 : special_fname_builtin (), 0));
1696 214851 : cb_file_change (parse_in, bltin_map);
1697 214851 : linemap_line_start (line_table, 0, 1);
1698 :
1699 : /* Make sure all of the builtins about to be declared have
1700 : BUILTINS_LOCATION has their location_t. */
1701 214851 : cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
1702 :
1703 214851 : cpp_init_builtins (parse_in, flag_hosted);
1704 214851 : c_cpp_builtins (parse_in);
1705 :
1706 : /* We're about to send user input to cpplib, so make it warn for
1707 : things that we previously (when we sent it internal definitions)
1708 : told it to not warn.
1709 :
1710 : C99 permits implementation-defined characters in identifiers.
1711 : The documented meaning of -std= is to turn off extensions that
1712 : conflict with the specified standard, and since a strictly
1713 : conforming program cannot contain a '$', we do not condition
1714 : their acceptance on the -std= setting. */
1715 214851 : cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1716 :
1717 214851 : const line_map_ordinary *cmd_map
1718 214851 : = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1719 214851 : _("<command-line>"), 0));
1720 214851 : cb_file_change (parse_in, cmd_map);
1721 214851 : linemap_line_start (line_table, 0, 1);
1722 :
1723 214851 : bool fortify_seen_p = false;
1724 214851 : bool cxx_assert_seen_p = false;
1725 :
1726 : /* All command line defines must have the same location. */
1727 214851 : line_table->cmdline_location = line_table->highest_line;
1728 214851 : cpp_force_token_locations (parse_in, line_table->highest_line);
1729 613397 : for (size_t i = 0; i < deferred_count; i++)
1730 : {
1731 183695 : struct deferred_opt *opt = &deferred_opts[i];
1732 :
1733 183695 : if (opt->code == OPT_D)
1734 168011 : cpp_define (parse_in, opt->arg);
1735 15684 : else if (opt->code == OPT_U)
1736 61 : cpp_undef (parse_in, opt->arg);
1737 15623 : else if (opt->code == OPT_A)
1738 : {
1739 10 : if (opt->arg[0] == '-')
1740 2 : cpp_unassert (parse_in, opt->arg + 1);
1741 : else
1742 8 : cpp_assert (parse_in, opt->arg);
1743 : }
1744 :
1745 183695 : if (UNLIKELY (flag_hardened)
1746 83 : && (opt->code == OPT_D || opt->code == OPT_U))
1747 : {
1748 83 : if (!fortify_seen_p)
1749 79 : fortify_seen_p
1750 79 : = (!strncmp (opt->arg, "_FORTIFY_SOURCE", 15)
1751 79 : && (opt->arg[15] == '\0' || opt->arg[15] == '='));
1752 83 : if (!cxx_assert_seen_p)
1753 83 : cxx_assert_seen_p
1754 83 : = (!strncmp (opt->arg, "_GLIBCXX_ASSERTIONS", 19)
1755 83 : && (opt->arg[19] == '\0' || opt->arg[19] == '='));
1756 : }
1757 : }
1758 :
1759 214851 : if (flag_hardened)
1760 : {
1761 92 : if (!fortify_seen_p && optimize > 0)
1762 72 : cpp_define_formatted (parse_in, "_FORTIFY_SOURCE=%u",
1763 72 : targetm.fortify_source_default_level ());
1764 20 : else if (optimize == 0)
1765 20 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1766 : "%<_FORTIFY_SOURCE%> is not enabled by %<-fhardened%> "
1767 : "because optimizations are turned off");
1768 : else
1769 0 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1770 : "%<_FORTIFY_SOURCE%> is not enabled by %<-fhardened%> "
1771 : "because it was specified in %<-D%> or %<-U%>");
1772 92 : if (!cxx_assert_seen_p)
1773 88 : cpp_define (parse_in, "_GLIBCXX_ASSERTIONS");
1774 : else
1775 4 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1776 : "%<_GLIBCXX_ASSERTIONS%> is not enabled by "
1777 : "%<-fhardened%> because it was specified in %<-D%> "
1778 : "or %<-U%>");
1779 : }
1780 :
1781 214851 : cpp_stop_forcing_token_locations (parse_in);
1782 : }
1783 550 : else if (cpp_opts->directives_only)
1784 41 : cpp_init_special_builtins (parse_in);
1785 :
1786 : /* Start the main input file, if the debug writer wants it. */
1787 215401 : if (debug_hooks->start_end_main_source_file
1788 42100 : && !flag_preprocess_only)
1789 39838 : (*debug_hooks->start_source_file) (0, this_input_filename);
1790 :
1791 215401 : if (!cpp_opts->preprocessed)
1792 : /* Handle -imacros after -D and -U. */
1793 398546 : for (size_t i = 0; i < deferred_count; i++)
1794 : {
1795 183695 : struct deferred_opt *opt = &deferred_opts[i];
1796 :
1797 183695 : if (opt->code == OPT_imacros
1798 183695 : && cpp_push_include (parse_in, opt->arg))
1799 : {
1800 : /* Disable push_command_line_include callback for now. */
1801 8 : include_cursor = deferred_count + 1;
1802 8 : cpp_scan_nooutput (parse_in);
1803 : }
1804 : }
1805 :
1806 215401 : include_cursor = 0;
1807 215401 : push_command_line_include ();
1808 215401 : }
1809 :
1810 : /* Give CPP the next file given by -include, if any. */
1811 : static void
1812 759706 : push_command_line_include (void)
1813 : {
1814 : /* This can happen if disabled by -imacros for example.
1815 : Punt so that we don't set "<command-line>" as the filename for
1816 : the header. */
1817 759706 : if (include_cursor > deferred_count)
1818 : return;
1819 :
1820 439838 : if (!done_preinclude)
1821 : {
1822 215401 : done_preinclude = true;
1823 215401 : if (flag_hosted && std_inc && !cpp_opts->preprocessed)
1824 : {
1825 214769 : const char *preinc = targetcm.c_preinclude ();
1826 214769 : if (preinc && cpp_push_default_include (parse_in, preinc))
1827 : return;
1828 : }
1829 : }
1830 :
1831 225069 : pch_cpp_save_state ();
1832 :
1833 624216 : while (include_cursor < deferred_count)
1834 : {
1835 183747 : struct deferred_opt *opt = &deferred_opts[include_cursor++];
1836 :
1837 367441 : if (!cpp_opts->preprocessed && opt->code == OPT_include
1838 193419 : && cpp_push_include (parse_in, opt->arg))
1839 : return;
1840 : }
1841 :
1842 215400 : if (include_cursor == deferred_count)
1843 : {
1844 215400 : include_cursor++;
1845 : /* -Wunused-macros should only warn about macros defined hereafter. */
1846 215400 : cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
1847 : /* Restore the line map back to the main file. */
1848 215400 : if (!cpp_opts->preprocessed)
1849 : {
1850 214850 : cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1851 214850 : if (lang_hooks.preprocess_main_file)
1852 : /* We're starting the main file. Inform the FE of that. */
1853 100789 : lang_hooks.preprocess_main_file
1854 100789 : (parse_in, line_table, LINEMAPS_LAST_ORDINARY_MAP (line_table));
1855 : }
1856 :
1857 : /* Set this here so the client can change the option if it wishes,
1858 : and after stacking the main file so we don't trace the main file. */
1859 215400 : line_table->trace_includes = cpp_opts->print_include_names;
1860 : }
1861 : }
1862 :
1863 : /* File change callback. Has to handle -include files. */
1864 : static void
1865 21330423 : cb_file_change (cpp_reader *reader, const line_map_ordinary *new_map)
1866 : {
1867 21330423 : if (flag_preprocess_only)
1868 188600 : pp_file_change (new_map);
1869 : else
1870 21141823 : fe_file_change (new_map);
1871 :
1872 21115410 : if (new_map && cpp_opts->preprocessed
1873 42759 : && lang_hooks.preprocess_main_file && MAIN_FILE_P (new_map)
1874 21333037 : && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map))
1875 : /* We're starting the main file. Inform the FE of that. */
1876 468 : lang_hooks.preprocess_main_file (reader, line_table, new_map);
1877 :
1878 21330423 : if (new_map
1879 21115410 : && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
1880 : {
1881 : /* Signal to plugins that a file is included. This could happen
1882 : several times with the same file path, e.g. because of
1883 : several '#include' or '#line' directives... */
1884 10990024 : invoke_plugin_callbacks
1885 10990024 : (PLUGIN_INCLUDE_FILE,
1886 10990024 : const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
1887 : }
1888 :
1889 21115410 : if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1890 : {
1891 544305 : pch_cpp_save_state ();
1892 544305 : push_command_line_include ();
1893 : }
1894 21330422 : }
1895 :
1896 : void
1897 53 : cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1898 : {
1899 53 : if (!set_src_pwd (dir))
1900 0 : warning (0, "too late for # directive to set debug directory");
1901 53 : }
1902 :
1903 : /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1904 : extensions if ISO). There is no concept of gnu94. */
1905 : static void
1906 7015 : set_std_c89 (int c94, int iso)
1907 : {
1908 9968 : cpp_set_lang (parse_in, c94 ? CLK_STDC94 : iso ? CLK_STDC89 : CLK_GNUC89);
1909 7015 : flag_iso = iso;
1910 7015 : flag_no_asm = iso;
1911 7015 : flag_no_gnu_keywords = iso;
1912 7015 : flag_no_nonansi_builtin = iso;
1913 7015 : flag_isoc94 = c94;
1914 7015 : flag_isoc99 = 0;
1915 7015 : flag_isoc11 = 0;
1916 7015 : flag_isoc23 = 0;
1917 7015 : flag_isoc2y = 0;
1918 7015 : lang_hooks.name = "GNU C89";
1919 7015 : }
1920 :
1921 : /* Set the C 99 standard (without GNU extensions if ISO). */
1922 : static void
1923 1227 : set_std_c99 (int iso)
1924 : {
1925 1867 : cpp_set_lang (parse_in, iso ? CLK_STDC99 : CLK_GNUC99);
1926 1227 : flag_no_asm = iso;
1927 1227 : flag_no_nonansi_builtin = iso;
1928 1227 : flag_iso = iso;
1929 1227 : flag_isoc2y = 0;
1930 1227 : flag_isoc23 = 0;
1931 1227 : flag_isoc11 = 0;
1932 1227 : flag_isoc99 = 1;
1933 1227 : flag_isoc94 = 1;
1934 1227 : lang_hooks.name = "GNU C99";
1935 1227 : }
1936 :
1937 : /* Set the C 11 standard (without GNU extensions if ISO). */
1938 : static void
1939 4240 : set_std_c11 (int iso)
1940 : {
1941 7965 : cpp_set_lang (parse_in, iso ? CLK_STDC11 : CLK_GNUC11);
1942 4240 : flag_no_asm = iso;
1943 4240 : flag_no_nonansi_builtin = iso;
1944 4240 : flag_iso = iso;
1945 4240 : flag_isoc2y = 0;
1946 4240 : flag_isoc23 = 0;
1947 4240 : flag_isoc11 = 1;
1948 4240 : flag_isoc99 = 1;
1949 4240 : flag_isoc94 = 1;
1950 4240 : lang_hooks.name = "GNU C11";
1951 4240 : }
1952 :
1953 : /* Set the C 17 standard (without GNU extensions if ISO). */
1954 : static void
1955 821 : set_std_c17 (int iso)
1956 : {
1957 1599 : cpp_set_lang (parse_in, iso ? CLK_STDC17 : CLK_GNUC17);
1958 821 : flag_no_asm = iso;
1959 821 : flag_no_nonansi_builtin = iso;
1960 821 : flag_iso = iso;
1961 821 : flag_isoc2y = 0;
1962 821 : flag_isoc23 = 0;
1963 821 : flag_isoc11 = 1;
1964 821 : flag_isoc99 = 1;
1965 821 : flag_isoc94 = 1;
1966 821 : lang_hooks.name = "GNU C17";
1967 821 : }
1968 :
1969 : /* Set the C 23 standard (without GNU extensions if ISO). */
1970 : static void
1971 115829 : set_std_c23 (int iso)
1972 : {
1973 230676 : cpp_set_lang (parse_in, iso ? CLK_STDC23 : CLK_GNUC23);
1974 115829 : flag_no_asm = iso;
1975 115829 : flag_no_nonansi_builtin = iso;
1976 115829 : flag_iso = iso;
1977 115829 : flag_isoc2y = 0;
1978 115829 : flag_isoc23 = 1;
1979 115829 : flag_isoc11 = 1;
1980 115829 : flag_isoc99 = 1;
1981 115829 : flag_isoc94 = 1;
1982 115829 : lang_hooks.name = "GNU C23";
1983 115829 : }
1984 :
1985 : /* Set the C 2Y standard (without GNU extensions if ISO). */
1986 : static void
1987 216 : set_std_c2y (int iso)
1988 : {
1989 227 : cpp_set_lang (parse_in, iso ? CLK_STDC2Y : CLK_GNUC2Y);
1990 216 : flag_no_asm = iso;
1991 216 : flag_no_nonansi_builtin = iso;
1992 216 : flag_iso = iso;
1993 216 : flag_isoc2y = 1;
1994 216 : flag_isoc23 = 1;
1995 216 : flag_isoc11 = 1;
1996 216 : flag_isoc99 = 1;
1997 216 : flag_isoc94 = 1;
1998 216 : lang_hooks.name = "GNU C2Y";
1999 216 : }
2000 :
2001 :
2002 : /* Set the C++ 98 standard (without GNU extensions if ISO). */
2003 : static void
2004 14402 : set_std_cxx98 (int iso)
2005 : {
2006 19842 : cpp_set_lang (parse_in, iso ? CLK_CXX98 : CLK_GNUCXX);
2007 14402 : flag_no_gnu_keywords = iso;
2008 14402 : flag_no_nonansi_builtin = iso;
2009 14402 : flag_iso = iso;
2010 14402 : flag_isoc94 = 0;
2011 14402 : flag_isoc99 = 0;
2012 14402 : cxx_dialect = cxx98;
2013 14402 : lang_hooks.name = "GNU C++98";
2014 14402 : }
2015 :
2016 : /* Set the C++ 2011 standard (without GNU extensions if ISO). */
2017 : static void
2018 5790 : set_std_cxx11 (int iso)
2019 : {
2020 7258 : cpp_set_lang (parse_in, iso ? CLK_CXX11 : CLK_GNUCXX11);
2021 5790 : flag_no_gnu_keywords = iso;
2022 5790 : flag_no_nonansi_builtin = iso;
2023 5790 : flag_iso = iso;
2024 : /* C++11 includes the C99 standard library. */
2025 5790 : flag_isoc94 = 1;
2026 5790 : flag_isoc99 = 1;
2027 5790 : cxx_dialect = cxx11;
2028 5790 : lang_hooks.name = "GNU C++11";
2029 5790 : }
2030 :
2031 : /* Set the C++ 2014 standard (without GNU extensions if ISO). */
2032 : static void
2033 1339 : set_std_cxx14 (int iso)
2034 : {
2035 1628 : cpp_set_lang (parse_in, iso ? CLK_CXX14 : CLK_GNUCXX14);
2036 1339 : flag_no_gnu_keywords = iso;
2037 1339 : flag_no_nonansi_builtin = iso;
2038 1339 : flag_iso = iso;
2039 : /* C++14 includes the C99 standard library. */
2040 1339 : flag_isoc94 = 1;
2041 1339 : flag_isoc99 = 1;
2042 1339 : cxx_dialect = cxx14;
2043 1339 : lang_hooks.name = "GNU C++14";
2044 1339 : }
2045 :
2046 : /* Set the C++ 2017 standard (without GNU extensions if ISO). */
2047 : static void
2048 4273 : set_std_cxx17 (int iso)
2049 : {
2050 5211 : cpp_set_lang (parse_in, iso ? CLK_CXX17 : CLK_GNUCXX17);
2051 4273 : flag_no_gnu_keywords = iso;
2052 4273 : flag_no_nonansi_builtin = iso;
2053 4273 : flag_iso = iso;
2054 : /* C++17 includes the C11 standard library. */
2055 4273 : flag_isoc94 = 1;
2056 4273 : flag_isoc99 = 1;
2057 4273 : flag_isoc11 = 1;
2058 4273 : cxx_dialect = cxx17;
2059 4273 : lang_hooks.name = "GNU C++17";
2060 4273 : }
2061 :
2062 : /* Set the C++ 2020 standard (without GNU extensions if ISO). */
2063 : static void
2064 133662 : set_std_cxx20 (int iso)
2065 : {
2066 250414 : cpp_set_lang (parse_in, iso ? CLK_CXX20 : CLK_GNUCXX20);
2067 133662 : flag_no_gnu_keywords = iso;
2068 133662 : flag_no_nonansi_builtin = iso;
2069 133662 : flag_iso = iso;
2070 : /* C++20 includes the C11 standard library. */
2071 133662 : flag_isoc94 = 1;
2072 133662 : flag_isoc99 = 1;
2073 133662 : flag_isoc11 = 1;
2074 133662 : cxx_dialect = cxx20;
2075 133662 : lang_hooks.name = "GNU C++20";
2076 133662 : }
2077 :
2078 : /* Set the C++ 2023 standard (without GNU extensions if ISO). */
2079 : static void
2080 2216 : set_std_cxx23 (int iso)
2081 : {
2082 2804 : cpp_set_lang (parse_in, iso ? CLK_CXX23 : CLK_GNUCXX23);
2083 2216 : flag_no_gnu_keywords = iso;
2084 2216 : flag_no_nonansi_builtin = iso;
2085 2216 : flag_iso = iso;
2086 : /* C++23 includes the C11 standard library. */
2087 2216 : flag_isoc94 = 1;
2088 2216 : flag_isoc99 = 1;
2089 2216 : flag_isoc11 = 1;
2090 2216 : cxx_dialect = cxx23;
2091 2216 : lang_hooks.name = "GNU C++23";
2092 2216 : }
2093 :
2094 : /* Set the C++ 2026 standard (without GNU extensions if ISO). */
2095 : static void
2096 1428 : set_std_cxx26 (int iso)
2097 : {
2098 1808 : cpp_set_lang (parse_in, iso ? CLK_CXX26 : CLK_GNUCXX26);
2099 1428 : flag_no_gnu_keywords = iso;
2100 1428 : flag_no_nonansi_builtin = iso;
2101 1428 : flag_iso = iso;
2102 : /* C++26 includes the C11 standard library. */
2103 1428 : flag_isoc94 = 1;
2104 1428 : flag_isoc99 = 1;
2105 1428 : flag_isoc11 = 1;
2106 1428 : cxx_dialect = cxx26;
2107 1428 : lang_hooks.name = "GNU C++26";
2108 1428 : }
2109 :
2110 : /* Set the C++ 2029 standard (without GNU extensions if ISO). */
2111 : static void
2112 24331 : set_std_cxx29 (int iso)
2113 : {
2114 31435 : cpp_set_lang (parse_in, iso ? CLK_CXX29 : CLK_GNUCXX29);
2115 24331 : flag_no_gnu_keywords = iso;
2116 24331 : flag_no_nonansi_builtin = iso;
2117 24331 : flag_iso = iso;
2118 : /* C++29 includes the C11 standard library. */
2119 24331 : flag_isoc94 = 1;
2120 24331 : flag_isoc99 = 1;
2121 24331 : flag_isoc11 = 1;
2122 24331 : cxx_dialect = cxx29;
2123 24331 : lang_hooks.name = "GNU C++29";
2124 24331 : }
2125 :
2126 : /* Args to -d specify what to dump. Silently ignore
2127 : unrecognized options; they may be aimed at toplev.cc. */
2128 : static void
2129 1633 : handle_OPT_d (const char *arg)
2130 : {
2131 1633 : char c;
2132 :
2133 3266 : while ((c = *arg++) != '\0')
2134 1633 : switch (c)
2135 : {
2136 787 : case 'M': /* Dump macros only. */
2137 787 : case 'N': /* Dump names. */
2138 787 : case 'D': /* Dump definitions. */
2139 787 : case 'U': /* Dump used macros. */
2140 787 : flag_dump_macros = c;
2141 787 : break;
2142 :
2143 2 : case 'I':
2144 2 : flag_dump_includes = 1;
2145 2 : break;
2146 : }
2147 1633 : }
|