1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002 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
29 #include "langhooks.h"
30 #include "tree-inline.h"
31 #include "diagnostic.h"
34 static cpp_options *cpp_opts;
36 static void missing_arg PARAMS ((size_t));
37 static size_t find_opt PARAMS ((const char *, int));
38 static void set_Wimplicit PARAMS ((int));
39 static void complain_wrong_lang PARAMS ((size_t));
40 static void write_langs PARAMS ((char *, int));
41 static void print_help PARAMS ((void));
42 static void handle_OPT_d PARAMS ((const char *));
43 static void set_std_cxx98 PARAMS ((int));
44 static void set_std_c89 PARAMS ((int, int));
45 static void set_std_c99 PARAMS ((int));
47 #define CL_C_ONLY (1 << 0) /* Only C. */
48 #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
49 #define CL_CXX_ONLY (1 << 2) /* Only C++. */
50 #define CL_OBJCXX_ONLY (1 << 3) /* Only ObjC++. */
51 #define CL_JOINED (1 << 4) /* If takes joined argument. */
52 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
54 #define CL_ARG (CL_JOINED | CL_SEPARATE)
55 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
56 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
57 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
58 #define CL_ALL (CL_C | CL_CXX)
60 /* This is the list of all command line options, with the leading "-"
61 removed. It must be sorted in ASCII collating order. All options
62 beginning with "f" or "W" are implicitly assumed to take a "no-"
63 form; this form should not be listed. The variable "on" is true if
64 the positive form is given, otherwise it is false. If you don't
65 want to allow a "no-" form, your handler should reject "on" being
66 false by returning zero. See, for example, the handling of
69 If the user gives an option to a front end that doesn't support it,
70 an error is output, mentioning which front ends the option is valid
71 for. If you don't want this, you must accept it for all front
72 ends, and test for the front end in the option handler. See, for
73 example, the handling of -Wno-strict-prototypes for C++.
75 If you request an argument with CL_JOINED, CL_SEPARATE or their
76 combination CL_ARG, it is stored in the variable "arg", which is
77 guaranteed to be non-NULL and to not be an empty string. It points
78 to the argument either within the argv[] vector or within one of
79 that vector's strings, and so the text is permanent and copies need
80 not be made. Be sure to add an error message in missing_arg() if
81 the default is not appropriate. */
83 #define COMMAND_LINE_OPTIONS \
84 OPT("-help", CL_ALL, OPT__help) \
85 OPT("C", CL_ALL, OPT_C) \
86 OPT("CC", CL_ALL, OPT_CC) \
87 OPT("E", CL_ALL, OPT_E) \
88 OPT("H", CL_ALL, OPT_H) \
89 OPT("P", CL_ALL, OPT_P) \
90 OPT("Wall", CL_ALL, OPT_Wall) \
91 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
92 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
93 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
94 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
95 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
96 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
97 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
98 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
99 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
100 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
101 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
102 OPT("Werror", CL_ALL, OPT_Werror) \
103 OPT("Werror-implicit-function-declaration", \
104 CL_C, OPT_Werror_implicit_function_decl) \
105 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
106 OPT("Wformat", CL_ALL, OPT_Wformat) \
107 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
108 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
109 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
110 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
111 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
112 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
113 OPT("Wimplicit", CL_CXX, OPT_Wimplicit) \
114 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
115 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
116 OPT("Wimport", CL_ALL, OPT_Wimport) \
117 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
118 OPT("Wmain", CL_C, OPT_Wmain) \
119 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
120 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
121 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
122 OPT("Wmissing-prototypes", CL_ALL, OPT_Wmissing_prototypes) \
123 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
124 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
125 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
126 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
127 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
128 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
129 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
130 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
131 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
132 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
133 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
134 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
135 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
136 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
137 OPT("Wselector", CL_OBJC, OPT_Wselector) \
138 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
139 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
140 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
141 OPT("Wstrict-prototypes", CL_ALL, OPT_Wstrict_prototypes) \
142 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
143 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
144 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
145 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
146 OPT("Wundef", CL_ALL, OPT_Wundef) \
147 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
148 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
149 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
150 OPT("ansi", CL_ALL, OPT_ansi) \
151 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
152 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
153 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
154 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
155 OPT("fasm", CL_ALL, OPT_fasm) \
156 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
157 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
158 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
159 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
160 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
161 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
162 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
163 OPT_fconstant_string_class) \
164 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
165 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
166 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
167 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
168 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
169 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
170 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
171 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
172 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
173 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
174 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
175 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
176 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
177 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
178 OPT("fhosted", CL_C, OPT_fhosted) \
179 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
180 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
181 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
182 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
183 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
184 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
185 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
186 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
187 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
188 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
189 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
190 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
191 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
192 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
193 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
194 OPT("frepo", CL_CXX, OPT_frepo) \
195 OPT("frtti", CL_CXX, OPT_frtti) \
196 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
197 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
198 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
199 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
200 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
201 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
202 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
203 OPT("fstats", CL_CXX, OPT_fstats) \
204 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
205 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
206 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
207 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
208 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
209 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
210 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
211 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
212 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
213 OPT("fweak", CL_CXX, OPT_fweak) \
214 OPT("fxref", CL_CXX, OPT_fxref) \
215 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
216 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
217 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
218 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
219 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
220 OPT("o", CL_ALL | CL_ARG, OPT_o) \
221 OPT("pedantic", CL_ALL, OPT_pedantic) \
222 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
223 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
224 OPT("remap", CL_ALL, OPT_remap) \
225 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
226 OPT("std=c89", CL_C, OPT_std_c89) \
227 OPT("std=c99", CL_C, OPT_std_c99) \
228 OPT("std=c9x", CL_C, OPT_std_c9x) \
229 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
230 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
231 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
232 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
233 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
234 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
235 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
236 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
237 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
238 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
239 OPT("undef", CL_ALL, OPT_undef) \
240 OPT("v", CL_ALL, OPT_v) \
241 OPT("w", CL_ALL, OPT_w)
243 #define OPT(text, flags, code) code,
253 const char *opt_text;
254 unsigned char opt_len;
256 ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
259 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
261 static struct cl_option cl_options[] =
263 static const struct cl_option cl_options[] =
269 #undef COMMAND_LINE_OPTIONS
272 static int opt_comp PARAMS ((const void *, const void *));
274 /* Run-time sorting of options array. */
279 return strcmp (((struct cl_option *) p1)->opt_text,
280 ((struct cl_option *) p2)->opt_text);
284 /* Complain that switch OPT_INDEX expects an argument but none was
287 missing_arg (opt_index)
296 case OPT_fname_mangling:
298 case OPT_ftemplate_depth:
300 error ("missing argument to \"-%s\"", cl_options[opt_index].opt_text);
303 case OPT_fconstant_string_class:
304 error ("no class name specified with -fconstant-string-class=");
308 error ("missing filename after \"-%s\"", cl_options[opt_index].opt_text);
313 /* Perform a binary search to find which option the command-line INPUT
314 matches. Returns its index in the option array, and N_OPTS on
317 Complications arise since some options can be suffixed with an
318 argument, and multiple complete matches can occur, e.g. -pedantic
319 and -pedantic-errors. Also, some options are only accepted by some
322 find_opt (input, lang_flag)
328 size_t wrong_lang = N_OPTS;
338 opt_len = cl_options[md].opt_len;
339 comp = memcmp (input, cl_options[md].opt_text, opt_len);
347 /* The switch matches. It it an exact match? */
348 if (input[opt_len] == '\0')
351 if (cl_options[md].flags & lang_flag)
360 /* If the switch takes no arguments this is not a proper
361 match, so we continue the search (e.g. input="stdc++"
362 match was "stdc"). */
363 if (!(cl_options[md].flags & CL_JOINED))
366 /* Is this switch valid for this front end? */
367 if (!(cl_options[md].flags & lang_flag))
369 /* If subsequently we don't find a good match,
370 report this as a bad match. */
375 /* Two scenarios remain: we have the switch's argument,
376 or we match a longer option. This can happen with
377 -iwithprefix and -withprefixbefore. The longest
378 possible option match succeeds.
380 Scan forwards, and return an exact match. Otherwise
381 return the longest valid option-accepting match (mx).
382 This loops at most twice with current options. */
384 for (md = md + 1; md < (size_t) N_OPTS; md++)
386 opt_len = cl_options[md].opt_len;
387 if (memcmp (input, cl_options[md].opt_text, opt_len))
389 if (input[opt_len] == '\0')
391 if (cl_options[md].flags & lang_flag
392 && cl_options[md].flags & CL_JOINED)
401 if (wrong_lang != N_OPTS)
402 complain_wrong_lang (wrong_lang);
407 /* Common initialization before parsing options. */
409 c_common_init_options (lang)
410 enum c_language_kind lang;
413 /* For non-ASCII hosts, the cl_options array needs to be sorted at
415 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
419 parse_in = cpp_create_reader (lang == clk_c
420 ? CLK_GNUC89 : CLK_GNUCXX);
421 cpp_opts = cpp_get_options (parse_in);
426 flag_const_strings = (lang == clk_cplusplus);
427 warn_pointer_arith = (lang == clk_cplusplus);
429 warn_sign_compare = -1;
431 /* Mark as "unspecified" (see c_common_post_options). */
432 flag_bounds_check = -1;
435 /* Handle one command-line option in (argc, argv).
436 Can be called multiple times, to handle multiple sets of options.
437 Returns number of strings consumed. */
439 c_common_decode_option (argc, argv)
443 static int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
445 const char *opt, *arg = 0;
449 const struct cl_option *option;
454 /* Interpret "-" or a non-switch as a file name. */
455 if (opt[0] != '-' || opt[1] == '\0')
457 if (!cpp_opts->in_fname)
458 cpp_opts->in_fname = opt;
459 else if (!cpp_opts->out_fname)
460 cpp_opts->out_fname = opt;
463 error ("too many filenames given. Type %s --help for usage",
471 /* Drop the "no-" from negative switches. */
472 if ((opt[1] == 'W' || opt[1] == 'f')
473 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
475 size_t len = strlen (opt) - 3;
477 dup = xmalloc (len + 1);
480 memcpy (dup + 2, opt + 5, len - 2 + 1);
485 result = cpp_handle_option (parse_in, argc, argv);
488 opt_index = find_opt (opt + 1, lang_flags[(c_language << 1) + flag_objc]);
489 if (opt_index == N_OPTS)
493 option = &cl_options[opt_index];
495 /* Sort out any argument the switch takes. */
496 if (option->flags & CL_ARG)
498 if (option->flags & CL_JOINED)
500 /* Have arg point to the original switch. This is because
501 some code, such as disable_builtin_function, expects its
502 argument to be persistent until the program exits. */
503 arg = argv[0] + cl_options[opt_index].opt_len + 1;
505 arg += strlen ("no-");
508 /* If we don't have an argument, and CL_SEPARATE, try the next
509 argument in the vector. */
510 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
516 if (!arg || *arg == '\0')
518 missing_arg (opt_index);
524 switch (code = option->opt_code)
526 case N_OPTS: /* Shut GCC up. */
534 cpp_opts->discard_comments = 0;
538 cpp_opts->discard_comments = 0;
539 cpp_opts->discard_comments_in_macro_exp = 0;
543 flag_preprocess_only = 1;
547 cpp_opts->print_include_names = 1;
551 cpp_opts->no_line_commands = 1;
558 warn_char_subscripts = on;
559 warn_missing_braces = on;
560 warn_multichar = on; /* Was C++ only. */
561 warn_parentheses = on;
562 warn_return_type = on;
563 warn_sequence_point = on; /* Was C only. */
564 warn_sign_compare = on; /* Was C++ only. */
567 /* Only warn about unknown pragmas that are not in system
569 warn_unknown_pragmas = on;
571 /* We save the value of warn_uninitialized, since if they put
572 -Wuninitialized on the command line, we need to generate a
573 warning about not using it without also specifying -O. */
574 if (warn_uninitialized != 1)
575 warn_uninitialized = (on ? 2 : 0);
577 if (c_language == clk_c)
578 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
579 can turn it off only if it's not explicit. */
583 /* C++-specific warnings. */
584 warn_ctor_dtor_privacy = on;
587 warn_nontemplate_friend = on;
590 cpp_opts->warn_trigraphs = on;
591 cpp_opts->warn_comments = on;
592 cpp_opts->warn_num_sign_change = on;
595 case OPT_Wbad_function_cast:
596 warn_bad_function_cast = on;
603 case OPT_Wchar_subscripts:
604 warn_char_subscripts = on;
609 cpp_opts->warn_comments = on;
612 case OPT_Wconversion:
613 warn_conversion = on;
616 case OPT_Wctor_dtor_privacy:
617 warn_ctor_dtor_privacy = on;
620 case OPT_Wdeprecated:
621 warn_deprecated = on;
624 case OPT_Wdiv_by_zero:
625 warn_div_by_zero = on;
632 case OPT_Wendif_labels:
633 cpp_opts->warn_endif_labels = on;
637 cpp_opts->warnings_are_errors = on;
640 case OPT_Werror_implicit_function_decl:
644 mesg_implicit_function_declaration = 2;
647 case OPT_Wfloat_equal:
648 warn_float_equal = on;
656 set_Wformat (atoi (arg));
659 case OPT_Wformat_extra_args:
660 warn_format_extra_args = on;
663 case OPT_Wformat_nonliteral:
664 warn_format_nonliteral = on;
667 case OPT_Wformat_security:
668 warn_format_security = on;
671 case OPT_Wformat_y2k:
672 warn_format_y2k = on;
675 case OPT_Wformat_zero_length:
676 warn_format_zero_length = on;
683 case OPT_Wimplicit_function_decl:
684 mesg_implicit_function_declaration = on;
687 case OPT_Wimplicit_int:
688 warn_implicit_int = on;
692 cpp_opts->warn_import = on;
706 case OPT_Wmissing_braces:
707 warn_missing_braces = on;
710 case OPT_Wmissing_declarations:
711 warn_missing_declarations = on;
714 case OPT_Wmissing_format_attribute:
715 warn_missing_format_attribute = on;
718 case OPT_Wmissing_prototypes:
719 warn_missing_prototypes = on;
726 case OPT_Wnested_externs:
727 warn_nested_externs = on;
730 case OPT_Wnon_template_friend:
731 warn_nontemplate_friend = on;
734 case OPT_Wnon_virtual_dtor:
742 case OPT_Wold_style_cast:
743 warn_old_style_cast = on;
746 case OPT_Woverloaded_virtual:
747 warn_overloaded_virtual = on;
750 case OPT_Wparentheses:
751 warn_parentheses = on;
754 case OPT_Wpmf_conversions:
758 case OPT_Wpointer_arith:
759 warn_pointer_arith = on;
770 case OPT_Wredundant_decls:
771 warn_redundant_decls = on;
778 case OPT_Wreturn_type:
779 warn_return_type = on;
782 case OPT_Wsequence_point:
783 warn_sequence_point = on;
786 case OPT_Wsign_compare:
787 warn_sign_compare = on;
790 case OPT_Wsign_promo:
791 warn_sign_promo = on;
794 case OPT_Wstrict_prototypes:
795 if (!on && c_language == clk_cplusplus)
796 warning ("-Wno-strict-prototypes is not supported in C++");
798 warn_strict_prototypes = on;
805 case OPT_Wsystem_headers:
806 cpp_opts->warn_system_headers = on;
809 case OPT_Wtraditional:
810 warn_traditional = on;
811 cpp_opts->warn_traditional = on;
815 cpp_opts->warn_trigraphs = on;
819 cpp_opts->warn_undef = on;
822 case OPT_Wunknown_pragmas:
823 /* Set to greater than 1, so that even unknown pragmas in
824 system headers will be warned about. */
825 warn_unknown_pragmas = on * 2;
828 case OPT_Wunused_macros:
829 cpp_opts->warn_unused_macros = on;
832 case OPT_Wwrite_strings:
833 if (c_language == clk_c)
834 flag_const_strings = on;
836 warn_write_strings = on;
840 if (c_language == clk_c)
841 set_std_c89 (false, true);
843 set_std_cxx98 (true);
850 case OPT_fcond_mismatch:
851 if (c_language == clk_c)
853 flag_cond_mismatch = on;
858 case OPT_fall_virtual:
859 case OPT_fenum_int_equiv:
860 case OPT_fguiding_decls:
862 case OPT_fhuge_objects:
864 case OPT_fname_mangling:
866 case OPT_fnonnull_objects:
868 case OPT_fstrict_prototype:
869 case OPT_fthis_is_variable:
870 case OPT_fvtable_thunks:
872 warning ("switch \"%s\" is no longer supported", argv[0]);
875 case OPT_faccess_control:
876 flag_access_control = on;
879 case OPT_falt_external_templates:
880 flag_alt_external_templates = on;
882 flag_external_templates = true;
884 warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
892 flag_no_builtin = !on;
899 disable_builtin_function (arg);
902 case OPT_fdollars_in_identifiers:
903 dollars_in_ident = on;
907 if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
911 case OPT_ffreestanding:
913 /* Fall through... */
916 flag_no_builtin = !on;
917 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
918 if (!on && warn_main == 2)
922 case OPT_fshort_double:
923 flag_short_double = on;
926 case OPT_fshort_enums:
927 flag_short_enums = on;
930 case OPT_fshort_wchar:
931 flag_short_wchar = on;
934 case OPT_fsigned_bitfields:
935 flag_signed_bitfields = on;
936 explicit_flag_signed_bitfields = 1;
939 case OPT_fsigned_char:
940 flag_signed_char = on;
943 case OPT_funsigned_bitfields:
944 flag_signed_bitfields = !on;
945 explicit_flag_signed_bitfields = 1;
948 case OPT_funsigned_char:
949 flag_signed_char = !on;
956 case OPT_fconserve_space:
957 flag_conserve_space = on;
960 case OPT_fconst_strings:
961 flag_const_strings = on;
964 case OPT_fconstant_string_class:
965 constant_string_class_name = arg;
968 case OPT_fdefault_inline:
969 flag_default_inline = on;
972 case OPT_felide_constructors:
973 flag_elide_constructors = on;
976 case OPT_fenforce_eh_specs:
977 flag_enforce_eh_specs = on;
980 case OPT_fexternal_templates:
981 flag_external_templates = on;
985 flag_new_for_scope = on;
988 case OPT_fgnu_keywords:
989 flag_no_gnu_keywords = !on;
992 case OPT_fgnu_runtime:
993 flag_next_runtime = !on;
996 case OPT_fhandle_exceptions:
997 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
998 flag_exceptions = on;
1001 case OPT_fimplement_inlines:
1002 flag_implement_inlines = on;
1005 case OPT_fimplicit_inline_templates:
1006 flag_implicit_inline_templates = on;
1009 case OPT_fimplicit_templates:
1010 flag_implicit_templates = on;
1013 case OPT_fms_extensions:
1014 flag_ms_extensions = on;
1017 case OPT_fnext_runtime:
1018 flag_next_runtime = on;
1021 case OPT_fnonansi_builtins:
1022 flag_no_nonansi_builtin = !on;
1025 case OPT_foperator_names:
1026 cpp_opts->operator_names = on;
1029 case OPT_foptional_diags:
1030 flag_optional_diags = on;
1033 case OPT_fpermissive:
1034 flag_permissive = on;
1037 case OPT_fpreprocessed:
1038 cpp_opts->preprocessed = on;
1042 flag_use_repository = on;
1044 flag_implicit_templates = 0;
1051 case OPT_fshow_column:
1052 cpp_opts->show_column = on;
1056 flag_detailed_statistics = on;
1060 /* Don't recognise -fno-tabstop=. */
1064 /* It is documented that we silently ignore silly values. */
1067 long tabstop = strtol (arg, &endptr, 10);
1068 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1069 cpp_opts->tabstop = tabstop;
1073 case OPT_ftemplate_depth:
1074 max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
1077 case OPT_fvtable_gc:
1078 flag_vtable_gc = on;
1081 case OPT_fuse_cxa_atexit:
1082 flag_use_cxa_atexit = on;
1090 flag_gen_declaration = 1;
1094 cpp_set_lang (parse_in, CLK_ASM);
1102 /* No default include directories. You must specify all
1103 include-file directories with -I. */
1104 cpp_opts->no_standard_includes = 1;
1107 case OPT_nostdincplusplus:
1108 /* No default C++-specific include directories. */
1109 cpp_opts->no_standard_cplusplus_includes = 1;
1113 if (!cpp_opts->out_fname)
1114 cpp_opts->out_fname = arg;
1117 error ("output filename specified twice");
1122 /* We need to handle the -pedantic switches here, rather than in
1123 c_common_post_options, so that a subsequent -Wno-endif-labels
1124 is not overridden. */
1125 case OPT_pedantic_errors:
1126 cpp_opts->pedantic_errors = 1;
1129 cpp_opts->pedantic = 1;
1130 cpp_opts->warn_endif_labels = 1;
1133 case OPT_print_objc_runtime_info:
1134 print_struct_values = 1;
1138 cpp_opts->remap = 1;
1141 case OPT_std_cplusplus98:
1142 case OPT_std_gnuplusplus98:
1143 set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
1147 case OPT_std_iso9899_1990:
1148 case OPT_std_iso9899_199409:
1149 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1153 set_std_c89 (false /* c94 */, false /* ISO */);
1158 case OPT_std_iso9899_1999:
1159 case OPT_std_iso9899_199x:
1160 set_std_c99 (true /* ISO */);
1165 set_std_c99 (false /* ISO */);
1169 cpp_opts->trigraphs = 1;
1172 case OPT_traditional_cpp:
1173 cpp_opts->traditional = 1;
1181 cpp_opts->inhibit_warnings = 1;
1185 cpp_opts->verbose = 1;
1195 /* Post-switch processing. */
1197 c_common_post_options ()
1199 cpp_post_options (parse_in);
1201 flag_inline_trees = 1;
1203 /* Use tree inlining if possible. Function instrumentation is only
1204 done in the RTL level, so we disable tree inlining. */
1205 if (! flag_instrument_function_entry_exit)
1207 if (!flag_no_inline)
1209 if (flag_inline_functions)
1211 flag_inline_trees = 2;
1212 flag_inline_functions = 0;
1216 /* If still "unspecified", make it match -fbounded-pointers. */
1217 if (flag_bounds_check == -1)
1218 flag_bounds_check = flag_bounded_pointers;
1220 /* Special format checking options don't work without -Wformat; warn if
1222 if (warn_format_y2k && !warn_format)
1223 warning ("-Wformat-y2k ignored without -Wformat");
1224 if (warn_format_extra_args && !warn_format)
1225 warning ("-Wformat-extra-args ignored without -Wformat");
1226 if (warn_format_zero_length && !warn_format)
1227 warning ("-Wformat-zero-length ignored without -Wformat");
1228 if (warn_format_nonliteral && !warn_format)
1229 warning ("-Wformat-nonliteral ignored without -Wformat");
1230 if (warn_format_security && !warn_format)
1231 warning ("-Wformat-security ignored without -Wformat");
1232 if (warn_missing_format_attribute && !warn_format)
1233 warning ("-Wmissing-format-attribute ignored without -Wformat");
1235 /* If an error has occurred in cpplib, note it so we fail
1237 errorcount += cpp_errors (parse_in);
1239 return flag_preprocess_only;
1242 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1243 extensions if ISO). There is no concept of gnu94. */
1245 set_std_c89 (c94, iso)
1248 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1251 flag_no_gnu_keywords = iso;
1252 flag_no_nonansi_builtin = iso;
1253 flag_noniso_default_format_attributes = !iso;
1256 flag_writable_strings = 0;
1259 /* Set the C 99 standard (without GNU extensions if ISO). */
1264 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1266 flag_no_nonansi_builtin = iso;
1267 flag_noniso_default_format_attributes = !iso;
1271 flag_writable_strings = 0;
1274 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1279 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1280 flag_no_gnu_keywords = iso;
1281 flag_no_nonansi_builtin = iso;
1282 flag_noniso_default_format_attributes = !iso;
1286 /* Handle setting implicit to ON. */
1292 warn_implicit_int = on;
1295 if (mesg_implicit_function_declaration != 2)
1296 mesg_implicit_function_declaration = 1;
1299 mesg_implicit_function_declaration = 0;
1302 /* Args to -d specify what to dump. Silently ignore
1303 unrecognised options; they may be aimed at toplev.c. */
1310 while ((c = *arg++) != '\0')
1314 cpp_opts->dump_macros = dump_only;
1318 cpp_opts->dump_macros = dump_names;
1322 cpp_opts->dump_macros = dump_definitions;
1326 cpp_opts->dump_includes = 1;
1331 /* Write a slash-separated list of languages in FLAGS to BUF. */
1333 write_langs (buf, flags)
1338 if (flags & CL_C_ONLY)
1340 if (flags & CL_OBJC_ONLY)
1344 strcat (buf, "ObjC");
1346 if (flags & CL_CXX_ONLY)
1350 strcat (buf, "C++");
1354 /* Complain that switch OPT_INDEX does not apply to this front end. */
1356 complain_wrong_lang (opt_index)
1359 char ok_langs[60], bad_langs[60];
1360 int ok_flags = cl_options[opt_index].flags;
1362 write_langs (ok_langs, ok_flags);
1363 write_langs (bad_langs, ~ok_flags);
1364 warning ("\"-%s\" is valid for %s but not for %s",
1365 cl_options[opt_index].opt_text, ok_langs, bad_langs);
1368 /* Handle --help output. */
1372 /* To keep the lines from getting too long for some compilers, limit
1373 to about 500 characters (6 lines) per chunk. */
1376 -include <file> Include the contents of <file> before other files\n\
1377 -imacros <file> Accept definition of macros in <file>\n\
1378 -iprefix <path> Specify <path> as a prefix for next two options\n\
1379 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1380 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1381 -isystem <dir> Add <dir> to the start of the system include path\n\
1384 -idirafter <dir> Add <dir> to the end of the system include path\n\
1385 -I <dir> Add <dir> to the end of the main include path\n\
1386 -I- Fine-grained include path control; see info docs\n\
1387 -nostdinc Do not search system include directories\n\
1388 (dirs specified with -isystem will still be used)\n\
1389 -nostdinc++ Do not search system include directories for C++\n\
1390 -o <file> Put output into <file>\n\
1393 -trigraphs Support ISO C trigraphs\n\
1394 -std=<std name> Specify the conformance standard; one of:\n\
1395 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1396 iso9899:199409, iso9899:1999, c++98\n\
1397 -w Inhibit warning messages\n\
1398 -W[no-]trigraphs Warn if trigraphs are encountered\n\
1399 -W[no-]comment{s} Warn if one comment starts inside another\n\
1402 -W[no-]traditional Warn about features not present in traditional C\n\
1403 -W[no-]undef Warn if an undefined macro is used by #if\n\
1404 -W[no-]import Warn about the use of the #import directive\n\
1407 -W[no-]error Treat all warnings as errors\n\
1408 -W[no-]system-headers Do not suppress warnings from system headers\n\
1409 -W[no-]all Enable most preprocessor warnings\n\
1412 -M Generate make dependencies\n\
1413 -MM As -M, but ignore system header files\n\
1414 -MD Generate make dependencies and compile\n\
1415 -MMD As -MD, but ignore system header files\n\
1416 -MF <file> Write dependency output to the given file\n\
1417 -MG Treat missing header file as generated files\n\
1420 -MP Generate phony targets for all headers\n\
1421 -MQ <target> Add a MAKE-quoted target\n\
1422 -MT <target> Add an unquoted target\n\
1425 -D<macro> Define a <macro> with string '1' as its value\n\
1426 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1427 -A<question>=<answer> Assert the <answer> to <question>\n\
1428 -A-<question>=<answer> Disable the <answer> to <question>\n\
1429 -U<macro> Undefine <macro> \n\
1430 -v Display the version number\n\
1433 -H Print the name of header files as they are used\n\
1434 -C Do not discard comments\n\
1435 -dM Display a list of macro definitions active at end\n\
1436 -dD Preserve macro definitions in output\n\
1437 -dN As -dD except that only the names are preserved\n\
1438 -dI Include #include directives in the output\n\
1441 -f[no-]preprocessed Treat the input file as already preprocessed\n\
1442 -ftabstop=<number> Distance between tab stops for column reporting\n\
1443 -P Do not generate #line directives\n\
1444 -remap Remap file names when including files\n\
1445 --help Display this information\n\