Merge trunk version 214779 into gupc branch.
[official-gcc.git] / gcc / c-family / c-opts.c
blob51bf7e18ee757d5a32eed2d3e12664a274c788e0
1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002-2014 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 "tree.h"
25 #include "c-common.h"
26 #include "c-pragma.h"
27 #include "c-upc-low.h"
28 #include "c-upc.h"
29 #include "c-upc-pts.h"
30 #include "flags.h"
31 #include "toplev.h"
32 #include "langhooks.h"
33 #include "diagnostic.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 "options.h"
41 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
42 #include "mkdeps.h"
43 #include "c-target.h"
44 #include "tm.h" /* For BYTES_BIG_ENDIAN,
45 DOLLARS_IN_IDENTIFIERS,
46 STDC_0_IN_SYSTEM_HEADERS,
47 TARGET_FLT_EVAL_METHOD_NON_DEFAULT and
48 TARGET_OPTF. */
49 #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
50 #include "dumpfile.h"
52 #ifndef DOLLARS_IN_IDENTIFIERS
53 # define DOLLARS_IN_IDENTIFIERS true
54 #endif
56 #ifndef TARGET_SYSTEM_ROOT
57 # define TARGET_SYSTEM_ROOT NULL
58 #endif
60 #ifndef TARGET_OPTF
61 #define TARGET_OPTF(ARG)
62 #endif
64 /* CPP's options. */
65 cpp_options *cpp_opts;
67 /* Input filename. */
68 static const char *this_input_filename;
70 /* Filename and stream for preprocessed output. */
71 static const char *out_fname;
72 static FILE *out_stream;
74 /* Append dependencies to deps_file. */
75 static bool deps_append;
77 /* If dependency switches (-MF etc.) have been given. */
78 static bool deps_seen;
80 /* If -v seen. */
81 static bool verbose;
83 /* Dependency output file. */
84 static const char *deps_file;
86 /* The prefix given by -iprefix, if any. */
87 static const char *iprefix;
89 /* The multilib directory given by -imultilib, if any. */
90 static const char *imultilib;
92 /* The system root, if any. Overridden by -isysroot. */
93 static const char *sysroot = TARGET_SYSTEM_ROOT;
95 /* Zero disables all standard directories for headers. */
96 static bool std_inc = true;
98 /* Zero disables the C++-specific standard directories for headers. */
99 static bool std_cxx_inc = true;
101 /* If the quote chain has been split by -I-. */
102 static bool quote_chain_split;
104 /* Number of deferred options. */
105 static size_t deferred_count;
107 /* Number of deferred options scanned for -include. */
108 static size_t include_cursor;
110 /* Dump files/flags to use during parsing. */
111 static FILE *original_dump_file = NULL;
112 static int original_dump_flags;
113 static FILE *class_dump_file = NULL;
114 static int class_dump_flags;
116 /* Whether any standard preincluded header has been preincluded. */
117 static bool done_preinclude;
119 static void handle_OPT_d (const char *);
120 static void set_std_cxx98 (int);
121 static void set_std_cxx11 (int);
122 static void set_std_cxx14 (int);
123 static void set_std_cxx1z (int);
124 static void set_std_c89 (int, int);
125 static void set_std_c99 (int);
126 static void set_std_c11 (int);
127 static void check_deps_environment_vars (void);
128 static void handle_deferred_opts (void);
129 static void sanitize_cpp_opts (void);
130 static void add_prefixed_path (const char *, size_t);
131 static void push_command_line_include (void);
132 static void cb_file_change (cpp_reader *, const struct line_map *);
133 static void cb_dir_change (cpp_reader *, const char *);
134 static void c_finish_options (void);
136 #ifndef STDC_0_IN_SYSTEM_HEADERS
137 #define STDC_0_IN_SYSTEM_HEADERS 0
138 #endif
140 /* Holds switches parsed by c_common_handle_option (), but whose
141 handling is deferred to c_common_post_options (). */
142 static void defer_opt (enum opt_code, const char *);
143 static struct deferred_opt
145 enum opt_code code;
146 const char *arg;
147 } *deferred_opts;
150 extern const unsigned int
151 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
153 /* Defer option CODE with argument ARG. */
154 static void
155 defer_opt (enum opt_code code, const char *arg)
157 deferred_opts[deferred_count].code = code;
158 deferred_opts[deferred_count].arg = arg;
159 deferred_count++;
162 /* Return language mask for option parsing. */
163 unsigned int
164 c_common_option_lang_mask (void)
166 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
167 return lang_flags[c_language];
170 /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
171 static void
172 c_diagnostic_finalizer (diagnostic_context *context,
173 diagnostic_info *diagnostic)
175 diagnostic_show_locus (context, diagnostic);
176 /* By default print macro expansion contexts in the diagnostic
177 finalizer -- for tokens resulting from macro expansion. */
178 virt_loc_aware_diagnostic_finalizer (context, diagnostic);
179 pp_destroy_prefix (context->printer);
180 pp_newline_and_flush (context->printer);
183 /* Common diagnostics initialization. */
184 void
185 c_common_initialize_diagnostics (diagnostic_context *context)
187 /* This is conditionalized only because that is the way the front
188 ends used to do it. Maybe this should be unconditional? */
189 if (c_dialect_cxx ())
191 /* By default wrap lines at 80 characters. Is getenv
192 ("COLUMNS") preferable? */
193 diagnostic_line_cutoff (context) = 80;
194 /* By default, emit location information once for every
195 diagnostic message. */
196 diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
198 diagnostic_finalizer (context) = c_diagnostic_finalizer;
199 context->opt_permissive = OPT_fpermissive;
202 /* Whether options from all C-family languages should be accepted
203 quietly. */
204 static bool accept_all_c_family_options = false;
206 /* Return whether to complain about a wrong-language option. */
207 bool
208 c_common_complain_wrong_lang_p (const struct cl_option *option)
210 if (accept_all_c_family_options
211 && (option->flags & c_family_lang_mask))
212 return false;
214 return true;
217 /* Initialize options structure OPTS. */
218 void
219 c_common_init_options_struct (struct gcc_options *opts)
221 opts->x_flag_exceptions = c_dialect_cxx ();
222 opts->x_warn_pointer_arith = c_dialect_cxx ();
223 opts->x_warn_write_strings = c_dialect_cxx ();
224 opts->x_flag_warn_unused_result = true;
226 /* By default, C99-like requirements for complex multiply and divide. */
227 opts->x_flag_complex_method = 2;
230 /* Initialize UPC-specific options. */
231 static void
232 upc_init_options ()
234 struct cl_option_handlers handlers;
236 /* UPC is based upon the C99 dialect. Assert it here.
237 * We'll let the user override these options as he/she
238 * sees fit. For example, -traditional will disable
239 * prototype checking. */
240 set_std_c99 ( 0 /* iso=0 */ );
242 /* The consensus of the UPC community seems to be that
243 arithmetic on (void *) pointers and sizeof (void)
244 are compilation errors. Enable this warning-as-error
245 mode by default. */
246 warn_pointer_arith = 1;
247 set_default_handlers (&handlers);
248 control_warning_option (OPT_Wpointer_arith, (int) DK_ERROR, true,
249 UNKNOWN_LOCATION, CL_C,
250 &handlers, &global_options, &global_options_set,
251 global_dc);
253 #ifdef ENABLE_UPC_DWARF2_SUPPORT
254 /* Some targets support UPC's DWARF2 extensions by default. */
255 use_upc_dwarf2_extensions = 1;
256 #else
257 use_upc_dwarf2_extensions = 0;
258 #endif
260 flag_upc = 1;
261 flag_upc_threads = 0;
262 flag_upc_pthreads = 0;
263 /* By default, don't map UPC threads to POSIX threads. */
264 flag_upc_pthreads = 0;
265 upc_pthreads_model = upc_pthreads_no_model;
266 /* By default, GASP profiling is off. */
267 flag_upc_instrument = 0;
268 flag_upc_instrument_functions = 0;
269 /* By default, optimization level > 0 defines shared access routines
270 inlining, otherwise use the user specified flag for unconditional
271 enable/disable of inlining (0 - disable, 1 - enable). */
272 flag_upc_inline_lib = -1;
273 /* Disable section anchors. The presence of an unshared equivalent of the
274 shared variables causes a double definition of the symbol names in the
275 assembly code. */
276 flag_section_anchors = 0;
279 /* Common initialization before calling option handlers. */
280 void
281 c_common_init_options (unsigned int decoded_options_count,
282 struct cl_decoded_option *decoded_options)
284 unsigned int i;
285 struct cpp_callbacks *cb;
287 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
288 ident_hash, line_table);
289 cb = cpp_get_callbacks (parse_in);
290 cb->error = c_cpp_error;
292 cpp_opts = cpp_get_options (parse_in);
293 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
294 cpp_opts->objc = c_dialect_objc ();
296 /* Reset to avoid warnings on internal definitions. We set it just
297 before passing on command-line options to cpplib. */
298 cpp_opts->warn_dollars = 0;
300 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
302 if (c_language == clk_c)
304 for (i = 1; i < decoded_options_count; i++)
306 /* If preprocessing assembly language, accept any of the C-family
307 front end options since the driver may pass them through. */
308 if (decoded_options[i].opt_index == OPT_lang_asm)
310 accept_all_c_family_options = true;
311 break;
313 /* If compiling UPC, initialize appropriate default options. */
314 if (decoded_options[i].opt_index == OPT_fupc)
316 upc_init_options ();
317 break;
323 /* Process UPC specific command line switches */
325 static bool
326 upc_handle_option (const enum opt_code code, const char *arg, const int value)
328 int result = 1;
329 if (!flag_upc)
331 error ("%s is supported only when -fupc is also present", arg);
332 return false;
334 switch (code)
336 default:
337 gcc_unreachable ();
338 break;
339 case OPT_fupc:
340 flag_upc = value;
341 break;
342 case OPT_dwarf_2_upc:
343 use_upc_dwarf2_extensions = value;
344 break;
345 case OPT_fupc_debug:
346 if ((value == 1) && (flag_upc_inline_lib == 1))
347 error ("-fupc-debug is incompatible with -fupc-inline-lib");
348 flag_upc_debug = value;
349 break;
350 case OPT_fupc_inline_lib:
351 if ((value == 1) && (flag_upc_instrument == 1))
352 error ("-fupc-inline-lib is incompatible with -fupc-instrument");
353 if ((value == 1) && (flag_upc_debug == 1))
354 error ("-fupc-inline-lib is incompatible with -fupc-debug");
355 flag_upc_inline_lib = value;
356 break;
357 case OPT_fupc_instrument:
358 if ((value == 1) && (flag_upc_inline_lib == 1))
359 error ("-fupc-instrument is incompatible with -fupc-inline-lib");
360 flag_upc_instrument = value;
361 break;
362 case OPT_fupc_instrument_functions:
363 if ((value == 1) && (flag_upc_inline_lib == 1))
364 error
365 ("-fupc-instrument-functions is incompatible "
366 "with -fupc-inline-lib");
367 flag_upc_instrument = value;
368 flag_upc_instrument_functions = value;
369 break;
370 case OPT_fupc_pthreads_model_tls:
371 flag_upc_pthreads = 1;
372 upc_pthreads_model = upc_pthreads_tls_model;
373 break;
374 case OPT_fupc_threads_:
376 int num_threads = value;
377 if (num_threads > UPC_MAX_THREADS)
379 error ("THREADS value exceeds UPC implementation limit of %d",
380 UPC_MAX_THREADS);
381 num_threads = 1;
383 flag_upc_threads = num_threads;
385 break;
387 return result;
390 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
391 form of an -f or -W option was given. Returns false if the switch was
392 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
393 bool
394 c_common_handle_option (size_t scode, const char *arg, int value,
395 int kind, location_t loc,
396 const struct cl_option_handlers *handlers)
398 const struct cl_option *option = &cl_options[scode];
399 enum opt_code code = (enum opt_code) scode;
400 bool result = true;
402 /* Prevent resetting the language standard to a C dialect when the driver
403 has already determined that we're looking at assembler input. */
404 bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
406 switch (code)
408 default:
409 if (cl_options[code].flags & c_family_lang_mask)
411 if ((option->flags & CL_TARGET)
412 && ! targetcm.handle_c_option (scode, arg, value))
413 result = false;
414 break;
416 result = false;
417 break;
419 case OPT__output_pch_:
420 pch_file = arg;
421 break;
423 case OPT_A:
424 defer_opt (code, arg);
425 break;
427 case OPT_C:
428 cpp_opts->discard_comments = 0;
429 break;
431 case OPT_CC:
432 cpp_opts->discard_comments = 0;
433 cpp_opts->discard_comments_in_macro_exp = 0;
434 break;
436 case OPT_D:
437 defer_opt (code, arg);
438 break;
440 case OPT_H:
441 cpp_opts->print_include_names = 1;
442 break;
444 case OPT_F:
445 TARGET_OPTF (xstrdup (arg));
446 break;
448 case OPT_I:
449 if (strcmp (arg, "-"))
450 add_path (xstrdup (arg), BRACKET, 0, true);
451 else
453 if (quote_chain_split)
454 error ("-I- specified twice");
455 quote_chain_split = true;
456 split_quote_chain ();
457 inform (input_location, "obsolete option -I- used, please use -iquote instead");
459 break;
461 case OPT_M:
462 case OPT_MM:
463 /* When doing dependencies with -M or -MM, suppress normal
464 preprocessed output, but still do -dM etc. as software
465 depends on this. Preprocessed output does occur if -MD, -MMD
466 or environment var dependency generation is used. */
467 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
468 flag_no_output = 1;
469 break;
471 case OPT_MD:
472 case OPT_MMD:
473 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
474 cpp_opts->deps.need_preprocessor_output = true;
475 deps_file = arg;
476 break;
478 case OPT_MF:
479 deps_seen = true;
480 deps_file = arg;
481 break;
483 case OPT_MG:
484 deps_seen = true;
485 cpp_opts->deps.missing_files = true;
486 break;
488 case OPT_MP:
489 deps_seen = true;
490 cpp_opts->deps.phony_targets = true;
491 break;
493 case OPT_MQ:
494 case OPT_MT:
495 deps_seen = true;
496 defer_opt (code, arg);
497 break;
499 case OPT_P:
500 flag_no_line_commands = 1;
501 break;
503 case OPT_U:
504 defer_opt (code, arg);
505 break;
507 case OPT_Wall:
508 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
510 cpp_opts->warn_num_sign_change = value;
511 break;
513 case OPT_Wc___compat:
514 cpp_opts->warn_cxx_operator_names = value;
515 break;
517 case OPT_Wlong_long:
518 cpp_opts->cpp_warn_long_long = value;
519 break;
521 case OPT_Wnormalized_:
522 /* FIXME: Move all this to c.opt. */
523 if (kind == DK_ERROR)
525 gcc_assert (!arg);
526 inform (input_location, "-Werror=normalized=: set -Wnormalized=nfc");
527 cpp_opts->warn_normalize = normalized_C;
529 else
531 if (!value || (arg && strcasecmp (arg, "none") == 0))
532 cpp_opts->warn_normalize = normalized_none;
533 else if (!arg || strcasecmp (arg, "nfkc") == 0)
534 cpp_opts->warn_normalize = normalized_KC;
535 else if (strcasecmp (arg, "id") == 0)
536 cpp_opts->warn_normalize = normalized_identifier_C;
537 else if (strcasecmp (arg, "nfc") == 0)
538 cpp_opts->warn_normalize = normalized_C;
539 else
540 error ("argument %qs to %<-Wnormalized%> not recognized", arg);
541 break;
544 case OPT_Wtraditional:
545 cpp_opts->cpp_warn_traditional = value;
546 break;
548 case OPT_Wunknown_pragmas:
549 /* Set to greater than 1, so that even unknown pragmas in
550 system headers will be warned about. */
551 /* ??? There is no way to handle this automatically for now. */
552 warn_unknown_pragmas = value * 2;
553 break;
555 case OPT_ansi:
556 if (!c_dialect_cxx ())
557 set_std_c89 (false, true);
558 else
559 set_std_cxx98 (true);
560 break;
562 case OPT_d:
563 handle_OPT_d (arg);
564 break;
566 case OPT_Wabi_:
567 warn_abi = true;
568 if (value == 1)
570 warning (0, "%<-Wabi=1%> is not supported, using =2");
571 value = 2;
573 flag_abi_compat_version = value;
574 break;
576 case OPT_fcanonical_system_headers:
577 cpp_opts->canonical_system_headers = value;
578 break;
580 case OPT_fcond_mismatch:
581 if (!c_dialect_cxx ())
583 flag_cond_mismatch = value;
584 break;
586 warning (0, "switch %qs is no longer supported", option->opt_text);
587 break;
589 case OPT_fbuiltin_:
590 if (value)
591 result = false;
592 else
593 disable_builtin_function (arg);
594 break;
596 case OPT_fdirectives_only:
597 cpp_opts->directives_only = value;
598 break;
600 case OPT_fdollars_in_identifiers:
601 cpp_opts->dollars_in_ident = value;
602 break;
604 case OPT_ffreestanding:
605 value = !value;
606 /* Fall through.... */
607 case OPT_fhosted:
608 flag_hosted = value;
609 flag_no_builtin = !value;
610 break;
612 case OPT_fconstant_string_class_:
613 constant_string_class_name = arg;
614 break;
616 case OPT_fextended_identifiers:
617 cpp_opts->extended_identifiers = value;
618 break;
620 case OPT_foperator_names:
621 cpp_opts->operator_names = value;
622 break;
624 case OPT_fpch_deps:
625 cpp_opts->restore_pch_deps = value;
626 break;
628 case OPT_fpch_preprocess:
629 flag_pch_preprocess = value;
630 break;
632 case OPT_fpermissive:
633 flag_permissive = value;
634 global_dc->permissive = value;
635 break;
637 case OPT_fpreprocessed:
638 cpp_opts->preprocessed = value;
639 break;
641 case OPT_fdebug_cpp:
642 cpp_opts->debug = 1;
643 break;
645 case OPT_ftrack_macro_expansion:
646 if (value)
647 value = 2;
648 /* Fall Through. */
650 case OPT_ftrack_macro_expansion_:
651 if (arg && *arg != '\0')
652 cpp_opts->track_macro_expansion = value;
653 else
654 cpp_opts->track_macro_expansion = 2;
655 break;
657 case OPT_frepo:
658 flag_use_repository = value;
659 if (value)
660 flag_implicit_templates = 0;
661 break;
663 case OPT_ftabstop_:
664 /* It is documented that we silently ignore silly values. */
665 if (value >= 1 && value <= 100)
666 cpp_opts->tabstop = value;
667 break;
669 case OPT_fexec_charset_:
670 cpp_opts->narrow_charset = arg;
671 break;
673 case OPT_fwide_exec_charset_:
674 cpp_opts->wide_charset = arg;
675 break;
677 case OPT_finput_charset_:
678 cpp_opts->input_charset = arg;
679 break;
681 case OPT_ftemplate_depth_:
682 max_tinst_depth = value;
683 break;
685 case OPT_fvisibility_inlines_hidden:
686 visibility_options.inlines_hidden = value;
687 break;
689 case OPT_femit_struct_debug_baseonly:
690 set_struct_debug_option (&global_options, loc, "base");
691 break;
693 case OPT_femit_struct_debug_reduced:
694 set_struct_debug_option (&global_options, loc,
695 "dir:ord:sys,dir:gen:any,ind:base");
696 break;
698 case OPT_femit_struct_debug_detailed_:
699 set_struct_debug_option (&global_options, loc, arg);
700 break;
702 case OPT_fext_numeric_literals:
703 cpp_opts->ext_numeric_literals = value;
704 break;
706 case OPT_fupc:
707 case OPT_dwarf_2_upc:
708 case OPT_fupc_debug:
709 case OPT_fupc_inline_lib:
710 case OPT_fupc_instrument:
711 case OPT_fupc_instrument_functions:
712 case OPT_fupc_pthreads_model_tls:
713 case OPT_fupc_threads_:
714 result = upc_handle_option (code, arg, value);
715 break;
717 case OPT_idirafter:
718 add_path (xstrdup (arg), AFTER, 0, true);
719 break;
721 case OPT_imacros:
722 case OPT_include:
723 defer_opt (code, arg);
724 break;
726 case OPT_imultilib:
727 imultilib = arg;
728 break;
730 case OPT_iprefix:
731 iprefix = arg;
732 break;
734 case OPT_iquote:
735 add_path (xstrdup (arg), QUOTE, 0, true);
736 break;
738 case OPT_isysroot:
739 sysroot = arg;
740 break;
742 case OPT_isystem:
743 add_path (xstrdup (arg), SYSTEM, 0, true);
744 break;
746 case OPT_iwithprefix:
747 add_prefixed_path (arg, SYSTEM);
748 break;
750 case OPT_iwithprefixbefore:
751 add_prefixed_path (arg, BRACKET);
752 break;
754 case OPT_lang_asm:
755 cpp_set_lang (parse_in, CLK_ASM);
756 cpp_opts->dollars_in_ident = false;
757 break;
759 case OPT_nostdinc:
760 std_inc = false;
761 break;
763 case OPT_nostdinc__:
764 std_cxx_inc = false;
765 break;
767 case OPT_o:
768 if (!out_fname)
769 out_fname = arg;
770 else
771 error ("output filename specified twice");
772 break;
774 /* We need to handle the -Wpedantic switch here, rather than in
775 c_common_post_options, so that a subsequent -Wno-endif-labels
776 is not overridden. */
777 case OPT_Wpedantic:
778 cpp_opts->cpp_pedantic = 1;
779 cpp_opts->warn_endif_labels = 1;
780 break;
782 case OPT_print_objc_runtime_info:
783 print_struct_values = 1;
784 break;
786 case OPT_remap:
787 cpp_opts->remap = 1;
788 break;
790 case OPT_std_c__98:
791 case OPT_std_gnu__98:
792 if (!preprocessing_asm_p)
793 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
794 break;
796 case OPT_std_c__11:
797 case OPT_std_gnu__11:
798 if (!preprocessing_asm_p)
800 set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
801 if (code == OPT_std_c__11)
802 cpp_opts->ext_numeric_literals = 0;
804 break;
806 case OPT_std_c__14:
807 case OPT_std_gnu__14:
808 if (!preprocessing_asm_p)
810 set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
811 if (code == OPT_std_c__14)
812 cpp_opts->ext_numeric_literals = 0;
814 break;
816 case OPT_std_c__1z:
817 case OPT_std_gnu__1z:
818 if (!preprocessing_asm_p)
820 set_std_cxx1z (code == OPT_std_c__1z /* ISO */);
821 if (code == OPT_std_c__1z)
822 cpp_opts->ext_numeric_literals = 0;
824 break;
826 case OPT_std_c90:
827 case OPT_std_iso9899_199409:
828 if (!preprocessing_asm_p)
829 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
830 break;
832 case OPT_std_gnu90:
833 if (!preprocessing_asm_p)
834 set_std_c89 (false /* c94 */, false /* ISO */);
835 break;
837 case OPT_std_c99:
838 if (!preprocessing_asm_p)
839 set_std_c99 (true /* ISO */);
840 break;
842 case OPT_std_gnu99:
843 if (!preprocessing_asm_p)
844 set_std_c99 (false /* ISO */);
845 break;
847 case OPT_std_c11:
848 if (!preprocessing_asm_p)
849 set_std_c11 (true /* ISO */);
850 break;
852 case OPT_std_gnu11:
853 if (!preprocessing_asm_p)
854 set_std_c11 (false /* ISO */);
855 break;
857 case OPT_trigraphs:
858 cpp_opts->trigraphs = 1;
859 break;
861 case OPT_traditional_cpp:
862 cpp_opts->traditional = 1;
863 break;
865 case OPT_v:
866 verbose = true;
867 break;
869 case OPT_Wabi:
870 warn_psabi = value;
871 break;
874 switch (c_language)
876 case clk_c:
877 C_handle_option_auto (&global_options, &global_options_set,
878 scode, arg, value,
879 c_family_lang_mask, kind,
880 loc, handlers, global_dc);
881 break;
883 case clk_objc:
884 ObjC_handle_option_auto (&global_options, &global_options_set,
885 scode, arg, value,
886 c_family_lang_mask, kind,
887 loc, handlers, global_dc);
888 break;
890 case clk_cxx:
891 CXX_handle_option_auto (&global_options, &global_options_set,
892 scode, arg, value,
893 c_family_lang_mask, kind,
894 loc, handlers, global_dc);
895 break;
897 case clk_objcxx:
898 ObjCXX_handle_option_auto (&global_options, &global_options_set,
899 scode, arg, value,
900 c_family_lang_mask, kind,
901 loc, handlers, global_dc);
902 break;
904 default:
905 gcc_unreachable ();
908 cpp_handle_option_auto (&global_options, scode, cpp_opts);
909 return result;
912 /* Default implementation of TARGET_HANDLE_C_OPTION. */
914 bool
915 default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
916 const char *arg ATTRIBUTE_UNUSED,
917 int value ATTRIBUTE_UNUSED)
919 return false;
922 /* Post-switch processing. */
923 bool
924 c_common_post_options (const char **pfilename)
926 struct cpp_callbacks *cb;
928 /* Canonicalize the input and output filenames. */
929 if (in_fnames == NULL)
931 in_fnames = XNEWVEC (const char *, 1);
932 in_fnames[0] = "";
934 else if (strcmp (in_fnames[0], "-") == 0)
935 in_fnames[0] = "";
937 if (out_fname == NULL || !strcmp (out_fname, "-"))
938 out_fname = "";
940 if (cpp_opts->deps.style == DEPS_NONE)
941 check_deps_environment_vars ();
943 handle_deferred_opts ();
945 sanitize_cpp_opts ();
947 register_include_chains (parse_in, sysroot, iprefix, imultilib,
948 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
950 #ifdef C_COMMON_OVERRIDE_OPTIONS
951 /* Some machines may reject certain combinations of C
952 language-specific options. */
953 C_COMMON_OVERRIDE_OPTIONS;
954 #endif
956 /* Excess precision other than "fast" requires front-end
957 support. */
958 if (c_dialect_cxx ())
960 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
961 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
962 sorry ("-fexcess-precision=standard for C++");
963 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
965 else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
966 flag_excess_precision_cmdline = (flag_iso
967 ? EXCESS_PRECISION_STANDARD
968 : EXCESS_PRECISION_FAST);
970 /* ISO C restricts floating-point expression contraction to within
971 source-language expressions (-ffp-contract=on, currently an alias
972 for -ffp-contract=off). */
973 if (flag_iso
974 && !c_dialect_cxx ()
975 && (global_options_set.x_flag_fp_contract_mode
976 == (enum fp_contract_mode) 0)
977 && flag_unsafe_math_optimizations == 0)
978 flag_fp_contract_mode = FP_CONTRACT_OFF;
980 /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
981 inline semantics are not supported in GNU89 or C89 mode. */
982 if (flag_gnu89_inline == -1)
983 flag_gnu89_inline = !flag_isoc99;
984 else if (!flag_gnu89_inline && !flag_isoc99)
985 error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
987 /* Default to ObjC sjlj exception handling if NeXT runtime. */
988 if (flag_objc_sjlj_exceptions < 0)
989 flag_objc_sjlj_exceptions = flag_next_runtime;
990 if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
991 flag_exceptions = 1;
993 /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
994 pattern recognition. */
995 if (!global_options_set.x_flag_tree_loop_distribute_patterns
996 && flag_no_builtin)
997 flag_tree_loop_distribute_patterns = 0;
999 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
1000 It is never enabled in C++, as the minimum limit is not normative
1001 in that standard. */
1002 if (c_dialect_cxx ())
1003 warn_overlength_strings = 0;
1005 /* Wmain is enabled by default in C++ but not in C. */
1006 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
1007 even if -Wall or -Wpedantic was given (warn_main will be 2 if set
1008 by -Wall, 1 if set by -Wmain). */
1009 if (warn_main == -1)
1010 warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
1011 else if (warn_main == 2)
1012 warn_main = flag_hosted ? 1 : 0;
1014 /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
1015 yet been set, it is disabled by default. In C++, it is enabled
1016 by default. */
1017 if (warn_enum_compare == -1)
1018 warn_enum_compare = c_dialect_cxx () ? 1 : 0;
1020 /* -Wpacked-bitfield-compat is on by default for the C languages. The
1021 warning is issued in stor-layout.c which is not part of the front-end so
1022 we need to selectively turn it on here. */
1023 if (warn_packed_bitfield_compat == -1)
1024 warn_packed_bitfield_compat = 1;
1026 /* Special format checking options don't work without -Wformat; warn if
1027 they are used. */
1028 if (!warn_format)
1030 warning (OPT_Wformat_y2k,
1031 "-Wformat-y2k ignored without -Wformat");
1032 warning (OPT_Wformat_extra_args,
1033 "-Wformat-extra-args ignored without -Wformat");
1034 warning (OPT_Wformat_zero_length,
1035 "-Wformat-zero-length ignored without -Wformat");
1036 warning (OPT_Wformat_nonliteral,
1037 "-Wformat-nonliteral ignored without -Wformat");
1038 warning (OPT_Wformat_contains_nul,
1039 "-Wformat-contains-nul ignored without -Wformat");
1040 warning (OPT_Wformat_security,
1041 "-Wformat-security ignored without -Wformat");
1044 /* -Wimplicit-function-declaration is enabled by default for C99. */
1045 if (warn_implicit_function_declaration == -1)
1046 warn_implicit_function_declaration = flag_isoc99;
1048 /* Declone C++ 'structors if -Os. */
1049 if (flag_declone_ctor_dtor == -1)
1050 flag_declone_ctor_dtor = optimize_size;
1052 if (flag_abi_compat_version == 1)
1054 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
1055 flag_abi_compat_version = 2;
1057 else if (flag_abi_compat_version == -1)
1059 /* Generate compatibility aliases for ABI v2 (3.4-4.9) by default. */
1060 flag_abi_compat_version = (flag_abi_version == 0 ? 2 : 0);
1062 /* But don't warn about backward compatibility unless explicitly
1063 requested with -Wabi=n. */
1064 if (flag_abi_version == 0)
1065 warn_abi = false;
1068 if (cxx_dialect >= cxx11)
1070 /* If we're allowing C++0x constructs, don't warn about C++98
1071 identifiers which are keywords in C++0x. */
1072 warn_cxx0x_compat = 0;
1074 if (warn_narrowing == -1)
1075 warn_narrowing = 1;
1077 else if (warn_narrowing == -1)
1078 warn_narrowing = 0;
1080 if (flag_extern_tls_init)
1082 #if !defined (ASM_OUTPUT_DEF) || !SUPPORTS_WEAK
1083 /* Lazy TLS initialization for a variable in another TU requires
1084 alias and weak reference support. */
1085 if (flag_extern_tls_init > 0)
1086 sorry ("external TLS initialization functions not supported "
1087 "on this target");
1088 flag_extern_tls_init = 0;
1089 #else
1090 flag_extern_tls_init = 1;
1091 #endif
1094 if (flag_preprocess_only)
1096 /* Open the output now. We must do so even if flag_no_output is
1097 on, because there may be other output than from the actual
1098 preprocessing (e.g. from -dM). */
1099 if (out_fname[0] == '\0')
1100 out_stream = stdout;
1101 else
1102 out_stream = fopen (out_fname, "w");
1104 if (out_stream == NULL)
1106 fatal_error ("opening output file %s: %m", out_fname);
1107 return false;
1110 if (num_in_fnames > 1)
1111 error ("too many filenames given. Type %s --help for usage",
1112 progname);
1114 init_pp_output (out_stream);
1116 else
1118 init_c_lex ();
1120 /* When writing a PCH file, avoid reading some other PCH file,
1121 because the default address space slot then can't be used
1122 for the output PCH file. */
1123 if (pch_file)
1125 c_common_no_more_pch ();
1126 /* Only -g0 and -gdwarf* are supported with PCH, for other
1127 debug formats we warn here and refuse to load any PCH files. */
1128 if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1129 warning (OPT_Wdeprecated,
1130 "the \"%s\" debug format cannot be used with "
1131 "pre-compiled headers", debug_type_names[write_symbols]);
1133 else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1134 c_common_no_more_pch ();
1136 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1137 input_location = UNKNOWN_LOCATION;
1140 cb = cpp_get_callbacks (parse_in);
1141 cb->file_change = cb_file_change;
1142 cb->dir_change = cb_dir_change;
1143 cpp_post_options (parse_in);
1144 init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
1146 input_location = UNKNOWN_LOCATION;
1148 *pfilename = this_input_filename
1149 = cpp_read_main_file (parse_in, in_fnames[0]);
1150 /* Don't do any compilation or preprocessing if there is no input file. */
1151 if (this_input_filename == NULL)
1153 errorcount++;
1154 return false;
1157 if (flag_working_directory
1158 && flag_preprocess_only && !flag_no_line_commands)
1159 pp_dir_change (parse_in, get_src_pwd ());
1161 /* Disable LTO output when outputting a precompiled header. */
1162 if (pch_file && flag_lto)
1164 flag_lto = 0;
1165 flag_generate_lto = 0;
1168 return flag_preprocess_only;
1171 /* Front end initialization common to C, ObjC and C++. */
1172 bool
1173 c_common_init (void)
1175 /* Set up preprocessor arithmetic. Must be done after call to
1176 c_common_nodes_and_builtins for type nodes to be good. */
1177 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1178 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1179 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1180 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1181 cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1182 cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1184 /* This can't happen until after wchar_precision and bytes_big_endian
1185 are known. */
1186 cpp_init_iconv (parse_in);
1188 if (version_flag)
1190 int i;
1191 fputs ("Compiler executable checksum: ", stderr);
1192 for (i = 0; i < 16; i++)
1193 fprintf (stderr, "%02x", executable_checksum[i]);
1194 putc ('\n', stderr);
1197 /* Has to wait until now so that cpplib has its hash table. */
1198 init_pragma ();
1200 if (flag_preprocess_only)
1202 c_finish_options ();
1203 preprocess_file (parse_in);
1204 return false;
1207 return true;
1210 /* Initialize the integrated preprocessor after debug output has been
1211 initialized; loop over each input file. */
1212 void
1213 c_common_parse_file (void)
1215 unsigned int i;
1217 i = 0;
1218 for (;;)
1220 c_finish_options ();
1221 /* Open the dump files to use for the original and class dump output
1222 here, to be used during parsing for the current file. */
1223 original_dump_file = dump_begin (TDI_original, &original_dump_flags);
1224 class_dump_file = dump_begin (TDI_class, &class_dump_flags);
1225 pch_init ();
1226 push_file_scope ();
1227 c_parse_file ();
1228 /* Generate UPC global initialization code, if required. */
1229 if (flag_upc)
1230 upc_write_global_declarations ();
1231 pop_file_scope ();
1232 /* And end the main input file, if the debug writer wants it */
1233 if (debug_hooks->start_end_main_source_file)
1234 (*debug_hooks->end_source_file) (0);
1235 if (++i >= num_in_fnames)
1236 break;
1237 cpp_undef_all (parse_in);
1238 cpp_clear_file_cache (parse_in);
1239 this_input_filename
1240 = cpp_read_main_file (parse_in, in_fnames[i]);
1241 if (original_dump_file)
1243 dump_end (TDI_original, original_dump_file);
1244 original_dump_file = NULL;
1246 if (class_dump_file)
1248 dump_end (TDI_class, class_dump_file);
1249 class_dump_file = NULL;
1251 /* If an input file is missing, abandon further compilation.
1252 cpplib has issued a diagnostic. */
1253 if (!this_input_filename)
1254 break;
1258 /* Returns the appropriate dump file for PHASE to dump with FLAGS. */
1259 FILE *
1260 get_dump_info (int phase, int *flags)
1262 gcc_assert (phase == TDI_original || phase == TDI_class);
1263 if (phase == TDI_original)
1265 *flags = original_dump_flags;
1266 return original_dump_file;
1268 else
1270 *flags = class_dump_flags;
1271 return class_dump_file;
1275 /* Common finish hook for the C, ObjC and C++ front ends. */
1276 void
1277 c_common_finish (void)
1279 FILE *deps_stream = NULL;
1281 /* Don't write the deps file if there are errors. */
1282 if (cpp_opts->deps.style != DEPS_NONE && !seen_error ())
1284 /* If -M or -MM was seen without -MF, default output to the
1285 output stream. */
1286 if (!deps_file)
1287 deps_stream = out_stream;
1288 else
1290 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1291 if (!deps_stream)
1292 fatal_error ("opening dependency file %s: %m", deps_file);
1296 /* For performance, avoid tearing down cpplib's internal structures
1297 with cpp_destroy (). */
1298 cpp_finish (parse_in, deps_stream);
1300 if (deps_stream && deps_stream != out_stream
1301 && (ferror (deps_stream) || fclose (deps_stream)))
1302 fatal_error ("closing dependency file %s: %m", deps_file);
1304 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1305 fatal_error ("when writing output to %s: %m", out_fname);
1308 /* Either of two environment variables can specify output of
1309 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1310 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1311 and DEPS_TARGET is the target to mention in the deps. They also
1312 result in dependency information being appended to the output file
1313 rather than overwriting it, and like Sun's compiler
1314 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1315 static void
1316 check_deps_environment_vars (void)
1318 char *spec;
1320 spec = getenv ("DEPENDENCIES_OUTPUT");
1321 if (spec)
1322 cpp_opts->deps.style = DEPS_USER;
1323 else
1325 spec = getenv ("SUNPRO_DEPENDENCIES");
1326 if (spec)
1328 cpp_opts->deps.style = DEPS_SYSTEM;
1329 cpp_opts->deps.ignore_main_file = true;
1333 if (spec)
1335 /* Find the space before the DEPS_TARGET, if there is one. */
1336 char *s = strchr (spec, ' ');
1337 if (s)
1339 /* Let the caller perform MAKE quoting. */
1340 defer_opt (OPT_MT, s + 1);
1341 *s = '\0';
1344 /* Command line -MF overrides environment variables and default. */
1345 if (!deps_file)
1346 deps_file = spec;
1348 deps_append = 1;
1349 deps_seen = true;
1353 /* Handle deferred command line switches. */
1354 static void
1355 handle_deferred_opts (void)
1357 size_t i;
1358 struct deps *deps;
1360 /* Avoid allocating the deps buffer if we don't need it.
1361 (This flag may be true without there having been -MT or -MQ
1362 options, but we'll still need the deps buffer.) */
1363 if (!deps_seen)
1364 return;
1366 deps = cpp_get_deps (parse_in);
1368 for (i = 0; i < deferred_count; i++)
1370 struct deferred_opt *opt = &deferred_opts[i];
1372 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1373 deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1377 /* These settings are appropriate for GCC, but not necessarily so for
1378 cpplib as a library. */
1379 static void
1380 sanitize_cpp_opts (void)
1382 /* If we don't know what style of dependencies to output, complain
1383 if any other dependency switches have been given. */
1384 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1385 error ("to generate dependencies you must specify either -M or -MM");
1387 /* -dM and dependencies suppress normal output; do it here so that
1388 the last -d[MDN] switch overrides earlier ones. */
1389 if (flag_dump_macros == 'M')
1390 flag_no_output = 1;
1392 /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1393 to perform proper macro expansion. */
1394 if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1395 flag_dump_macros = 'D';
1397 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1398 -dM since at least glibc relies on -M -dM to work. */
1399 /* Also, flag_no_output implies flag_no_line_commands, always. */
1400 if (flag_no_output)
1402 if (flag_dump_macros != 'M')
1403 flag_dump_macros = 0;
1404 flag_dump_includes = 0;
1405 flag_no_line_commands = 1;
1407 else if (cpp_opts->deps.missing_files)
1408 error ("-MG may only be used with -M or -MM");
1410 cpp_opts->unsigned_char = !flag_signed_char;
1411 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1412 cpp_opts->cpp_warn_c90_c99_compat = warn_c90_c99_compat;
1414 /* Wlong-long is disabled by default. It is enabled by:
1415 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1416 [-Wpedantic | -Wtraditional] -std=non-c99 ; or
1417 -Wc90-c99-compat, if specified.
1419 Either -Wlong-long or -Wno-long-long override any other settings. */
1420 if (warn_long_long == -1 && warn_c90_c99_compat != -1)
1421 warn_long_long = warn_c90_c99_compat;
1422 else if (warn_long_long == -1)
1423 warn_long_long = ((pedantic || warn_traditional)
1424 && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1425 cpp_opts->cpp_warn_long_long = warn_long_long;
1427 /* If we're generating preprocessor output, emit current directory
1428 if explicitly requested or if debugging information is enabled.
1429 ??? Maybe we should only do it for debugging formats that
1430 actually output the current directory? */
1431 if (flag_working_directory == -1)
1432 flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1434 if (cpp_opts->directives_only)
1436 if (cpp_warn_unused_macros)
1437 error ("-fdirectives-only is incompatible with -Wunused_macros");
1438 if (cpp_opts->traditional)
1439 error ("-fdirectives-only is incompatible with -traditional");
1443 /* Add include path with a prefix at the front of its name. */
1444 static void
1445 add_prefixed_path (const char *suffix, size_t chain)
1447 char *path;
1448 const char *prefix;
1449 size_t prefix_len, suffix_len;
1451 suffix_len = strlen (suffix);
1452 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1453 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1455 path = (char *) xmalloc (prefix_len + suffix_len + 1);
1456 memcpy (path, prefix, prefix_len);
1457 memcpy (path + prefix_len, suffix, suffix_len);
1458 path[prefix_len + suffix_len] = '\0';
1460 add_path (path, chain, 0, false);
1463 /* Handle -D, -U, -A, -imacros, and the first -include. */
1464 static void
1465 c_finish_options (void)
1467 if (!cpp_opts->preprocessed)
1469 size_t i;
1471 cb_file_change (parse_in,
1472 linemap_add (line_table, LC_RENAME, 0,
1473 _("<built-in>"), 0));
1474 /* Make sure all of the builtins about to be declared have
1475 BUILTINS_LOCATION has their source_location. */
1476 source_location builtins_loc = BUILTINS_LOCATION;
1477 cpp_force_token_locations (parse_in, &builtins_loc);
1479 cpp_init_builtins (parse_in, flag_hosted);
1480 c_cpp_builtins (parse_in);
1482 cpp_stop_forcing_token_locations (parse_in);
1484 /* We're about to send user input to cpplib, so make it warn for
1485 things that we previously (when we sent it internal definitions)
1486 told it to not warn.
1488 C99 permits implementation-defined characters in identifiers.
1489 The documented meaning of -std= is to turn off extensions that
1490 conflict with the specified standard, and since a strictly
1491 conforming program cannot contain a '$', we do not condition
1492 their acceptance on the -std= setting. */
1493 cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1495 cb_file_change (parse_in,
1496 linemap_add (line_table, LC_RENAME, 0,
1497 _("<command-line>"), 0));
1499 for (i = 0; i < deferred_count; i++)
1501 struct deferred_opt *opt = &deferred_opts[i];
1503 if (opt->code == OPT_D)
1504 cpp_define (parse_in, opt->arg);
1505 else if (opt->code == OPT_U)
1506 cpp_undef (parse_in, opt->arg);
1507 else if (opt->code == OPT_A)
1509 if (opt->arg[0] == '-')
1510 cpp_unassert (parse_in, opt->arg + 1);
1511 else
1512 cpp_assert (parse_in, opt->arg);
1516 /* Start the main input file, if the debug writer wants it. */
1517 if (debug_hooks->start_end_main_source_file
1518 && !flag_preprocess_only)
1519 (*debug_hooks->start_source_file) (0, this_input_filename);
1521 /* Handle -imacros after -D and -U. */
1522 for (i = 0; i < deferred_count; i++)
1524 struct deferred_opt *opt = &deferred_opts[i];
1526 if (opt->code == OPT_imacros
1527 && cpp_push_include (parse_in, opt->arg))
1529 /* Disable push_command_line_include callback for now. */
1530 include_cursor = deferred_count + 1;
1531 cpp_scan_nooutput (parse_in);
1535 else
1537 if (cpp_opts->directives_only)
1538 cpp_init_special_builtins (parse_in);
1540 /* Start the main input file, if the debug writer wants it. */
1541 if (debug_hooks->start_end_main_source_file
1542 && !flag_preprocess_only)
1543 (*debug_hooks->start_source_file) (0, this_input_filename);
1546 include_cursor = 0;
1547 push_command_line_include ();
1550 /* Give CPP the next file given by -include, if any. */
1551 static void
1552 push_command_line_include (void)
1554 /* This can happen if disabled by -imacros for example.
1555 Punt so that we don't set "<command-line>" as the filename for
1556 the header. */
1557 if (include_cursor > deferred_count)
1558 return;
1560 if (!done_preinclude)
1562 done_preinclude = true;
1563 if (flag_hosted && std_inc && !cpp_opts->preprocessed)
1565 const char *preinc = targetcm.c_preinclude ();
1566 if (preinc && cpp_push_default_include (parse_in, preinc))
1567 return;
1571 pch_cpp_save_state ();
1573 while (include_cursor < deferred_count)
1575 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1577 if (!cpp_opts->preprocessed && opt->code == OPT_include
1578 && cpp_push_include (parse_in, opt->arg))
1579 return;
1582 if (include_cursor == deferred_count)
1584 include_cursor++;
1585 /* -Wunused-macros should only warn about macros defined hereafter. */
1586 cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
1587 /* Restore the line map from <command line>. */
1588 if (!cpp_opts->preprocessed)
1589 cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1591 /* Set this here so the client can change the option if it wishes,
1592 and after stacking the main file so we don't trace the main file. */
1593 line_table->trace_includes = cpp_opts->print_include_names;
1597 /* File change callback. Has to handle -include files. */
1598 static void
1599 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
1600 const struct line_map *new_map)
1602 if (flag_preprocess_only)
1603 pp_file_change (new_map);
1604 else
1605 fe_file_change (new_map);
1607 if (new_map
1608 && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
1610 /* Signal to plugins that a file is included. This could happen
1611 several times with the same file path, e.g. because of
1612 several '#include' or '#line' directives... */
1613 invoke_plugin_callbacks
1614 (PLUGIN_INCLUDE_FILE,
1615 const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
1618 if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1620 pch_cpp_save_state ();
1621 push_command_line_include ();
1625 void
1626 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1628 if (!set_src_pwd (dir))
1629 warning (0, "too late for # directive to set debug directory");
1632 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1633 extensions if ISO). There is no concept of gnu94. */
1634 static void
1635 set_std_c89 (int c94, int iso)
1637 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1638 flag_iso = iso;
1639 flag_no_asm = iso;
1640 flag_no_gnu_keywords = iso;
1641 flag_no_nonansi_builtin = iso;
1642 flag_isoc94 = c94;
1643 flag_isoc99 = 0;
1644 flag_isoc11 = 0;
1647 /* Set the C 99 standard (without GNU extensions if ISO). */
1648 static void
1649 set_std_c99 (int iso)
1651 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1652 flag_no_asm = iso;
1653 flag_no_nonansi_builtin = iso;
1654 flag_iso = iso;
1655 flag_isoc11 = 0;
1656 flag_isoc99 = 1;
1657 flag_isoc94 = 1;
1660 /* Set the C 11 standard (without GNU extensions if ISO). */
1661 static void
1662 set_std_c11 (int iso)
1664 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
1665 flag_no_asm = iso;
1666 flag_no_nonansi_builtin = iso;
1667 flag_iso = iso;
1668 flag_isoc11 = 1;
1669 flag_isoc99 = 1;
1670 flag_isoc94 = 1;
1673 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1674 static void
1675 set_std_cxx98 (int iso)
1677 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1678 flag_no_gnu_keywords = iso;
1679 flag_no_nonansi_builtin = iso;
1680 flag_iso = iso;
1681 cxx_dialect = cxx98;
1684 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1685 static void
1686 set_std_cxx11 (int iso)
1688 cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
1689 flag_no_gnu_keywords = iso;
1690 flag_no_nonansi_builtin = iso;
1691 flag_iso = iso;
1692 /* C++11 includes the C99 standard library. */
1693 flag_isoc94 = 1;
1694 flag_isoc99 = 1;
1695 cxx_dialect = cxx11;
1698 /* Set the C++ 2014 draft standard (without GNU extensions if ISO). */
1699 static void
1700 set_std_cxx14 (int iso)
1702 cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14);
1703 flag_no_gnu_keywords = iso;
1704 flag_no_nonansi_builtin = iso;
1705 flag_iso = iso;
1706 /* C++11 includes the C99 standard library. */
1707 flag_isoc94 = 1;
1708 flag_isoc99 = 1;
1709 cxx_dialect = cxx14;
1712 /* Set the C++ 201z draft standard (without GNU extensions if ISO). */
1713 static void
1714 set_std_cxx1z (int iso)
1716 cpp_set_lang (parse_in, iso ? CLK_CXX1Z: CLK_GNUCXX1Z);
1717 flag_no_gnu_keywords = iso;
1718 flag_no_nonansi_builtin = iso;
1719 flag_iso = iso;
1720 /* C++11 includes the C99 standard library. */
1721 flag_isoc94 = 1;
1722 flag_isoc99 = 1;
1723 flag_isoc11 = 1;
1724 cxx_dialect = cxx1z;
1727 /* Args to -d specify what to dump. Silently ignore
1728 unrecognized options; they may be aimed at toplev.c. */
1729 static void
1730 handle_OPT_d (const char *arg)
1732 char c;
1734 while ((c = *arg++) != '\0')
1735 switch (c)
1737 case 'M': /* Dump macros only. */
1738 case 'N': /* Dump names. */
1739 case 'D': /* Dump definitions. */
1740 case 'U': /* Dump used macros. */
1741 flag_dump_macros = c;
1742 break;
1744 case 'I':
1745 flag_dump_includes = 1;
1746 break;