Debian Codegraph @

gcc/c-family/c-opts.cc

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