1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002, 2003 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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
31 #include "langhooks.h"
32 #include "tree-inline.h"
33 #include "diagnostic.h"
35 #include "cppdefault.h"
36 #include "c-incpath.h"
37 #include "debug.h" /* For debug_hooks. */
38 #include "c-options.h"
40 #ifndef DOLLARS_IN_IDENTIFIERS
41 # define DOLLARS_IN_IDENTIFIERS true
44 #ifndef TARGET_SYSTEM_ROOT
45 # define TARGET_SYSTEM_ROOT NULL
49 # define TARGET_EBCDIC 0
52 static int saved_lineno;
55 static cpp_options *cpp_opts;
58 static const char *in_fname;
60 /* Filename and stream for preprocessed output. */
61 static const char *out_fname;
62 static FILE *out_stream;
64 /* Append dependencies to deps_file. */
65 static bool deps_append;
67 /* If dependency switches (-MF etc.) have been given. */
68 static bool deps_seen;
73 /* Dependency output file. */
74 static const char *deps_file;
76 /* The prefix given by -iprefix, if any. */
77 static const char *iprefix;
79 /* The system root, if any. Overridden by -isysroot. */
80 static const char *sysroot = TARGET_SYSTEM_ROOT;
82 /* Zero disables all standard directories for headers. */
83 static bool std_inc = true;
85 /* Zero disables the C++-specific standard directories for headers. */
86 static bool std_cxx_inc = true;
88 /* If the quote chain has been split by -I-. */
89 static bool quote_chain_split;
91 /* If -Wunused-macros. */
92 static bool warn_unused_macros;
94 /* Number of deferred options, deferred options array size. */
95 static size_t deferred_count, deferred_size;
97 /* Number of deferred options scanned for -include. */
98 static size_t include_cursor;
100 static void missing_arg PARAMS ((size_t));
101 static size_t find_opt PARAMS ((const char *, int));
102 static void set_Wimplicit PARAMS ((int));
103 static void complain_wrong_lang PARAMS ((size_t));
104 static void write_langs PARAMS ((char *, int));
105 static void print_help PARAMS ((void));
106 static void handle_OPT_d PARAMS ((const char *));
107 static void set_std_cxx98 PARAMS ((int));
108 static void set_std_c89 PARAMS ((int, int));
109 static void set_std_c99 PARAMS ((int));
110 static void check_deps_environment_vars PARAMS ((void));
111 static void handle_deferred_opts PARAMS ((void));
112 static void sanitize_cpp_opts PARAMS ((void));
113 static void add_prefixed_path PARAMS ((const char *, size_t));
114 static void push_command_line_include PARAMS ((void));
115 static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
116 static void finish_options PARAMS ((void));
117 static int c_common_handle_option (enum opt_code, const char *arg, int on);
119 #ifndef STDC_0_IN_SYSTEM_HEADERS
120 #define STDC_0_IN_SYSTEM_HEADERS 0
123 #define CL_C (1 << 0) /* Only C. */
124 #define CL_OBJC (1 << 1) /* Only ObjC. */
125 #define CL_CXX (1 << 2) /* Only C++. */
126 #define CL_OBJCXX (1 << 3) /* Only ObjC++. */
127 #define CL_JOINED (1 << 4) /* If takes joined argument. */
128 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
129 #define CL_REJECT_NEGATIVE (1 << 6) /* Reject no- form. */
131 #include "c-options.c"
133 /* If the user gives an option to a front end that doesn't support it,
134 an error is output, mentioning which front ends the option is valid
135 for. If you don't want this, you must accept it for all front
136 ends, and test for the front end in the option handler. See, for
137 example, the handling of -fcond-mismatch.
139 If you requested a joined or separate argument, it is stored in the
140 variable "arg", which is guaranteed to be non-NULL and to not be an
141 empty string. It points to the argument either within the argv[]
142 vector or within one of that vector's strings, and so the text is
143 permanent and copies need not be made. Be sure to add an error
144 message in missing_arg() if the default is not appropriate. */
146 /* Holds switches parsed by c_common_decode_option (), but whose
147 handling is deferred to c_common_post_options (). */
148 static void defer_opt PARAMS ((enum opt_code, const char *));
149 static struct deferred_opt
155 /* Complain that switch OPT_INDEX expects an argument but none was
158 missing_arg (opt_index)
161 const char *opt_text = cl_options[opt_index].opt_text;
165 case OPT__output_pch_:
168 case OPT_fabi_version_:
171 case OPT_fname_mangling_version_:
173 case OPT_ftemplate_depth_:
175 case OPT_iwithprefix:
176 case OPT_iwithprefixbefore:
178 error ("missing argument to \"-%s\"", opt_text);
181 case OPT_fconstant_string_class_:
182 error ("no class name specified with \"-%s\"", opt_text);
186 error ("assertion missing after \"-%s\"", opt_text);
191 error ("macro name missing after \"-%s\"", opt_text);
198 error ("missing path after \"-%s\"", opt_text);
207 error ("missing filename after \"-%s\"", opt_text);
212 error ("missing target after \"-%s\"", opt_text);
217 /* Perform a binary search to find which option the command-line INPUT
218 matches. Returns its index in the option array, and N_OPTS on
221 Complications arise since some options can be suffixed with an
222 argument, and multiple complete matches can occur, e.g. -pedantic
223 and -pedantic-errors. Also, some options are only accepted by some
224 languages. If a switch matches for a different language and
225 doesn't match any alternatives for the true front end, the index of
226 the matched switch is returned anyway. The caller should check for
229 find_opt (input, lang_flag)
235 size_t result = N_OPTS;
245 opt_len = cl_options[md].opt_len;
246 comp = strncmp (input, cl_options[md].opt_text, opt_len);
254 /* The switch matches. It it an exact match? */
255 if (input[opt_len] == '\0')
261 /* If the switch takes no arguments this is not a proper
262 match, so we continue the search (e.g. input="stdc++"
263 match was "stdc"). */
264 if (!(cl_options[md].flags & CL_JOINED))
267 /* Is this switch valid for this front end? */
268 if (!(cl_options[md].flags & lang_flag))
270 /* If subsequently we don't find a better match,
271 return this and let the caller report it as a bad
277 /* Two scenarios remain: we have the switch's argument,
278 or we match a longer option. This can happen with
279 -iwithprefix and -withprefixbefore. The longest
280 possible option match succeeds.
282 Scan forwards, and return an exact match. Otherwise
283 return the longest valid option-accepting match (mx).
284 This loops at most twice with current options. */
286 for (md = md + 1; md < (size_t) N_OPTS; md++)
288 opt_len = cl_options[md].opt_len;
289 if (strncmp (input, cl_options[md].opt_text, opt_len))
291 if (input[opt_len] == '\0')
293 if (cl_options[md].flags & lang_flag
294 && cl_options[md].flags & CL_JOINED)
306 /* Defer option CODE with argument ARG. */
308 defer_opt (code, arg)
312 /* FIXME: this should be in c_common_init_options, which should take
316 extern int save_argc;
317 deferred_size = save_argc;
318 deferred_opts = (struct deferred_opt *)
319 xmalloc (deferred_size * sizeof (struct deferred_opt));
322 if (deferred_count == deferred_size)
325 deferred_opts[deferred_count].code = code;
326 deferred_opts[deferred_count].arg = arg;
330 /* Common initialization before parsing options. */
332 c_common_init_options (lang)
333 enum c_language_kind lang;
336 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX,
338 cpp_opts = cpp_get_options (parse_in);
339 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
343 flag_const_strings = (lang == clk_cplusplus);
344 warn_pointer_arith = (lang == clk_cplusplus);
347 /* Handle one command-line option in (argc, argv).
348 Can be called multiple times, to handle multiple sets of options.
349 Returns number of strings consumed. */
351 c_common_decode_option (argc, argv)
355 static const int lang_flags[] = {CL_C, CL_OBJC, CL_CXX, CL_OBJCXX};
357 const char *opt, *arg = 0;
360 int result = 0, temp, lang_flag;
361 const struct cl_option *option;
365 /* Interpret "-" or a non-switch as a file name. */
366 if (opt[0] != '-' || opt[1] == '\0')
374 error ("too many filenames given. Type %s --help for usage",
382 /* Drop the "no-" from negative switches. */
383 if ((opt[1] == 'W' || opt[1] == 'f')
384 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
386 size_t len = strlen (opt) - 3;
388 dup = xmalloc (len + 1);
391 memcpy (dup + 2, opt + 5, len - 2 + 1);
397 lang_flag = lang_flags[(c_language << 1) + flag_objc];
398 opt_index = find_opt (opt + 1, lang_flag);
399 if (opt_index == N_OPTS)
402 option = &cl_options[opt_index];
404 /* Reject negative form of switches that don't take negatives. */
405 if (!on && (option->flags & CL_REJECT_NEGATIVE))
408 /* We've recognised this switch. */
411 /* Sort out any argument the switch takes. */
412 if (option->flags & (CL_JOINED | CL_SEPARATE))
414 if (option->flags & CL_JOINED)
416 /* Have arg point to the original switch. This is because
417 some code, such as disable_builtin_function, expects its
418 argument to be persistent until the program exits. */
419 arg = argv[0] + cl_options[opt_index].opt_len + 1;
421 arg += strlen ("no-");
424 /* If we don't have an argument, and CL_SEPARATE, try the next
425 argument in the vector. */
426 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
432 if (!arg || *arg == '\0')
434 missing_arg (opt_index);
440 /* Complain about the wrong language after we've swallowed any
441 necessary extra argument. Eventually make this a hard error
442 after the call to find_opt, and return argc. */
443 if (!(cl_options[opt_index].flags & lang_flag))
445 complain_wrong_lang (opt_index);
449 temp = c_common_handle_option (opt_index, arg, on);
459 /* Handle switch OPT_INDEX with argument ARG. ON is true, unless no-
460 form of an -f or -W option was given. Returns 0 if the switch was
461 invalid, a negative number to prevent language-independent
462 processing in toplev.c (a hack necessary for the short-term). */
464 c_common_handle_option (enum opt_code code, const char *arg, int on)
466 const struct cl_option *option = &cl_options[code];
471 case N_OPTS: /* Shut GCC up. */
478 case OPT__output_pch_:
483 defer_opt (code, arg);
487 cpp_opts->discard_comments = 0;
491 cpp_opts->discard_comments = 0;
492 cpp_opts->discard_comments_in_macro_exp = 0;
496 defer_opt (code, arg);
500 flag_preprocess_only = 1;
504 cpp_opts->print_include_names = 1;
508 if (strcmp (arg, "-"))
509 add_path (xstrdup (arg), BRACKET, 0);
512 if (quote_chain_split)
513 error ("-I- specified twice");
514 quote_chain_split = true;
515 split_quote_chain ();
521 /* When doing dependencies with -M or -MM, suppress normal
522 preprocessed output, but still do -dM etc. as software
523 depends on this. Preprocessed output does occur if -MD, -MMD
524 or environment var dependency generation is used. */
525 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
527 cpp_opts->inhibit_warnings = 1;
532 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
543 cpp_opts->deps.missing_files = true;
548 cpp_opts->deps.phony_targets = true;
554 defer_opt (code, arg);
558 flag_no_line_commands = 1;
562 defer_opt (code, arg);
573 warn_char_subscripts = on;
574 warn_missing_braces = on;
575 warn_parentheses = on;
576 warn_return_type = on;
577 warn_sequence_point = on; /* Was C only. */
578 if (c_language == clk_cplusplus)
579 warn_sign_compare = on;
581 warn_strict_aliasing = on;
583 /* Only warn about unknown pragmas that are not in system
585 warn_unknown_pragmas = on;
587 /* We save the value of warn_uninitialized, since if they put
588 -Wuninitialized on the command line, we need to generate a
589 warning about not using it without also specifying -O. */
590 if (warn_uninitialized != 1)
591 warn_uninitialized = (on ? 2 : 0);
593 if (c_language == clk_c)
594 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
595 can turn it off only if it's not explicit. */
599 /* C++-specific warnings. */
602 warn_nontemplate_friend = on;
605 cpp_opts->warn_trigraphs = on;
606 cpp_opts->warn_comments = on;
607 cpp_opts->warn_num_sign_change = on;
608 cpp_opts->warn_multichar = on; /* Was C++ only. */
611 case OPT_Wbad_function_cast:
612 warn_bad_function_cast = on;
619 case OPT_Wchar_subscripts:
620 warn_char_subscripts = on;
625 cpp_opts->warn_comments = on;
628 case OPT_Wconversion:
629 warn_conversion = on;
632 case OPT_Wctor_dtor_privacy:
633 warn_ctor_dtor_privacy = on;
636 case OPT_Wdeprecated:
637 warn_deprecated = on;
638 cpp_opts->warn_deprecated = on;
641 case OPT_Wdiv_by_zero:
642 warn_div_by_zero = on;
649 case OPT_Wendif_labels:
650 cpp_opts->warn_endif_labels = on;
654 cpp_opts->warnings_are_errors = on;
657 case OPT_Werror_implicit_function_declaration:
658 mesg_implicit_function_declaration = 2;
661 case OPT_Wfloat_equal:
662 warn_float_equal = on;
670 set_Wformat (atoi (arg));
673 case OPT_Wformat_extra_args:
674 warn_format_extra_args = on;
677 case OPT_Wformat_nonliteral:
678 warn_format_nonliteral = on;
681 case OPT_Wformat_security:
682 warn_format_security = on;
685 case OPT_Wformat_y2k:
686 warn_format_y2k = on;
689 case OPT_Wformat_zero_length:
690 warn_format_zero_length = on;
697 case OPT_Wimplicit_function_declaration:
698 mesg_implicit_function_declaration = on;
701 case OPT_Wimplicit_int:
702 warn_implicit_int = on;
706 cpp_opts->warn_import = on;
709 case OPT_Winvalid_offsetof:
710 warn_invalid_offsetof = on;
713 case OPT_Winvalid_pch:
714 cpp_opts->warn_invalid_pch = on;
728 case OPT_Wmissing_braces:
729 warn_missing_braces = on;
732 case OPT_Wmissing_declarations:
733 warn_missing_declarations = on;
736 case OPT_Wmissing_format_attribute:
737 warn_missing_format_attribute = on;
740 case OPT_Wmissing_prototypes:
741 warn_missing_prototypes = on;
745 cpp_opts->warn_multichar = on;
748 case OPT_Wnested_externs:
749 warn_nested_externs = on;
752 case OPT_Wnon_template_friend:
753 warn_nontemplate_friend = on;
756 case OPT_Wnon_virtual_dtor:
764 case OPT_Wold_style_cast:
765 warn_old_style_cast = on;
768 case OPT_Woverloaded_virtual:
769 warn_overloaded_virtual = on;
772 case OPT_Wparentheses:
773 warn_parentheses = on;
776 case OPT_Wpmf_conversions:
780 case OPT_Wpointer_arith:
781 warn_pointer_arith = on;
792 case OPT_Wredundant_decls:
793 warn_redundant_decls = on;
800 case OPT_Wreturn_type:
801 warn_return_type = on;
804 case OPT_Wsequence_point:
805 warn_sequence_point = on;
808 case OPT_Wsign_compare:
809 warn_sign_compare = on;
812 case OPT_Wsign_promo:
813 warn_sign_promo = on;
816 case OPT_Wstrict_prototypes:
817 warn_strict_prototypes = on;
824 case OPT_Wsystem_headers:
825 cpp_opts->warn_system_headers = on;
828 case OPT_Wtraditional:
829 warn_traditional = on;
830 cpp_opts->warn_traditional = on;
834 cpp_opts->warn_trigraphs = on;
837 case OPT_Wundeclared_selector:
838 warn_undeclared_selector = on;
842 cpp_opts->warn_undef = on;
845 case OPT_Wunknown_pragmas:
846 /* Set to greater than 1, so that even unknown pragmas in
847 system headers will be warned about. */
848 warn_unknown_pragmas = on * 2;
851 case OPT_Wunused_macros:
852 warn_unused_macros = on;
855 case OPT_Wwrite_strings:
856 if (c_language == clk_c)
857 flag_const_strings = on;
859 warn_write_strings = on;
863 if (c_language == clk_c)
864 set_std_c89 (false, true);
866 set_std_cxx98 (true);
873 case OPT_fcond_mismatch:
874 if (c_language == clk_c)
876 flag_cond_mismatch = on;
881 case OPT_fall_virtual:
882 case OPT_fenum_int_equiv:
883 case OPT_fguiding_decls:
885 case OPT_fhuge_objects:
887 case OPT_fname_mangling_version_:
889 case OPT_fnonnull_objects:
891 case OPT_fstrict_prototype:
892 case OPT_fthis_is_variable:
893 case OPT_fvtable_thunks:
895 warning ("switch \"%s\" is no longer supported", option->opt_text);
898 case OPT_fabi_version_:
899 flag_abi_version = read_integral_parameter (arg, option->opt_text, 1);
902 case OPT_faccess_control:
903 flag_access_control = on;
906 case OPT_falt_external_templates:
907 flag_alt_external_templates = on;
909 flag_external_templates = true;
911 warning ("switch \"%s\" is deprecated, please see documentation for details", option->opt_text);
919 flag_no_builtin = !on;
926 disable_builtin_function (arg);
929 case OPT_fdollars_in_identifiers:
930 cpp_opts->dollars_in_ident = on;
934 if (!dump_switch_p (option->opt_text + strlen ("f")))
938 case OPT_ffreestanding:
940 /* Fall through... */
943 flag_no_builtin = !on;
944 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
945 if (!on && warn_main == 2)
949 case OPT_fshort_double:
950 flag_short_double = on;
953 case OPT_fshort_enums:
954 flag_short_enums = on;
957 case OPT_fshort_wchar:
958 flag_short_wchar = on;
961 case OPT_fsigned_bitfields:
962 flag_signed_bitfields = on;
963 explicit_flag_signed_bitfields = 1;
966 case OPT_fsigned_char:
967 flag_signed_char = on;
970 case OPT_funsigned_bitfields:
971 flag_signed_bitfields = !on;
972 explicit_flag_signed_bitfields = 1;
975 case OPT_funsigned_char:
976 flag_signed_char = !on;
983 case OPT_fconserve_space:
984 flag_conserve_space = on;
987 case OPT_fconst_strings:
988 flag_const_strings = on;
991 case OPT_fconstant_string_class_:
992 constant_string_class_name = arg;
995 case OPT_fdefault_inline:
996 flag_default_inline = on;
999 case OPT_felide_constructors:
1000 flag_elide_constructors = on;
1003 case OPT_fenforce_eh_specs:
1004 flag_enforce_eh_specs = on;
1007 case OPT_fexternal_templates:
1008 flag_external_templates = on;
1011 case OPT_ffixed_form:
1012 case OPT_ffixed_line_length_:
1013 /* Fortran front end options ignored when preprocessing only. */
1014 if (flag_preprocess_only)
1018 case OPT_ffor_scope:
1019 flag_new_for_scope = on;
1022 case OPT_fgnu_keywords:
1023 flag_no_gnu_keywords = !on;
1026 case OPT_fgnu_runtime:
1027 flag_next_runtime = !on;
1030 case OPT_fhandle_exceptions:
1031 warning ("-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
1032 flag_exceptions = on;
1035 case OPT_fimplement_inlines:
1036 flag_implement_inlines = on;
1039 case OPT_fimplicit_inline_templates:
1040 flag_implicit_inline_templates = on;
1043 case OPT_fimplicit_templates:
1044 flag_implicit_templates = on;
1047 case OPT_fms_extensions:
1048 flag_ms_extensions = on;
1051 case OPT_fnext_runtime:
1052 flag_next_runtime = on;
1055 case OPT_fnonansi_builtins:
1056 flag_no_nonansi_builtin = !on;
1059 case OPT_foperator_names:
1060 cpp_opts->operator_names = on;
1063 case OPT_foptional_diags:
1064 flag_optional_diags = on;
1068 cpp_opts->restore_pch_deps = on;
1071 case OPT_fpermissive:
1072 flag_permissive = on;
1075 case OPT_fpreprocessed:
1076 cpp_opts->preprocessed = on;
1080 flag_use_repository = on;
1082 flag_implicit_templates = 0;
1089 case OPT_fshow_column:
1090 cpp_opts->show_column = on;
1094 flag_detailed_statistics = on;
1098 /* It is documented that we silently ignore silly values. */
1101 long tabstop = strtol (arg, &endptr, 10);
1102 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1103 cpp_opts->tabstop = tabstop;
1107 case OPT_ftemplate_depth_:
1108 max_tinst_depth = read_integral_parameter (arg, option->opt_text, 0);
1111 case OPT_fvtable_gc:
1112 flag_vtable_gc = on;
1115 case OPT_fuse_cxa_atexit:
1116 flag_use_cxa_atexit = on;
1124 flag_gen_declaration = 1;
1128 add_path (xstrdup (arg), AFTER, 0);
1133 defer_opt (code, arg);
1145 add_path (xstrdup (arg), SYSTEM, 0);
1148 case OPT_iwithprefix:
1149 add_prefixed_path (arg, SYSTEM);
1152 case OPT_iwithprefixbefore:
1153 add_prefixed_path (arg, BRACKET);
1157 cpp_set_lang (parse_in, CLK_ASM);
1158 cpp_opts->dollars_in_ident = false;
1169 case OPT_nostdinc__:
1170 std_cxx_inc = false;
1177 error ("output filename specified twice");
1180 /* We need to handle the -pedantic switches here, rather than in
1181 c_common_post_options, so that a subsequent -Wno-endif-labels
1182 is not overridden. */
1183 case OPT_pedantic_errors:
1184 cpp_opts->pedantic_errors = 1;
1187 cpp_opts->pedantic = 1;
1188 cpp_opts->warn_endif_labels = 1;
1191 case OPT_print_objc_runtime_info:
1192 print_struct_values = 1;
1196 cpp_opts->remap = 1;
1200 case OPT_std_gnu__98:
1201 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
1205 case OPT_std_iso9899_1990:
1206 case OPT_std_iso9899_199409:
1207 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1211 set_std_c89 (false /* c94 */, false /* ISO */);
1216 case OPT_std_iso9899_1999:
1217 case OPT_std_iso9899_199x:
1218 set_std_c99 (true /* ISO */);
1223 set_std_c99 (false /* ISO */);
1227 cpp_opts->trigraphs = 1;
1230 case OPT_traditional_cpp:
1231 cpp_opts->traditional = 1;
1239 cpp_opts->inhibit_warnings = 1;
1250 /* Post-switch processing. */
1252 c_common_post_options (pfilename)
1253 const char **pfilename;
1255 /* Canonicalize the input and output filenames. */
1256 if (in_fname == NULL || !strcmp (in_fname, "-"))
1259 if (out_fname == NULL || !strcmp (out_fname, "-"))
1262 if (cpp_opts->deps.style == DEPS_NONE)
1263 check_deps_environment_vars ();
1265 handle_deferred_opts ();
1267 sanitize_cpp_opts ();
1269 register_include_chains (parse_in, sysroot, iprefix,
1270 std_inc, std_cxx_inc && c_language == clk_cplusplus,
1273 flag_inline_trees = 1;
1275 /* Use tree inlining if possible. Function instrumentation is only
1276 done in the RTL level, so we disable tree inlining. */
1277 if (! flag_instrument_function_entry_exit)
1279 if (!flag_no_inline)
1281 if (flag_inline_functions)
1283 flag_inline_trees = 2;
1284 flag_inline_functions = 0;
1288 /* -Wextra implies -Wsign-compare, but not if explicitly
1290 if (warn_sign_compare == -1)
1291 warn_sign_compare = extra_warnings;
1293 /* Special format checking options don't work without -Wformat; warn if
1295 if (warn_format_y2k && !warn_format)
1296 warning ("-Wformat-y2k ignored without -Wformat");
1297 if (warn_format_extra_args && !warn_format)
1298 warning ("-Wformat-extra-args ignored without -Wformat");
1299 if (warn_format_zero_length && !warn_format)
1300 warning ("-Wformat-zero-length ignored without -Wformat");
1301 if (warn_format_nonliteral && !warn_format)
1302 warning ("-Wformat-nonliteral ignored without -Wformat");
1303 if (warn_format_security && !warn_format)
1304 warning ("-Wformat-security ignored without -Wformat");
1305 if (warn_missing_format_attribute && !warn_format)
1306 warning ("-Wmissing-format-attribute ignored without -Wformat");
1308 if (flag_preprocess_only)
1310 /* Open the output now. We must do so even if flag_no_output is
1311 on, because there may be other output than from the actual
1312 preprocessing (e.g. from -dM). */
1313 if (out_fname[0] == '\0')
1314 out_stream = stdout;
1316 out_stream = fopen (out_fname, "w");
1318 if (out_stream == NULL)
1320 fatal_error ("opening output file %s: %m", out_fname);
1324 init_pp_output (out_stream);
1330 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1334 cpp_get_callbacks (parse_in)->file_change = cb_file_change;
1336 /* NOTE: we use in_fname here, not the one supplied. */
1337 *pfilename = cpp_read_main_file (parse_in, in_fname);
1339 saved_lineno = input_line;
1342 /* If an error has occurred in cpplib, note it so we fail
1344 errorcount += cpp_errors (parse_in);
1346 return flag_preprocess_only;
1349 /* Front end initialization common to C, ObjC and C++. */
1353 input_line = saved_lineno;
1355 /* Set up preprocessor arithmetic. Must be done after call to
1356 c_common_nodes_and_builtins for type nodes to be good. */
1357 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1358 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1359 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1360 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1361 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1362 cpp_opts->EBCDIC = TARGET_EBCDIC;
1364 if (flag_preprocess_only)
1367 preprocess_file (parse_in);
1371 /* Has to wait until now so that cpplib has its hash table. */
1377 /* A thin wrapper around the real parser that initializes the
1378 integrated preprocessor after debug output has been initialized.
1379 Also, make sure the start_source_file debug hook gets called for
1380 the primary source file. */
1382 c_common_parse_file (set_yydebug)
1383 int set_yydebug ATTRIBUTE_UNUSED;
1386 yydebug = set_yydebug;
1388 warning ("YYDEBUG not defined");
1391 (*debug_hooks->start_source_file) (input_line, input_filename);
1395 free_parser_stacks ();
1398 /* Common finish hook for the C, ObjC and C++ front ends. */
1402 FILE *deps_stream = NULL;
1404 if (cpp_opts->deps.style != DEPS_NONE)
1406 /* If -M or -MM was seen without -MF, default output to the
1409 deps_stream = out_stream;
1412 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1414 fatal_error ("opening dependency file %s: %m", deps_file);
1418 /* For performance, avoid tearing down cpplib's internal structures
1419 with cpp_destroy (). */
1420 errorcount += cpp_finish (parse_in, deps_stream);
1422 if (deps_stream && deps_stream != out_stream
1423 && (ferror (deps_stream) || fclose (deps_stream)))
1424 fatal_error ("closing dependency file %s: %m", deps_file);
1426 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1427 fatal_error ("when writing output to %s: %m", out_fname);
1430 /* Either of two environment variables can specify output of
1431 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1432 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1433 and DEPS_TARGET is the target to mention in the deps. They also
1434 result in dependency information being appended to the output file
1435 rather than overwriting it, and like Sun's compiler
1436 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1438 check_deps_environment_vars ()
1442 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1444 cpp_opts->deps.style = DEPS_USER;
1447 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1450 cpp_opts->deps.style = DEPS_SYSTEM;
1451 cpp_opts->deps.ignore_main_file = true;
1457 /* Find the space before the DEPS_TARGET, if there is one. */
1458 char *s = strchr (spec, ' ');
1461 /* Let the caller perform MAKE quoting. */
1462 defer_opt (OPT_MT, s + 1);
1466 /* Command line -MF overrides environment variables and default. */
1474 /* Handle deferred command line switches. */
1476 handle_deferred_opts ()
1480 for (i = 0; i < deferred_count; i++)
1482 struct deferred_opt *opt = &deferred_opts[i];
1484 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1485 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1489 /* These settings are appropriate for GCC, but not necessarily so for
1490 cpplib as a library. */
1492 sanitize_cpp_opts ()
1494 /* If we don't know what style of dependencies to output, complain
1495 if any other dependency switches have been given. */
1496 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1497 error ("to generate dependencies you must specify either -M or -MM");
1499 /* -dM and dependencies suppress normal output; do it here so that
1500 the last -d[MDN] switch overrides earlier ones. */
1501 if (flag_dump_macros == 'M')
1504 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1505 -dM since at least glibc relies on -M -dM to work. */
1508 if (flag_dump_macros != 'M')
1509 flag_dump_macros = 0;
1510 flag_dump_includes = 0;
1513 cpp_opts->unsigned_char = !flag_signed_char;
1514 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1516 /* We want -Wno-long-long to override -pedantic -std=non-c99
1517 and/or -Wtraditional, whatever the ordering. */
1518 cpp_opts->warn_long_long
1519 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1522 /* Add include path with a prefix at the front of its name. */
1524 add_prefixed_path (suffix, chain)
1530 size_t prefix_len, suffix_len;
1532 suffix_len = strlen (suffix);
1533 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1534 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1536 path = xmalloc (prefix_len + suffix_len + 1);
1537 memcpy (path, prefix, prefix_len);
1538 memcpy (path + prefix_len, suffix, suffix_len);
1539 path[prefix_len + suffix_len] = '\0';
1541 add_path (path, chain, 0);
1544 /* Handle -D, -U, -A, -imacros, and the first -include. */
1548 if (!cpp_opts->preprocessed)
1552 cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
1553 cpp_init_builtins (parse_in, flag_hosted);
1554 c_cpp_builtins (parse_in);
1555 cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
1556 for (i = 0; i < deferred_count; i++)
1558 struct deferred_opt *opt = &deferred_opts[i];
1560 if (opt->code == OPT_D)
1561 cpp_define (parse_in, opt->arg);
1562 else if (opt->code == OPT_U)
1563 cpp_undef (parse_in, opt->arg);
1564 else if (opt->code == OPT_A)
1566 if (opt->arg[0] == '-')
1567 cpp_unassert (parse_in, opt->arg + 1);
1569 cpp_assert (parse_in, opt->arg);
1573 /* Handle -imacros after -D and -U. */
1574 for (i = 0; i < deferred_count; i++)
1576 struct deferred_opt *opt = &deferred_opts[i];
1578 if (opt->code == OPT_imacros
1579 && cpp_push_include (parse_in, opt->arg))
1580 cpp_scan_nooutput (parse_in);
1584 push_command_line_include ();
1587 /* Give CPP the next file given by -include, if any. */
1589 push_command_line_include ()
1591 if (cpp_opts->preprocessed)
1594 while (include_cursor < deferred_count)
1596 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1598 if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg))
1602 if (include_cursor == deferred_count)
1604 /* Restore the line map from <command line>. */
1605 cpp_change_file (parse_in, LC_RENAME, main_input_filename);
1606 /* -Wunused-macros should only warn about macros defined hereafter. */
1607 cpp_opts->warn_unused_macros = warn_unused_macros;
1612 /* File change callback. Has to handle -include files. */
1614 cb_file_change (pfile, new_map)
1615 cpp_reader *pfile ATTRIBUTE_UNUSED;
1616 const struct line_map *new_map;
1618 if (flag_preprocess_only)
1619 pp_file_change (new_map);
1621 fe_file_change (new_map);
1623 if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))
1624 push_command_line_include ();
1627 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1628 extensions if ISO). There is no concept of gnu94. */
1630 set_std_c89 (c94, iso)
1633 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1636 flag_no_gnu_keywords = iso;
1637 flag_no_nonansi_builtin = iso;
1638 flag_noniso_default_format_attributes = !iso;
1641 flag_writable_strings = 0;
1644 /* Set the C 99 standard (without GNU extensions if ISO). */
1649 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1651 flag_no_nonansi_builtin = iso;
1652 flag_noniso_default_format_attributes = !iso;
1656 flag_writable_strings = 0;
1659 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1664 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1665 flag_no_gnu_keywords = iso;
1666 flag_no_nonansi_builtin = iso;
1667 flag_noniso_default_format_attributes = !iso;
1671 /* Handle setting implicit to ON. */
1677 warn_implicit_int = on;
1680 if (mesg_implicit_function_declaration != 2)
1681 mesg_implicit_function_declaration = 1;
1684 mesg_implicit_function_declaration = 0;
1687 /* Args to -d specify what to dump. Silently ignore
1688 unrecognized options; they may be aimed at toplev.c. */
1695 while ((c = *arg++) != '\0')
1698 case 'M': /* Dump macros only. */
1699 case 'N': /* Dump names. */
1700 case 'D': /* Dump definitions. */
1701 flag_dump_macros = c;
1705 flag_dump_includes = 1;
1710 /* Write a slash-separated list of languages in FLAGS to BUF. */
1712 write_langs (buf, flags)
1719 if (flags & CL_OBJC)
1723 strcat (buf, "ObjC");
1729 strcat (buf, "C++");
1733 /* Complain that switch OPT_INDEX does not apply to this front end. */
1735 complain_wrong_lang (opt_index)
1738 char ok_langs[60], bad_langs[60];
1739 int ok_flags = cl_options[opt_index].flags;
1741 write_langs (ok_langs, ok_flags);
1742 write_langs (bad_langs, ~ok_flags);
1743 warning ("\"-%s\" is valid for %s but not for %s",
1744 cl_options[opt_index].opt_text, ok_langs, bad_langs);
1747 /* Handle --help output. */
1751 /* To keep the lines from getting too long for some compilers, limit
1752 to about 500 characters (6 lines) per chunk. */
1755 -include <file> Include the contents of <file> before other files\n\
1756 -imacros <file> Accept definition of macros in <file>\n\
1757 -iprefix <path> Specify <path> as a prefix for next two options\n\
1758 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1759 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1760 -isystem <dir> Add <dir> to the start of the system include path\n\
1763 -idirafter <dir> Add <dir> to the end of the system include path\n\
1764 -I <dir> Add <dir> to the end of the main include path\n\
1765 -I- Fine-grained include path control; see info docs\n\
1766 -nostdinc Do not search system include directories\n\
1767 (dirs specified with -isystem will still be used)\n\
1768 -nostdinc++ Do not search system include directories for C++\n\
1769 -o <file> Put output into <file>\n\
1772 -trigraphs Support ISO C trigraphs\n\
1773 -std=<std name> Specify the conformance standard; one of:\n\
1774 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1775 iso9899:199409, iso9899:1999, c++98\n\
1776 -w Inhibit warning messages\n\
1777 -W[no-]trigraphs Warn if trigraphs are encountered\n\
1778 -W[no-]comment{s} Warn if one comment starts inside another\n\
1781 -W[no-]traditional Warn about features not present in traditional C\n\
1782 -W[no-]undef Warn if an undefined macro is used by #if\n\
1783 -W[no-]import Warn about the use of the #import directive\n\
1786 -W[no-]error Treat all warnings as errors\n\
1787 -W[no-]system-headers Do not suppress warnings from system headers\n\
1788 -W[no-]all Enable most preprocessor warnings\n\
1791 -M Generate make dependencies\n\
1792 -MM As -M, but ignore system header files\n\
1793 -MD Generate make dependencies and compile\n\
1794 -MMD As -MD, but ignore system header files\n\
1795 -MF <file> Write dependency output to the given file\n\
1796 -MG Treat missing header file as generated files\n\
1799 -MP Generate phony targets for all headers\n\
1800 -MQ <target> Add a MAKE-quoted target\n\
1801 -MT <target> Add an unquoted target\n\
1804 -D<macro> Define a <macro> with string '1' as its value\n\
1805 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1806 -A<question>=<answer> Assert the <answer> to <question>\n\
1807 -A-<question>=<answer> Disable the <answer> to <question>\n\
1808 -U<macro> Undefine <macro> \n\
1809 -v Display the version number\n\
1812 -H Print the name of header files as they are used\n\
1813 -C Do not discard comments\n\
1814 -dM Display a list of macro definitions active at end\n\
1815 -dD Preserve macro definitions in output\n\
1816 -dN As -dD except that only the names are preserved\n\
1817 -dI Include #include directives in the output\n\
1820 -f[no-]preprocessed Treat the input file as already preprocessed\n\
1821 -ftabstop=<number> Distance between tab stops for column reporting\n\
1822 -isysroot <dir> Set <dir> to be the system root directory\n\
1823 -P Do not generate #line directives\n\
1824 -remap Remap file names when including files\n\
1825 --help Display this information\n\