Fix compilation failure with C++98 compilers
[official-gcc.git] / gcc / c-family / c-opts.c
blob10cb53b2513a57c882dce552cd3dbe6f818c5796
1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "c-target.h"
26 #include "c-common.h"
27 #include "memmodel.h"
28 #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
29 #include "diagnostic.h"
30 #include "c-pragma.h"
31 #include "flags.h"
32 #include "toplev.h"
33 #include "langhooks.h"
34 #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
35 #include "intl.h"
36 #include "cppdefault.h"
37 #include "incpath.h"
38 #include "debug.h" /* For debug_hooks. */
39 #include "opts.h"
40 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
41 #include "mkdeps.h"
42 #include "dumpfile.h"
43 #include "file-prefix-map.h" /* add_*_prefix_map() */
45 #ifndef DOLLARS_IN_IDENTIFIERS
46 # define DOLLARS_IN_IDENTIFIERS true
47 #endif
49 #ifndef TARGET_SYSTEM_ROOT
50 # define TARGET_SYSTEM_ROOT NULL
51 #endif
53 #ifndef TARGET_OPTF
54 #define TARGET_OPTF(ARG)
55 #endif
57 /* CPP's options. */
58 cpp_options *cpp_opts;
60 /* Input filename. */
61 static const char *this_input_filename;
63 /* Filename and stream for preprocessed output. */
64 static const char *out_fname;
65 static FILE *out_stream;
67 /* Append dependencies to deps_file. */
68 static bool deps_append;
70 /* If dependency switches (-MF etc.) have been given. */
71 static bool deps_seen;
73 /* If -v seen. */
74 static bool verbose;
76 /* Dependency output file. */
77 static const char *deps_file;
79 /* The prefix given by -iprefix, if any. */
80 static const char *iprefix;
82 /* The multilib directory given by -imultilib, if any. */
83 static const char *imultilib;
85 /* The system root, if any. Overridden by -isysroot. */
86 static const char *sysroot = TARGET_SYSTEM_ROOT;
88 /* Zero disables all standard directories for headers. */
89 static bool std_inc = true;
91 /* Zero disables the C++-specific standard directories for headers. */
92 static bool std_cxx_inc = true;
94 /* If the quote chain has been split by -I-. */
95 static bool quote_chain_split;
97 /* Number of deferred options. */
98 static size_t deferred_count;
100 /* Number of deferred options scanned for -include. */
101 static size_t include_cursor;
103 /* Dump files/flags to use during parsing. */
104 static FILE *original_dump_file = NULL;
105 static dump_flags_t original_dump_flags;
107 /* Whether any standard preincluded header has been preincluded. */
108 static bool done_preinclude;
110 static void handle_OPT_d (const char *);
111 static void set_std_cxx98 (int);
112 static void set_std_cxx11 (int);
113 static void set_std_cxx14 (int);
114 static void set_std_cxx17 (int);
115 static void set_std_cxx2a (int);
116 static void set_std_c89 (int, int);
117 static void set_std_c99 (int);
118 static void set_std_c11 (int);
119 static void set_std_c17 (int);
120 static void check_deps_environment_vars (void);
121 static void handle_deferred_opts (void);
122 static void sanitize_cpp_opts (void);
123 static void add_prefixed_path (const char *, incpath_kind);
124 static void push_command_line_include (void);
125 static void cb_file_change (cpp_reader *, const line_map_ordinary *);
126 static void cb_dir_change (cpp_reader *, const char *);
127 static void c_finish_options (void);
129 #ifndef STDC_0_IN_SYSTEM_HEADERS
130 #define STDC_0_IN_SYSTEM_HEADERS 0
131 #endif
133 /* Holds switches parsed by c_common_handle_option (), but whose
134 handling is deferred to c_common_post_options (). */
135 static void defer_opt (enum opt_code, const char *);
136 static struct deferred_opt
138 enum opt_code code;
139 const char *arg;
140 } *deferred_opts;
143 extern const unsigned int
144 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
146 /* Defer option CODE with argument ARG. */
147 static void
148 defer_opt (enum opt_code code, const char *arg)
150 deferred_opts[deferred_count].code = code;
151 deferred_opts[deferred_count].arg = arg;
152 deferred_count++;
155 /* Return language mask for option parsing. */
156 unsigned int
157 c_common_option_lang_mask (void)
159 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
161 return lang_flags[c_language];
164 /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
165 static void
166 c_diagnostic_finalizer (diagnostic_context *context,
167 diagnostic_info *diagnostic)
169 diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
170 /* By default print macro expansion contexts in the diagnostic
171 finalizer -- for tokens resulting from macro expansion. */
172 virt_loc_aware_diagnostic_finalizer (context, diagnostic);
173 pp_destroy_prefix (context->printer);
174 pp_flush (context->printer);
177 /* Common default settings for diagnostics. */
178 void
179 c_common_diagnostics_set_defaults (diagnostic_context *context)
181 diagnostic_finalizer (context) = c_diagnostic_finalizer;
182 context->opt_permissive = OPT_fpermissive;
185 /* Whether options from all C-family languages should be accepted
186 quietly. */
187 static bool accept_all_c_family_options = false;
189 /* Return whether to complain about a wrong-language option. */
190 bool
191 c_common_complain_wrong_lang_p (const struct cl_option *option)
193 if (accept_all_c_family_options
194 && (option->flags & c_family_lang_mask))
195 return false;
197 return true;
200 /* Initialize options structure OPTS. */
201 void
202 c_common_init_options_struct (struct gcc_options *opts)
204 opts->x_flag_exceptions = c_dialect_cxx ();
205 opts->x_warn_pointer_arith = c_dialect_cxx ();
206 opts->x_warn_write_strings = c_dialect_cxx ();
207 opts->x_flag_warn_unused_result = true;
209 /* By default, C99-like requirements for complex multiply and divide. */
210 opts->x_flag_complex_method = 2;
213 /* Common initialization before calling option handlers. */
214 void
215 c_common_init_options (unsigned int decoded_options_count,
216 struct cl_decoded_option *decoded_options)
218 unsigned int i;
219 struct cpp_callbacks *cb;
221 g_string_concat_db
222 = new (ggc_alloc <string_concat_db> ()) string_concat_db ();
224 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
225 ident_hash, line_table);
226 cb = cpp_get_callbacks (parse_in);
227 cb->diagnostic = c_cpp_diagnostic;
229 cpp_opts = cpp_get_options (parse_in);
230 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
231 cpp_opts->objc = c_dialect_objc ();
233 /* Reset to avoid warnings on internal definitions. We set it just
234 before passing on command-line options to cpplib. */
235 cpp_opts->warn_dollars = 0;
237 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
239 if (c_language == clk_c)
241 /* The default for C is gnu17. */
242 set_std_c17 (false /* ISO */);
244 /* If preprocessing assembly language, accept any of the C-family
245 front end options since the driver may pass them through. */
246 for (i = 1; i < decoded_options_count; i++)
247 if (decoded_options[i].opt_index == OPT_lang_asm)
249 accept_all_c_family_options = true;
250 break;
254 /* Set C++ standard to C++14 if not specified on the command line. */
255 if (c_dialect_cxx ())
256 set_std_cxx14 (/*ISO*/false);
258 global_dc->colorize_source_p = true;
261 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
262 form of an -f or -W option was given. Returns false if the switch was
263 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
264 bool
265 c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
266 int kind, location_t loc,
267 const struct cl_option_handlers *handlers)
269 const struct cl_option *option = &cl_options[scode];
270 enum opt_code code = (enum opt_code) scode;
271 bool result = true;
273 /* Prevent resetting the language standard to a C dialect when the driver
274 has already determined that we're looking at assembler input. */
275 bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
277 switch (code)
279 default:
280 if (cl_options[code].flags & c_family_lang_mask)
282 if ((option->flags & CL_TARGET)
283 && ! targetcm.handle_c_option (scode, arg, value))
284 result = false;
285 break;
287 result = false;
288 break;
290 case OPT__output_pch_:
291 pch_file = arg;
292 break;
294 case OPT_A:
295 defer_opt (code, arg);
296 break;
298 case OPT_C:
299 cpp_opts->discard_comments = 0;
300 break;
302 case OPT_CC:
303 cpp_opts->discard_comments = 0;
304 cpp_opts->discard_comments_in_macro_exp = 0;
305 break;
307 case OPT_D:
308 defer_opt (code, arg);
309 break;
311 case OPT_H:
312 cpp_opts->print_include_names = 1;
313 break;
315 case OPT_F:
316 TARGET_OPTF (xstrdup (arg));
317 break;
319 case OPT_I:
320 if (strcmp (arg, "-"))
321 add_path (xstrdup (arg), INC_BRACKET, 0, true);
322 else
324 if (quote_chain_split)
325 error ("-I- specified twice");
326 quote_chain_split = true;
327 split_quote_chain ();
328 inform (input_location, "obsolete option -I- used, please use -iquote instead");
330 break;
332 case OPT_M:
333 case OPT_MM:
334 /* When doing dependencies with -M or -MM, suppress normal
335 preprocessed output, but still do -dM etc. as software
336 depends on this. Preprocessed output does occur if -MD, -MMD
337 or environment var dependency generation is used. */
338 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
339 flag_no_output = 1;
340 break;
342 case OPT_MD:
343 case OPT_MMD:
344 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
345 cpp_opts->deps.need_preprocessor_output = true;
346 deps_file = arg;
347 break;
349 case OPT_MF:
350 deps_seen = true;
351 deps_file = arg;
352 break;
354 case OPT_MG:
355 deps_seen = true;
356 cpp_opts->deps.missing_files = true;
357 break;
359 case OPT_MP:
360 deps_seen = true;
361 cpp_opts->deps.phony_targets = true;
362 break;
364 case OPT_MQ:
365 case OPT_MT:
366 deps_seen = true;
367 defer_opt (code, arg);
368 break;
370 case OPT_P:
371 flag_no_line_commands = 1;
372 break;
374 case OPT_U:
375 defer_opt (code, arg);
376 break;
378 case OPT_Wall:
379 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
381 cpp_opts->warn_num_sign_change = value;
382 break;
384 case OPT_Wunknown_pragmas:
385 /* Set to greater than 1, so that even unknown pragmas in
386 system headers will be warned about. */
387 /* ??? There is no way to handle this automatically for now. */
388 warn_unknown_pragmas = value * 2;
389 break;
391 case OPT_ansi:
392 if (!c_dialect_cxx ())
393 set_std_c89 (false, true);
394 else
395 set_std_cxx98 (true);
396 break;
398 case OPT_d:
399 handle_OPT_d (arg);
400 break;
402 case OPT_Wabi_:
403 warn_abi = true;
404 if (value == 1)
406 warning (0, "%<-Wabi=1%> is not supported, using =2");
407 value = 2;
409 warn_abi_version = value;
410 break;
412 case OPT_fcanonical_system_headers:
413 cpp_opts->canonical_system_headers = value;
414 break;
416 case OPT_fcond_mismatch:
417 if (!c_dialect_cxx ())
419 flag_cond_mismatch = value;
420 break;
422 warning (0, "switch %qs is no longer supported", option->opt_text);
423 break;
425 case OPT_fbuiltin_:
426 if (value)
427 result = false;
428 else
429 disable_builtin_function (arg);
430 break;
432 case OPT_fdirectives_only:
433 cpp_opts->directives_only = value;
434 break;
436 case OPT_fdollars_in_identifiers:
437 cpp_opts->dollars_in_ident = value;
438 break;
440 case OPT_fmacro_prefix_map_:
441 add_macro_prefix_map (arg);
442 break;
444 case OPT_ffreestanding:
445 value = !value;
446 /* Fall through. */
447 case OPT_fhosted:
448 flag_hosted = value;
449 flag_no_builtin = !value;
450 break;
452 case OPT_fconstant_string_class_:
453 constant_string_class_name = arg;
454 break;
456 case OPT_fextended_identifiers:
457 cpp_opts->extended_identifiers = value;
458 break;
460 case OPT_foperator_names:
461 cpp_opts->operator_names = value;
462 break;
464 case OPT_fpch_deps:
465 cpp_opts->restore_pch_deps = value;
466 break;
468 case OPT_fpch_preprocess:
469 flag_pch_preprocess = value;
470 break;
472 case OPT_fpermissive:
473 flag_permissive = value;
474 global_dc->permissive = value;
475 break;
477 case OPT_fpreprocessed:
478 cpp_opts->preprocessed = value;
479 break;
481 case OPT_fdebug_cpp:
482 cpp_opts->debug = 1;
483 break;
485 case OPT_ftrack_macro_expansion:
486 if (value)
487 value = 2;
488 /* Fall Through. */
490 case OPT_ftrack_macro_expansion_:
491 if (arg && *arg != '\0')
492 cpp_opts->track_macro_expansion = value;
493 else
494 cpp_opts->track_macro_expansion = 2;
495 break;
497 case OPT_frepo:
498 flag_use_repository = value;
499 if (value)
500 flag_implicit_templates = 0;
501 break;
503 case OPT_ftabstop_:
504 /* It is documented that we silently ignore silly values. */
505 if (value >= 1 && value <= 100)
506 cpp_opts->tabstop = value;
507 break;
509 case OPT_fexec_charset_:
510 cpp_opts->narrow_charset = arg;
511 break;
513 case OPT_fwide_exec_charset_:
514 cpp_opts->wide_charset = arg;
515 break;
517 case OPT_finput_charset_:
518 cpp_opts->input_charset = arg;
519 break;
521 case OPT_ftemplate_depth_:
522 max_tinst_depth = value;
523 break;
525 case OPT_fvisibility_inlines_hidden:
526 visibility_options.inlines_hidden = value;
527 break;
529 case OPT_femit_struct_debug_baseonly:
530 set_struct_debug_option (&global_options, loc, "base");
531 break;
533 case OPT_femit_struct_debug_reduced:
534 set_struct_debug_option (&global_options, loc,
535 "dir:ord:sys,dir:gen:any,ind:base");
536 break;
538 case OPT_femit_struct_debug_detailed_:
539 set_struct_debug_option (&global_options, loc, arg);
540 break;
542 case OPT_fext_numeric_literals:
543 cpp_opts->ext_numeric_literals = value;
544 break;
546 case OPT_idirafter:
547 add_path (xstrdup (arg), INC_AFTER, 0, true);
548 break;
550 case OPT_imacros:
551 case OPT_include:
552 defer_opt (code, arg);
553 break;
555 case OPT_imultilib:
556 imultilib = arg;
557 break;
559 case OPT_iprefix:
560 iprefix = arg;
561 break;
563 case OPT_iquote:
564 add_path (xstrdup (arg), INC_QUOTE, 0, true);
565 break;
567 case OPT_isysroot:
568 sysroot = arg;
569 break;
571 case OPT_isystem:
572 add_path (xstrdup (arg), INC_SYSTEM, 0, true);
573 break;
575 case OPT_iwithprefix:
576 add_prefixed_path (arg, INC_SYSTEM);
577 break;
579 case OPT_iwithprefixbefore:
580 add_prefixed_path (arg, INC_BRACKET);
581 break;
583 case OPT_lang_asm:
584 cpp_set_lang (parse_in, CLK_ASM);
585 cpp_opts->dollars_in_ident = false;
586 break;
588 case OPT_nostdinc:
589 std_inc = false;
590 break;
592 case OPT_nostdinc__:
593 std_cxx_inc = false;
594 break;
596 case OPT_o:
597 if (!out_fname)
598 out_fname = arg;
599 else
600 error ("output filename specified twice");
601 break;
603 case OPT_print_objc_runtime_info:
604 print_struct_values = 1;
605 break;
607 case OPT_remap:
608 cpp_opts->remap = 1;
609 break;
611 case OPT_std_c__98:
612 case OPT_std_gnu__98:
613 if (!preprocessing_asm_p)
614 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
615 break;
617 case OPT_std_c__11:
618 case OPT_std_gnu__11:
619 if (!preprocessing_asm_p)
620 set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
621 break;
623 case OPT_std_c__14:
624 case OPT_std_gnu__14:
625 if (!preprocessing_asm_p)
626 set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
627 break;
629 case OPT_std_c__17:
630 case OPT_std_gnu__17:
631 if (!preprocessing_asm_p)
632 set_std_cxx17 (code == OPT_std_c__17 /* ISO */);
633 break;
635 case OPT_std_c__2a:
636 case OPT_std_gnu__2a:
637 if (!preprocessing_asm_p)
638 set_std_cxx2a (code == OPT_std_c__2a /* ISO */);
639 break;
641 case OPT_std_c90:
642 case OPT_std_iso9899_199409:
643 if (!preprocessing_asm_p)
644 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
645 break;
647 case OPT_std_gnu90:
648 if (!preprocessing_asm_p)
649 set_std_c89 (false /* c94 */, false /* ISO */);
650 break;
652 case OPT_std_c99:
653 if (!preprocessing_asm_p)
654 set_std_c99 (true /* ISO */);
655 break;
657 case OPT_std_gnu99:
658 if (!preprocessing_asm_p)
659 set_std_c99 (false /* ISO */);
660 break;
662 case OPT_std_c11:
663 if (!preprocessing_asm_p)
664 set_std_c11 (true /* ISO */);
665 break;
667 case OPT_std_gnu11:
668 if (!preprocessing_asm_p)
669 set_std_c11 (false /* ISO */);
670 break;
672 case OPT_std_c17:
673 if (!preprocessing_asm_p)
674 set_std_c17 (true /* ISO */);
675 break;
677 case OPT_std_gnu17:
678 if (!preprocessing_asm_p)
679 set_std_c17 (false /* ISO */);
680 break;
682 case OPT_trigraphs:
683 cpp_opts->trigraphs = 1;
684 break;
686 case OPT_traditional_cpp:
687 cpp_opts->traditional = 1;
688 break;
690 case OPT_v:
691 verbose = true;
692 break;
695 switch (c_language)
697 case clk_c:
698 C_handle_option_auto (&global_options, &global_options_set,
699 scode, arg, value,
700 c_family_lang_mask, kind,
701 loc, handlers, global_dc);
702 break;
704 case clk_objc:
705 ObjC_handle_option_auto (&global_options, &global_options_set,
706 scode, arg, value,
707 c_family_lang_mask, kind,
708 loc, handlers, global_dc);
709 break;
711 case clk_cxx:
712 CXX_handle_option_auto (&global_options, &global_options_set,
713 scode, arg, value,
714 c_family_lang_mask, kind,
715 loc, handlers, global_dc);
716 break;
718 case clk_objcxx:
719 ObjCXX_handle_option_auto (&global_options, &global_options_set,
720 scode, arg, value,
721 c_family_lang_mask, kind,
722 loc, handlers, global_dc);
723 break;
725 default:
726 gcc_unreachable ();
729 cpp_handle_option_auto (&global_options, scode, cpp_opts);
730 return result;
733 /* Default implementation of TARGET_HANDLE_C_OPTION. */
735 bool
736 default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
737 const char *arg ATTRIBUTE_UNUSED,
738 int value ATTRIBUTE_UNUSED)
740 return false;
743 /* Post-switch processing. */
744 bool
745 c_common_post_options (const char **pfilename)
747 struct cpp_callbacks *cb;
749 /* Canonicalize the input and output filenames. */
750 if (in_fnames == NULL)
752 in_fnames = XNEWVEC (const char *, 1);
753 in_fnames[0] = "";
755 else if (strcmp (in_fnames[0], "-") == 0)
757 if (pch_file)
758 error ("cannot use %<-%> as input filename for a precompiled header");
760 in_fnames[0] = "";
763 if (out_fname == NULL || !strcmp (out_fname, "-"))
764 out_fname = "";
766 if (cpp_opts->deps.style == DEPS_NONE)
767 check_deps_environment_vars ();
769 handle_deferred_opts ();
771 sanitize_cpp_opts ();
773 register_include_chains (parse_in, sysroot, iprefix, imultilib,
774 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
776 #ifdef C_COMMON_OVERRIDE_OPTIONS
777 /* Some machines may reject certain combinations of C
778 language-specific options. */
779 C_COMMON_OVERRIDE_OPTIONS;
780 #endif
782 /* Excess precision other than "fast" requires front-end
783 support. */
784 if (c_dialect_cxx ())
786 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
787 sorry ("-fexcess-precision=standard for C++");
788 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
790 else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
791 flag_excess_precision_cmdline = (flag_iso
792 ? EXCESS_PRECISION_STANDARD
793 : EXCESS_PRECISION_FAST);
795 /* ISO C restricts floating-point expression contraction to within
796 source-language expressions (-ffp-contract=on, currently an alias
797 for -ffp-contract=off). */
798 if (flag_iso
799 && !c_dialect_cxx ()
800 && (global_options_set.x_flag_fp_contract_mode
801 == (enum fp_contract_mode) 0)
802 && flag_unsafe_math_optimizations == 0)
803 flag_fp_contract_mode = FP_CONTRACT_OFF;
805 /* If we are compiling C, and we are outside of a standards mode,
806 we can permit the new values from ISO/IEC TS 18661-3 for
807 FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
808 the set specified in ISO C99/C11. */
809 if (!flag_iso
810 && !c_dialect_cxx ()
811 && (global_options_set.x_flag_permitted_flt_eval_methods
812 == PERMITTED_FLT_EVAL_METHODS_DEFAULT))
813 flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_TS_18661;
814 else
815 flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
817 /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
818 inline semantics are not supported in GNU89 or C89 mode. */
819 if (flag_gnu89_inline == -1)
820 flag_gnu89_inline = !flag_isoc99;
821 else if (!flag_gnu89_inline && !flag_isoc99)
822 error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
824 /* Default to ObjC sjlj exception handling if NeXT runtime. */
825 if (flag_objc_sjlj_exceptions < 0)
826 flag_objc_sjlj_exceptions = flag_next_runtime;
827 if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
828 flag_exceptions = 1;
830 /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
831 pattern recognition. */
832 if (!global_options_set.x_flag_tree_loop_distribute_patterns
833 && flag_no_builtin)
834 flag_tree_loop_distribute_patterns = 0;
836 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
837 It is never enabled in C++, as the minimum limit is not normative
838 in that standard. */
839 if (c_dialect_cxx ())
840 warn_overlength_strings = 0;
842 /* Wmain is enabled by default in C++ but not in C. */
843 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
844 even if -Wall or -Wpedantic was given (warn_main will be 2 if set
845 by -Wall, 1 if set by -Wmain). */
846 if (warn_main == -1)
847 warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
848 else if (warn_main == 2)
849 warn_main = flag_hosted ? 1 : 0;
851 /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
852 yet been set, it is disabled by default. In C++, it is enabled
853 by default. */
854 if (warn_enum_compare == -1)
855 warn_enum_compare = c_dialect_cxx () ? 1 : 0;
857 /* -Wpacked-bitfield-compat is on by default for the C languages. The
858 warning is issued in stor-layout.c which is not part of the front-end so
859 we need to selectively turn it on here. */
860 if (warn_packed_bitfield_compat == -1)
861 warn_packed_bitfield_compat = 1;
863 /* Special format checking options don't work without -Wformat; warn if
864 they are used. */
865 if (!warn_format)
867 warning (OPT_Wformat_y2k,
868 "-Wformat-y2k ignored without -Wformat");
869 warning (OPT_Wformat_extra_args,
870 "-Wformat-extra-args ignored without -Wformat");
871 warning (OPT_Wformat_zero_length,
872 "-Wformat-zero-length ignored without -Wformat");
873 warning (OPT_Wformat_nonliteral,
874 "-Wformat-nonliteral ignored without -Wformat");
875 warning (OPT_Wformat_contains_nul,
876 "-Wformat-contains-nul ignored without -Wformat");
877 warning (OPT_Wformat_security,
878 "-Wformat-security ignored without -Wformat");
881 /* -Wimplicit-function-declaration is enabled by default for C99. */
882 if (warn_implicit_function_declaration == -1)
883 warn_implicit_function_declaration = flag_isoc99;
885 /* -Wimplicit-int is enabled by default for C99. */
886 if (warn_implicit_int == -1)
887 warn_implicit_int = flag_isoc99;
889 /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
890 if (warn_shift_overflow == -1)
891 warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
893 /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 modes. */
894 if (warn_shift_negative_value == -1)
895 warn_shift_negative_value = (extra_warnings
896 && (cxx_dialect >= cxx11 || flag_isoc99));
898 /* -Wregister is enabled by default in C++17. */
899 if (!global_options_set.x_warn_register)
900 warn_register = cxx_dialect >= cxx17;
902 /* Declone C++ 'structors if -Os. */
903 if (flag_declone_ctor_dtor == -1)
904 flag_declone_ctor_dtor = optimize_size;
906 if (flag_abi_compat_version == 1)
908 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
909 flag_abi_compat_version = 2;
912 /* Change flag_abi_version to be the actual current ABI level, for the
913 benefit of c_cpp_builtins, and to make comparison simpler. */
914 const int latest_abi_version = 13;
915 /* Generate compatibility aliases for ABI v11 (7.1) by default. */
916 const int abi_compat_default = 11;
918 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
919 clamp (flag_abi_version);
920 clamp (warn_abi_version);
921 clamp (flag_abi_compat_version);
922 #undef clamp
924 /* Default -Wabi= or -fabi-compat-version= from each other. */
925 if (warn_abi_version == -1 && flag_abi_compat_version != -1)
926 warn_abi_version = flag_abi_compat_version;
927 else if (flag_abi_compat_version == -1 && warn_abi_version != -1)
928 flag_abi_compat_version = warn_abi_version;
929 else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
931 warn_abi_version = latest_abi_version;
932 if (flag_abi_version == latest_abi_version)
934 auto_diagnostic_group d;
935 if (warning (OPT_Wabi, "-Wabi won't warn about anything"))
937 inform (input_location, "-Wabi warns about differences "
938 "from the most up-to-date ABI, which is also used "
939 "by default");
940 inform (input_location, "use e.g. -Wabi=11 to warn about "
941 "changes from GCC 7");
943 flag_abi_compat_version = abi_compat_default;
945 else
946 flag_abi_compat_version = latest_abi_version;
949 /* By default, enable the new inheriting constructor semantics along with ABI
950 11. New and old should coexist fine, but it is a change in what
951 artificial symbols are generated. */
952 if (!global_options_set.x_flag_new_inheriting_ctors)
953 flag_new_inheriting_ctors = abi_version_at_least (11);
955 /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
956 if (!global_options_set.x_flag_new_ttp)
957 flag_new_ttp = (cxx_dialect >= cxx17);
959 if (cxx_dialect >= cxx11)
961 /* If we're allowing C++0x constructs, don't warn about C++98
962 identifiers which are keywords in C++0x. */
963 warn_cxx11_compat = 0;
964 cpp_opts->cpp_warn_cxx11_compat = 0;
966 if (warn_narrowing == -1)
967 warn_narrowing = 1;
969 /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
970 for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals. */
971 if (flag_iso && !global_options_set.x_flag_ext_numeric_literals)
972 cpp_opts->ext_numeric_literals = 0;
974 else if (warn_narrowing == -1)
975 warn_narrowing = 0;
977 /* C++17 has stricter evaluation order requirements; let's use some of them
978 for earlier C++ as well, so chaining works as expected. */
979 if (c_dialect_cxx ()
980 && flag_strong_eval_order == -1)
981 flag_strong_eval_order = (cxx_dialect >= cxx17 ? 2 : 1);
983 /* Global sized deallocation is new in C++14. */
984 if (flag_sized_deallocation == -1)
985 flag_sized_deallocation = (cxx_dialect >= cxx14);
987 if (flag_extern_tls_init)
989 if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
991 /* Lazy TLS initialization for a variable in another TU requires
992 alias and weak reference support. */
993 if (flag_extern_tls_init > 0)
994 sorry ("external TLS initialization functions not supported "
995 "on this target");
997 flag_extern_tls_init = 0;
999 else
1000 flag_extern_tls_init = 1;
1003 /* Enable by default only for C++ and C++ with ObjC extensions. */
1004 if (warn_return_type == -1 && c_dialect_cxx ())
1005 warn_return_type = 1;
1007 if (num_in_fnames > 1)
1008 error ("too many filenames given. Type %s --help for usage",
1009 progname);
1011 if (flag_preprocess_only)
1013 /* Open the output now. We must do so even if flag_no_output is
1014 on, because there may be other output than from the actual
1015 preprocessing (e.g. from -dM). */
1016 if (out_fname[0] == '\0')
1017 out_stream = stdout;
1018 else
1019 out_stream = fopen (out_fname, "w");
1021 if (out_stream == NULL)
1023 fatal_error (input_location, "opening output file %s: %m", out_fname);
1024 return false;
1027 init_pp_output (out_stream);
1029 else
1031 init_c_lex ();
1033 /* When writing a PCH file, avoid reading some other PCH file,
1034 because the default address space slot then can't be used
1035 for the output PCH file. */
1036 if (pch_file)
1038 c_common_no_more_pch ();
1039 /* Only -g0 and -gdwarf* are supported with PCH, for other
1040 debug formats we warn here and refuse to load any PCH files. */
1041 if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1042 warning (OPT_Wdeprecated,
1043 "the \"%s\" debug format cannot be used with "
1044 "pre-compiled headers", debug_type_names[write_symbols]);
1046 else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1047 c_common_no_more_pch ();
1049 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1050 input_location = UNKNOWN_LOCATION;
1053 cb = cpp_get_callbacks (parse_in);
1054 cb->file_change = cb_file_change;
1055 cb->dir_change = cb_dir_change;
1056 cpp_post_options (parse_in);
1057 init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
1059 input_location = UNKNOWN_LOCATION;
1061 *pfilename = this_input_filename
1062 = cpp_read_main_file (parse_in, in_fnames[0]);
1063 /* Don't do any compilation or preprocessing if there is no input file. */
1064 if (this_input_filename == NULL)
1066 errorcount++;
1067 return false;
1070 if (flag_working_directory
1071 && flag_preprocess_only && !flag_no_line_commands)
1072 pp_dir_change (parse_in, get_src_pwd ());
1074 /* Disable LTO output when outputting a precompiled header. */
1075 if (pch_file && flag_lto)
1077 flag_lto = 0;
1078 flag_generate_lto = 0;
1081 return flag_preprocess_only;
1084 /* Front end initialization common to C, ObjC and C++. */
1085 bool
1086 c_common_init (void)
1088 /* Set up preprocessor arithmetic. Must be done after call to
1089 c_common_nodes_and_builtins for type nodes to be good. */
1090 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1091 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1092 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1093 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1094 cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1095 cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1097 /* This can't happen until after wchar_precision and bytes_big_endian
1098 are known. */
1099 cpp_init_iconv (parse_in);
1101 if (version_flag)
1103 int i;
1104 fputs ("Compiler executable checksum: ", stderr);
1105 for (i = 0; i < 16; i++)
1106 fprintf (stderr, "%02x", executable_checksum[i]);
1107 putc ('\n', stderr);
1110 /* Has to wait until now so that cpplib has its hash table. */
1111 init_pragma ();
1113 if (flag_preprocess_only)
1115 c_finish_options ();
1116 preprocess_file (parse_in);
1117 return false;
1120 return true;
1123 /* Initialize the integrated preprocessor after debug output has been
1124 initialized; loop over each input file. */
1125 void
1126 c_common_parse_file (void)
1128 unsigned int i;
1130 i = 0;
1131 for (;;)
1133 c_finish_options ();
1134 /* Open the dump file to use for the original dump output
1135 here, to be used during parsing for the current file. */
1136 original_dump_file = dump_begin (TDI_original, &original_dump_flags);
1137 pch_init ();
1138 push_file_scope ();
1139 c_parse_file ();
1140 pop_file_scope ();
1141 /* And end the main input file, if the debug writer wants it */
1142 if (debug_hooks->start_end_main_source_file)
1143 (*debug_hooks->end_source_file) (0);
1144 if (++i >= num_in_fnames)
1145 break;
1146 cpp_undef_all (parse_in);
1147 cpp_clear_file_cache (parse_in);
1148 this_input_filename
1149 = cpp_read_main_file (parse_in, in_fnames[i]);
1150 if (original_dump_file)
1152 dump_end (TDI_original, original_dump_file);
1153 original_dump_file = NULL;
1155 /* If an input file is missing, abandon further compilation.
1156 cpplib has issued a diagnostic. */
1157 if (!this_input_filename)
1158 break;
1161 c_parse_final_cleanups ();
1164 /* Returns the appropriate dump file for PHASE to dump with FLAGS. */
1166 FILE *
1167 get_dump_info (int phase, dump_flags_t *flags)
1169 gcc_assert (phase == TDI_original);
1171 *flags = original_dump_flags;
1172 return original_dump_file;
1175 /* Common finish hook for the C, ObjC and C++ front ends. */
1176 void
1177 c_common_finish (void)
1179 FILE *deps_stream = NULL;
1181 /* Note that we write the dependencies even if there are errors. This is
1182 useful for handling outdated generated headers that now trigger errors
1183 (for example, with #error) which would be resolved by re-generating
1184 them. In a sense, this complements -MG. */
1185 if (cpp_opts->deps.style != DEPS_NONE)
1187 /* If -M or -MM was seen without -MF, default output to the
1188 output stream. */
1189 if (!deps_file)
1190 deps_stream = out_stream;
1191 else if (deps_file[0] == '-' && deps_file[1] == '\0')
1192 deps_stream = stdout;
1193 else
1195 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1196 if (!deps_stream)
1197 fatal_error (input_location, "opening dependency file %s: %m",
1198 deps_file);
1202 /* For performance, avoid tearing down cpplib's internal structures
1203 with cpp_destroy (). */
1204 cpp_finish (parse_in, deps_stream);
1206 if (deps_stream && deps_stream != out_stream && deps_stream != stdout
1207 && (ferror (deps_stream) || fclose (deps_stream)))
1208 fatal_error (input_location, "closing dependency file %s: %m", deps_file);
1210 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1211 fatal_error (input_location, "when writing output to %s: %m", out_fname);
1214 /* Either of two environment variables can specify output of
1215 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1216 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1217 and DEPS_TARGET is the target to mention in the deps. They also
1218 result in dependency information being appended to the output file
1219 rather than overwriting it, and like Sun's compiler
1220 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1221 static void
1222 check_deps_environment_vars (void)
1224 char *spec;
1226 spec = getenv ("DEPENDENCIES_OUTPUT");
1227 if (spec)
1228 cpp_opts->deps.style = DEPS_USER;
1229 else
1231 spec = getenv ("SUNPRO_DEPENDENCIES");
1232 if (spec)
1234 cpp_opts->deps.style = DEPS_SYSTEM;
1235 cpp_opts->deps.ignore_main_file = true;
1239 if (spec)
1241 /* Find the space before the DEPS_TARGET, if there is one. */
1242 char *s = strchr (spec, ' ');
1243 if (s)
1245 /* Let the caller perform MAKE quoting. */
1246 defer_opt (OPT_MT, s + 1);
1247 *s = '\0';
1250 /* Command line -MF overrides environment variables and default. */
1251 if (!deps_file)
1252 deps_file = spec;
1254 deps_append = 1;
1255 deps_seen = true;
1259 /* Handle deferred command line switches. */
1260 static void
1261 handle_deferred_opts (void)
1263 size_t i;
1264 struct deps *deps;
1266 /* Avoid allocating the deps buffer if we don't need it.
1267 (This flag may be true without there having been -MT or -MQ
1268 options, but we'll still need the deps buffer.) */
1269 if (!deps_seen)
1270 return;
1272 deps = cpp_get_deps (parse_in);
1274 for (i = 0; i < deferred_count; i++)
1276 struct deferred_opt *opt = &deferred_opts[i];
1278 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1279 deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1283 /* These settings are appropriate for GCC, but not necessarily so for
1284 cpplib as a library. */
1285 static void
1286 sanitize_cpp_opts (void)
1288 /* If we don't know what style of dependencies to output, complain
1289 if any other dependency switches have been given. */
1290 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1291 error ("to generate dependencies you must specify either -M or -MM");
1293 /* -dM and dependencies suppress normal output; do it here so that
1294 the last -d[MDN] switch overrides earlier ones. */
1295 if (flag_dump_macros == 'M')
1296 flag_no_output = 1;
1298 /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1299 to perform proper macro expansion. */
1300 if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1301 flag_dump_macros = 'D';
1303 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1304 -dM since at least glibc relies on -M -dM to work. */
1305 /* Also, flag_no_output implies flag_no_line_commands, always. */
1306 if (flag_no_output)
1308 if (flag_dump_macros != 'M')
1309 flag_dump_macros = 0;
1310 flag_dump_includes = 0;
1311 flag_no_line_commands = 1;
1313 else if (cpp_opts->deps.missing_files)
1314 error ("-MG may only be used with -M or -MM");
1316 cpp_opts->unsigned_char = !flag_signed_char;
1317 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1319 /* Wlong-long is disabled by default. It is enabled by:
1320 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1321 [-Wpedantic | -Wtraditional] -std=non-c99
1323 Either -Wlong-long or -Wno-long-long override any other settings.
1324 ??? These conditions should be handled in c.opt. */
1325 if (warn_long_long == -1)
1327 warn_long_long = ((pedantic || warn_traditional)
1328 && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1329 cpp_opts->cpp_warn_long_long = warn_long_long;
1332 /* If we're generating preprocessor output, emit current directory
1333 if explicitly requested or if debugging information is enabled.
1334 ??? Maybe we should only do it for debugging formats that
1335 actually output the current directory? */
1336 if (flag_working_directory == -1)
1337 flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1339 if (warn_implicit_fallthrough < 5)
1340 cpp_opts->cpp_warn_implicit_fallthrough = warn_implicit_fallthrough;
1341 else
1342 cpp_opts->cpp_warn_implicit_fallthrough = 0;
1344 if (cpp_opts->directives_only)
1346 if (cpp_warn_unused_macros)
1347 error ("-fdirectives-only is incompatible with -Wunused_macros");
1348 if (cpp_opts->traditional)
1349 error ("-fdirectives-only is incompatible with -traditional");
1353 /* Add include path with a prefix at the front of its name. */
1354 static void
1355 add_prefixed_path (const char *suffix, incpath_kind chain)
1357 char *path;
1358 const char *prefix;
1359 size_t prefix_len, suffix_len;
1361 suffix_len = strlen (suffix);
1362 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1363 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1365 path = (char *) xmalloc (prefix_len + suffix_len + 1);
1366 memcpy (path, prefix, prefix_len);
1367 memcpy (path + prefix_len, suffix, suffix_len);
1368 path[prefix_len + suffix_len] = '\0';
1370 add_path (path, chain, 0, false);
1373 /* Handle -D, -U, -A, -imacros, and the first -include. */
1374 static void
1375 c_finish_options (void)
1377 if (!cpp_opts->preprocessed)
1379 size_t i;
1381 cb_file_change (parse_in,
1382 linemap_check_ordinary (linemap_add (line_table,
1383 LC_RENAME, 0,
1384 _("<built-in>"),
1385 0)));
1386 /* Make sure all of the builtins about to be declared have
1387 BUILTINS_LOCATION has their source_location. */
1388 source_location builtins_loc = BUILTINS_LOCATION;
1389 cpp_force_token_locations (parse_in, &builtins_loc);
1391 cpp_init_builtins (parse_in, flag_hosted);
1392 c_cpp_builtins (parse_in);
1394 cpp_stop_forcing_token_locations (parse_in);
1396 /* We're about to send user input to cpplib, so make it warn for
1397 things that we previously (when we sent it internal definitions)
1398 told it to not warn.
1400 C99 permits implementation-defined characters in identifiers.
1401 The documented meaning of -std= is to turn off extensions that
1402 conflict with the specified standard, and since a strictly
1403 conforming program cannot contain a '$', we do not condition
1404 their acceptance on the -std= setting. */
1405 cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1407 cb_file_change (parse_in,
1408 linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1409 _("<command-line>"), 0)));
1411 for (i = 0; i < deferred_count; i++)
1413 struct deferred_opt *opt = &deferred_opts[i];
1415 if (opt->code == OPT_D)
1416 cpp_define (parse_in, opt->arg);
1417 else if (opt->code == OPT_U)
1418 cpp_undef (parse_in, opt->arg);
1419 else if (opt->code == OPT_A)
1421 if (opt->arg[0] == '-')
1422 cpp_unassert (parse_in, opt->arg + 1);
1423 else
1424 cpp_assert (parse_in, opt->arg);
1428 /* Start the main input file, if the debug writer wants it. */
1429 if (debug_hooks->start_end_main_source_file
1430 && !flag_preprocess_only)
1431 (*debug_hooks->start_source_file) (0, this_input_filename);
1433 /* Handle -imacros after -D and -U. */
1434 for (i = 0; i < deferred_count; i++)
1436 struct deferred_opt *opt = &deferred_opts[i];
1438 if (opt->code == OPT_imacros
1439 && cpp_push_include (parse_in, opt->arg))
1441 /* Disable push_command_line_include callback for now. */
1442 include_cursor = deferred_count + 1;
1443 cpp_scan_nooutput (parse_in);
1447 else
1449 if (cpp_opts->directives_only)
1450 cpp_init_special_builtins (parse_in);
1452 /* Start the main input file, if the debug writer wants it. */
1453 if (debug_hooks->start_end_main_source_file
1454 && !flag_preprocess_only)
1455 (*debug_hooks->start_source_file) (0, this_input_filename);
1458 include_cursor = 0;
1459 push_command_line_include ();
1462 /* Give CPP the next file given by -include, if any. */
1463 static void
1464 push_command_line_include (void)
1466 /* This can happen if disabled by -imacros for example.
1467 Punt so that we don't set "<command-line>" as the filename for
1468 the header. */
1469 if (include_cursor > deferred_count)
1470 return;
1472 if (!done_preinclude)
1474 done_preinclude = true;
1475 if (flag_hosted && std_inc && !cpp_opts->preprocessed)
1477 const char *preinc = targetcm.c_preinclude ();
1478 if (preinc && cpp_push_default_include (parse_in, preinc))
1479 return;
1483 pch_cpp_save_state ();
1485 while (include_cursor < deferred_count)
1487 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1489 if (!cpp_opts->preprocessed && opt->code == OPT_include
1490 && cpp_push_include (parse_in, opt->arg))
1491 return;
1494 if (include_cursor == deferred_count)
1496 include_cursor++;
1497 /* -Wunused-macros should only warn about macros defined hereafter. */
1498 cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
1499 /* Restore the line map from <command line>. */
1500 if (!cpp_opts->preprocessed)
1501 cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1503 /* Set this here so the client can change the option if it wishes,
1504 and after stacking the main file so we don't trace the main file. */
1505 line_table->trace_includes = cpp_opts->print_include_names;
1509 /* File change callback. Has to handle -include files. */
1510 static void
1511 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
1512 const line_map_ordinary *new_map)
1514 if (flag_preprocess_only)
1515 pp_file_change (new_map);
1516 else
1517 fe_file_change (new_map);
1519 if (new_map
1520 && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
1522 /* Signal to plugins that a file is included. This could happen
1523 several times with the same file path, e.g. because of
1524 several '#include' or '#line' directives... */
1525 invoke_plugin_callbacks
1526 (PLUGIN_INCLUDE_FILE,
1527 const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
1530 if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1532 pch_cpp_save_state ();
1533 push_command_line_include ();
1537 void
1538 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1540 if (!set_src_pwd (dir))
1541 warning (0, "too late for # directive to set debug directory");
1544 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1545 extensions if ISO). There is no concept of gnu94. */
1546 static void
1547 set_std_c89 (int c94, int iso)
1549 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1550 flag_iso = iso;
1551 flag_no_asm = iso;
1552 flag_no_gnu_keywords = iso;
1553 flag_no_nonansi_builtin = iso;
1554 flag_isoc94 = c94;
1555 flag_isoc99 = 0;
1556 flag_isoc11 = 0;
1557 lang_hooks.name = "GNU C89";
1560 /* Set the C 99 standard (without GNU extensions if ISO). */
1561 static void
1562 set_std_c99 (int iso)
1564 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1565 flag_no_asm = iso;
1566 flag_no_nonansi_builtin = iso;
1567 flag_iso = iso;
1568 flag_isoc11 = 0;
1569 flag_isoc99 = 1;
1570 flag_isoc94 = 1;
1571 lang_hooks.name = "GNU C99";
1574 /* Set the C 11 standard (without GNU extensions if ISO). */
1575 static void
1576 set_std_c11 (int iso)
1578 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
1579 flag_no_asm = iso;
1580 flag_no_nonansi_builtin = iso;
1581 flag_iso = iso;
1582 flag_isoc11 = 1;
1583 flag_isoc99 = 1;
1584 flag_isoc94 = 1;
1585 lang_hooks.name = "GNU C11";
1588 /* Set the C 17 standard (without GNU extensions if ISO). */
1589 static void
1590 set_std_c17 (int iso)
1592 cpp_set_lang (parse_in, iso ? CLK_STDC17: CLK_GNUC17);
1593 flag_no_asm = iso;
1594 flag_no_nonansi_builtin = iso;
1595 flag_iso = iso;
1596 flag_isoc11 = 1;
1597 flag_isoc99 = 1;
1598 flag_isoc94 = 1;
1599 lang_hooks.name = "GNU C17";
1603 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1604 static void
1605 set_std_cxx98 (int iso)
1607 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1608 flag_no_gnu_keywords = iso;
1609 flag_no_nonansi_builtin = iso;
1610 flag_iso = iso;
1611 flag_isoc94 = 0;
1612 flag_isoc99 = 0;
1613 cxx_dialect = cxx98;
1614 lang_hooks.name = "GNU C++98";
1617 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1618 static void
1619 set_std_cxx11 (int iso)
1621 cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
1622 flag_no_gnu_keywords = iso;
1623 flag_no_nonansi_builtin = iso;
1624 flag_iso = iso;
1625 /* C++11 includes the C99 standard library. */
1626 flag_isoc94 = 1;
1627 flag_isoc99 = 1;
1628 cxx_dialect = cxx11;
1629 lang_hooks.name = "GNU C++11";
1632 /* Set the C++ 2014 standard (without GNU extensions if ISO). */
1633 static void
1634 set_std_cxx14 (int iso)
1636 cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14);
1637 flag_no_gnu_keywords = iso;
1638 flag_no_nonansi_builtin = iso;
1639 flag_iso = iso;
1640 /* C++14 includes the C99 standard library. */
1641 flag_isoc94 = 1;
1642 flag_isoc99 = 1;
1643 cxx_dialect = cxx14;
1644 lang_hooks.name = "GNU C++14";
1647 /* Set the C++ 2017 standard (without GNU extensions if ISO). */
1648 static void
1649 set_std_cxx17 (int iso)
1651 cpp_set_lang (parse_in, iso ? CLK_CXX17: CLK_GNUCXX17);
1652 flag_no_gnu_keywords = iso;
1653 flag_no_nonansi_builtin = iso;
1654 flag_iso = iso;
1655 /* C++17 includes the C11 standard library. */
1656 flag_isoc94 = 1;
1657 flag_isoc99 = 1;
1658 flag_isoc11 = 1;
1659 cxx_dialect = cxx17;
1660 lang_hooks.name = "GNU C++17";
1663 /* Set the C++ 202a draft standard (without GNU extensions if ISO). */
1664 static void
1665 set_std_cxx2a (int iso)
1667 cpp_set_lang (parse_in, iso ? CLK_CXX2A: CLK_GNUCXX2A);
1668 flag_no_gnu_keywords = iso;
1669 flag_no_nonansi_builtin = iso;
1670 flag_iso = iso;
1671 /* C++17 includes the C11 standard library. */
1672 flag_isoc94 = 1;
1673 flag_isoc99 = 1;
1674 flag_isoc11 = 1;
1675 cxx_dialect = cxx2a;
1676 lang_hooks.name = "GNU C++17"; /* Pretend C++17 until standardization. */
1679 /* Args to -d specify what to dump. Silently ignore
1680 unrecognized options; they may be aimed at toplev.c. */
1681 static void
1682 handle_OPT_d (const char *arg)
1684 char c;
1686 while ((c = *arg++) != '\0')
1687 switch (c)
1689 case 'M': /* Dump macros only. */
1690 case 'N': /* Dump names. */
1691 case 'D': /* Dump definitions. */
1692 case 'U': /* Dump used macros. */
1693 flag_dump_macros = c;
1694 break;
1696 case 'I':
1697 flag_dump_includes = 1;
1698 break;