OSDN Git Service

* tree-inline.c (find_builtin_longjmp_call): Save and restore
[pf3gnuchains/gcc-fork.git] / gcc / c-opts.c
1 /* C/ObjC/C++ command line option handling.
2    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    Contributed by Neil Booth.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "c-common.h"
28 #include "c-pragma.h"
29 #include "flags.h"
30 #include "toplev.h"
31 #include "langhooks.h"
32 #include "tree-inline.h"
33 #include "diagnostic.h"
34 #include "intl.h"
35 #include "cppdefault.h"
36 #include "c-incpath.h"
37
38 #ifndef TARGET_SYSTEM_ROOT
39 # define TARGET_SYSTEM_ROOT NULL
40 #endif
41
42 /* CPP's options.  */
43 static cpp_options *cpp_opts;
44
45 /* Input filename.  */
46 static const char *in_fname;
47
48 /* Filename and stream for preprocessed output.  */
49 static const char *out_fname;
50 static FILE *out_stream;
51
52 /* Append dependencies to deps_file.  */
53 static bool deps_append;
54
55 /* If dependency switches (-MF etc.) have been given.  */
56 static bool deps_seen;
57
58 /* If -v seen.  */
59 static bool verbose;
60
61 /* Dependency output file.  */
62 static const char *deps_file;
63
64 /* The prefix given by -iprefix, if any.  */
65 static const char *iprefix;
66
67 /* The system root, if any.  Overridden by -isysroot.  */
68 static const char *sysroot = TARGET_SYSTEM_ROOT;
69
70 /* Zero disables all standard directories for headers.  */
71 static bool std_inc = true;
72
73 /* Zero disables the C++-specific standard directories for headers.  */
74 static bool std_cxx_inc = true;
75
76 /* If the quote chain has been split by -I-.  */
77 static bool quote_chain_split;
78
79 /* Number of deferred options, deferred options array size.  */
80 static size_t deferred_count, deferred_size;
81
82 static void missing_arg PARAMS ((size_t));
83 static size_t find_opt PARAMS ((const char *, int));
84 static void set_Wimplicit PARAMS ((int));
85 static void complain_wrong_lang PARAMS ((size_t));
86 static void write_langs PARAMS ((char *, int));
87 static void print_help PARAMS ((void));
88 static void handle_OPT_d PARAMS ((const char *));
89 static void set_std_cxx98 PARAMS ((int));
90 static void set_std_c89 PARAMS ((int, int));
91 static void set_std_c99 PARAMS ((int));
92 static void check_deps_environment_vars PARAMS ((void));
93 static void preprocess_file PARAMS ((void));
94 static void handle_deferred_opts PARAMS ((void));
95 static void sanitize_cpp_opts PARAMS ((void));
96 static void add_prefixed_path PARAMS ((const char *, size_t));
97
98 #ifndef STDC_0_IN_SYSTEM_HEADERS
99 #define STDC_0_IN_SYSTEM_HEADERS 0
100 #endif
101
102 #define CL_C_ONLY       (1 << 0) /* Only C.  */
103 #define CL_OBJC_ONLY    (1 << 1) /* Only ObjC.  */
104 #define CL_CXX_ONLY     (1 << 2) /* Only C++.  */
105 #define CL_OBJCXX_ONLY  (1 << 3) /* Only ObjC++.  */
106 #define CL_JOINED       (1 << 4) /* If takes joined argument.  */
107 #define CL_SEPARATE     (1 << 5) /* If takes a separate argument.  */
108
109 #define CL_ARG          (CL_JOINED | CL_SEPARATE)
110 #define CL_C            (CL_C_ONLY | CL_OBJC_ONLY)
111 #define CL_OBJC         (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
112 #define CL_CXX          (CL_CXX_ONLY | CL_OBJCXX_ONLY)
113 #define CL_ALL          (CL_C | CL_CXX)
114
115 /* This is the list of all command line options, with the leading "-"
116    removed.  It must be sorted in ASCII collating order.  All options
117    beginning with "f" or "W" are implicitly assumed to take a "no-"
118    form; this form should not be listed.  The variable "on" is true if
119    the positive form is given, otherwise it is false.  If you don't
120    want to allow a "no-" form, your handler should reject "on" being
121    false by returning zero.  See, for example, the handling of
122    -ftabstop=.
123
124    If the user gives an option to a front end that doesn't support it,
125    an error is output, mentioning which front ends the option is valid
126    for.  If you don't want this, you must accept it for all front
127    ends, and test for the front end in the option handler.  See, for
128    example, the handling of -Wno-strict-prototypes for C++.
129
130    If you request an argument with CL_JOINED, CL_SEPARATE or their
131    combination CL_ARG, it is stored in the variable "arg", which is
132    guaranteed to be non-NULL and to not be an empty string.  It points
133    to the argument either within the argv[] vector or within one of
134    that vector's strings, and so the text is permanent and copies need
135    not be made.  Be sure to add an error message in missing_arg() if
136    the default is not appropriate.  */
137
138 #define COMMAND_LINE_OPTIONS                                                 \
139   OPT("-help",                  CL_ALL,   OPT__help)                         \
140   OPT("-output-pch=",           CL_ALL | CL_ARG, OPT__output_pch)            \
141   OPT("C",                      CL_ALL,   OPT_C)                             \
142   OPT("CC",                     CL_ALL,   OPT_CC)                            \
143   OPT("E",                      CL_ALL,   OPT_E)                             \
144   OPT("H",                      CL_ALL,   OPT_H)                             \
145   OPT("I",                      CL_ALL | CL_ARG, OPT_I)                      \
146   OPT("M",                      CL_ALL,   OPT_M)                             \
147   OPT("MD",                     CL_ALL | CL_SEPARATE, OPT_MD)                \
148   OPT("MF",                     CL_ALL | CL_ARG, OPT_MF)                     \
149   OPT("MG",                     CL_ALL,   OPT_MG)                            \
150   OPT("MM",                     CL_ALL,   OPT_MM)                            \
151   OPT("MMD",                    CL_ALL | CL_SEPARATE, OPT_MMD)               \
152   OPT("MP",                     CL_ALL,   OPT_MP)                            \
153   OPT("MQ",                     CL_ALL | CL_ARG, OPT_MQ)                     \
154   OPT("MT",                     CL_ALL | CL_ARG, OPT_MT)                     \
155   OPT("P",                      CL_ALL,   OPT_P)                             \
156   OPT("Wabi",                   CL_CXX,   OPT_Wabi)                          \
157   OPT("Wall",                   CL_ALL,   OPT_Wall)                          \
158   OPT("Wbad-function-cast",     CL_C,     OPT_Wbad_function_cast)            \
159   OPT("Wcast-qual",             CL_ALL,   OPT_Wcast_qual)                    \
160   OPT("Wchar-subscripts",       CL_ALL,   OPT_Wchar_subscripts)              \
161   OPT("Wcomment",               CL_ALL,   OPT_Wcomment)                      \
162   OPT("Wcomments",              CL_ALL,   OPT_Wcomments)                     \
163   OPT("Wconversion",            CL_ALL,   OPT_Wconversion)                   \
164   OPT("Wctor-dtor-privacy",     CL_CXX,   OPT_Wctor_dtor_privacy)            \
165   OPT("Wdeprecated",            CL_CXX,   OPT_Wdeprecated)                   \
166   OPT("Wdiv-by-zero",           CL_C,     OPT_Wdiv_by_zero)                  \
167   OPT("Weffc++",                CL_CXX,   OPT_Weffcxx)                       \
168   OPT("Wendif-labels",          CL_ALL,   OPT_Wendif_labels)                 \
169   OPT("Werror",                 CL_ALL,   OPT_Werror)                        \
170   OPT("Werror-implicit-function-declaration",                                \
171                                 CL_C,     OPT_Werror_implicit_function_decl) \
172   OPT("Wfloat-equal",           CL_ALL,   OPT_Wfloat_equal)                  \
173   OPT("Wformat",                CL_ALL,   OPT_Wformat)                       \
174   OPT("Wformat-extra-args",     CL_ALL,   OPT_Wformat_extra_args)            \
175   OPT("Wformat-nonliteral",     CL_ALL,   OPT_Wformat_nonliteral)            \
176   OPT("Wformat-security",       CL_ALL,   OPT_Wformat_security)              \
177   OPT("Wformat-y2k",            CL_ALL,   OPT_Wformat_y2k)                   \
178   OPT("Wformat-zero-length",    CL_C,     OPT_Wformat_zero_length)           \
179   OPT("Wformat=",               CL_ALL | CL_JOINED, OPT_Wformat_eq)          \
180   OPT("Wimplicit",              CL_ALL,   OPT_Wimplicit)                     \
181   OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl)   \
182   OPT("Wimplicit-int",          CL_C,     OPT_Wimplicit_int)                 \
183   OPT("Wimport",                CL_ALL,   OPT_Wimport)                       \
184   OPT("Winvalid-pch",           CL_ALL,   OPT_Winvalid_pch)                  \
185   OPT("Wlong-long",             CL_ALL,   OPT_Wlong_long)                    \
186   OPT("Wmain",                  CL_C,     OPT_Wmain)                         \
187   OPT("Wmissing-braces",        CL_ALL,   OPT_Wmissing_braces)               \
188   OPT("Wmissing-declarations",  CL_C,     OPT_Wmissing_declarations)         \
189   OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute)     \
190   OPT("Wmissing-prototypes",    CL_ALL,   OPT_Wmissing_prototypes)           \
191   OPT("Wmultichar",             CL_ALL,   OPT_Wmultichar)                    \
192   OPT("Wnested-externs",        CL_C,     OPT_Wnested_externs)               \
193   OPT("Wnon-template-friend",   CL_CXX,   OPT_Wnon_template_friend)          \
194   OPT("Wnon-virtual-dtor",      CL_CXX,   OPT_Wnon_virtual_dtor)             \
195   OPT("Wnonnull",               CL_C,     OPT_Wnonnull)                      \
196   OPT("Wold-style-cast",        CL_CXX,   OPT_Wold_style_cast)               \
197   OPT("Woverloaded-virtual",    CL_CXX,   OPT_Woverloaded_virtual)           \
198   OPT("Wparentheses",           CL_ALL,   OPT_Wparentheses)                  \
199   OPT("Wpmf-conversions",       CL_CXX,   OPT_Wpmf_conversions)              \
200   OPT("Wpointer-arith",         CL_ALL,   OPT_Wpointer_arith)                \
201   OPT("Wprotocol",              CL_OBJC,  OPT_Wprotocol)                     \
202   OPT("Wredundant-decls",       CL_ALL,   OPT_Wredundant_decls)              \
203   OPT("Wreorder",               CL_CXX,   OPT_Wreorder)                      \
204   OPT("Wreturn-type",           CL_ALL,   OPT_Wreturn_type)                  \
205   OPT("Wselector",              CL_OBJC,  OPT_Wselector)                     \
206   OPT("Wsequence-point",        CL_C,     OPT_Wsequence_point)               \
207   OPT("Wsign-compare",          CL_ALL,   OPT_Wsign_compare)                 \
208   OPT("Wsign-promo",            CL_CXX,   OPT_Wsign_promo)                   \
209   OPT("Wstrict-prototypes",     CL_ALL,   OPT_Wstrict_prototypes)            \
210   OPT("Wsynth",                 CL_CXX,   OPT_Wsynth)                        \
211   OPT("Wsystem-headers",        CL_ALL,   OPT_Wsystem_headers)               \
212   OPT("Wtraditional",           CL_C,     OPT_Wtraditional)                  \
213   OPT("Wtrigraphs",             CL_ALL,   OPT_Wtrigraphs)                    \
214   OPT("Wundeclared-selector",   CL_OBJC,  OPT_Wundeclared_selector)          \
215   OPT("Wundef",                 CL_ALL,   OPT_Wundef)                        \
216   OPT("Wunknown-pragmas",       CL_ALL,   OPT_Wunknown_pragmas)              \
217   OPT("Wunused-macros",         CL_ALL,   OPT_Wunused_macros)                \
218   OPT("Wwrite-strings",         CL_ALL,   OPT_Wwrite_strings)                \
219   OPT("ansi",                   CL_ALL,   OPT_ansi)                          \
220   OPT("d",                      CL_ALL | CL_JOINED, OPT_d)                   \
221   OPT("fabi-version=",          CL_CXX | CL_JOINED, OPT_fabi_version)        \
222   OPT("faccess-control",        CL_CXX,   OPT_faccess_control)               \
223   OPT("fall-virtual",           CL_CXX,   OPT_fall_virtual)                  \
224   OPT("falt-external-templates",CL_CXX,   OPT_falt_external_templates)       \
225   OPT("fasm",                   CL_ALL,   OPT_fasm)                          \
226   OPT("fbuiltin",               CL_ALL,   OPT_fbuiltin)                      \
227   OPT("fbuiltin-",              CL_ALL | CL_JOINED, OPT_fbuiltin_)           \
228   OPT("fcheck-new",             CL_CXX,   OPT_fcheck_new)                    \
229   OPT("fcond-mismatch",         CL_ALL,   OPT_fcond_mismatch)                \
230   OPT("fconserve-space",        CL_CXX,   OPT_fconserve_space)               \
231   OPT("fconst-strings",         CL_CXX,   OPT_fconst_strings)                \
232   OPT("fconstant-string-class=", CL_OBJC | CL_JOINED,                        \
233                                           OPT_fconstant_string_class)        \
234   OPT("fdefault-inline",        CL_CXX,   OPT_fdefault_inline)               \
235   OPT("fdollars-in-identifiers",CL_ALL,   OPT_fdollars_in_identifiers)       \
236   OPT("fdump-",                 CL_ALL | CL_JOINED, OPT_fdump)               \
237   OPT("felide-constructors",    CL_CXX,   OPT_felide_constructors)           \
238   OPT("fenforce-eh-specs",      CL_CXX,   OPT_fenforce_eh_specs)             \
239   OPT("fenum-int-equiv",        CL_CXX,   OPT_fenum_int_equiv)               \
240   OPT("fexternal-templates",    CL_CXX,   OPT_fexternal_templates)           \
241   OPT("ffixed-form",            CL_C,     OPT_ffixed_form)                   \
242   OPT("ffixed-line-length-",    CL_C | CL_JOINED, OPT_ffixed_line_length)    \
243   OPT("ffor-scope",             CL_CXX,   OPT_ffor_scope)                    \
244   OPT("ffreestanding",          CL_C,     OPT_ffreestanding)                 \
245   OPT("fgnu-keywords",          CL_CXX,   OPT_fgnu_keywords)                 \
246   OPT("fgnu-runtime",           CL_OBJC,  OPT_fgnu_runtime)                  \
247   OPT("fguiding-decls",         CL_CXX,   OPT_fguiding_decls)                \
248   OPT("fhandle-exceptions",     CL_CXX,   OPT_fhandle_exceptions)            \
249   OPT("fhonor-std",             CL_CXX,   OPT_fhonor_std)                    \
250   OPT("fhosted",                CL_C,     OPT_fhosted)                       \
251   OPT("fhuge-objects",          CL_CXX,   OPT_fhuge_objects)                 \
252   OPT("fimplement-inlines",     CL_CXX,   OPT_fimplement_inlines)            \
253   OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates)  \
254   OPT("fimplicit-templates",    CL_CXX,   OPT_fimplicit_templates)           \
255   OPT("flabels-ok",             CL_CXX,   OPT_flabels_ok)                    \
256   OPT("fms-extensions",         CL_ALL,   OPT_fms_extensions)                \
257   OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling)      \
258   OPT("fnew-abi",               CL_CXX,   OPT_fnew_abi)                      \
259   OPT("fnext-runtime",          CL_OBJC,  OPT_fnext_runtime)                 \
260   OPT("fnonansi-builtins",      CL_CXX,   OPT_fnonansi_builtins)             \
261   OPT("fnonnull-objects",       CL_CXX,   OPT_fnonnull_objects)              \
262   OPT("foperator-names",        CL_CXX,   OPT_foperator_names)               \
263   OPT("foptional-diags",        CL_CXX,   OPT_foptional_diags)               \
264   OPT("fpch-deps",              CL_ALL,   OPT_fpch_deps)                     \
265   OPT("fpermissive",            CL_CXX,   OPT_fpermissive)                   \
266   OPT("fpreprocessed",          CL_ALL,   OPT_fpreprocessed)                 \
267   OPT("frepo",                  CL_CXX,   OPT_frepo)                         \
268   OPT("frtti",                  CL_CXX,   OPT_frtti)                         \
269   OPT("fshort-double",          CL_ALL,   OPT_fshort_double)                 \
270   OPT("fshort-enums",           CL_ALL,   OPT_fshort_enums)                  \
271   OPT("fshort-wchar",           CL_ALL,   OPT_fshort_wchar)                  \
272   OPT("fshow-column",           CL_ALL,   OPT_fshow_column)                  \
273   OPT("fsigned-bitfields",      CL_ALL,   OPT_fsigned_bitfields)             \
274   OPT("fsigned-char",           CL_ALL,   OPT_fsigned_char)                  \
275   OPT("fsquangle",              CL_CXX,   OPT_fsquangle)                     \
276   OPT("fstats",                 CL_CXX,   OPT_fstats)                        \
277   OPT("fstrict-prototype",      CL_CXX,   OPT_fstrict_prototype)             \
278   OPT("ftabstop=",              CL_ALL | CL_JOINED, OPT_ftabstop)            \
279   OPT("ftemplate-depth-",       CL_CXX | CL_JOINED, OPT_ftemplate_depth)     \
280   OPT("fthis-is-variable",      CL_CXX,   OPT_fthis_is_variable)             \
281   OPT("funsigned-bitfields",    CL_ALL,   OPT_funsigned_bitfields)           \
282   OPT("funsigned-char",         CL_ALL,   OPT_funsigned_char)                \
283   OPT("fuse-cxa-atexit",        CL_CXX,   OPT_fuse_cxa_atexit)               \
284   OPT("fvtable-gc",             CL_CXX,   OPT_fvtable_gc)                    \
285   OPT("fvtable-thunks",         CL_CXX,   OPT_fvtable_thunks)                \
286   OPT("fweak",                  CL_CXX,   OPT_fweak)                         \
287   OPT("fxref",                  CL_CXX,   OPT_fxref)                         \
288   OPT("gen-decls",              CL_OBJC,  OPT_gen_decls)                     \
289   OPT("idirafter",              CL_ALL | CL_ARG, OPT_idirafter)              \
290   OPT("iprefix",                CL_ALL | CL_ARG, OPT_iprefix)                \
291   OPT("isysroot",               CL_ALL | CL_ARG, OPT_isysroot)               \
292   OPT("isystem",                CL_ALL | CL_ARG, OPT_isystem)                \
293   OPT("iwithprefix",            CL_ALL | CL_ARG, OPT_iwithprefix)            \
294   OPT("iwithprefixbefore",      CL_ALL | CL_ARG, OPT_iwithprefixbefore)      \
295   OPT("lang-asm",               CL_C_ONLY, OPT_lang_asm)                     \
296   OPT("lang-objc",              CL_ALL,   OPT_lang_objc)                     \
297   OPT("nostdinc",               CL_ALL,   OPT_nostdinc)                      \
298   OPT("nostdinc++",             CL_ALL,   OPT_nostdincplusplus)              \
299   OPT("o",                      CL_ALL | CL_ARG, OPT_o)                      \
300   OPT("pedantic",               CL_ALL,   OPT_pedantic)                      \
301   OPT("pedantic-errors",        CL_ALL,   OPT_pedantic_errors)               \
302   OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info)       \
303   OPT("remap",                  CL_ALL,   OPT_remap)                         \
304   OPT("std=c++98",              CL_CXX,   OPT_std_cplusplus98)               \
305   OPT("std=c89",                CL_C,     OPT_std_c89)                       \
306   OPT("std=c99",                CL_C,     OPT_std_c99)                       \
307   OPT("std=c9x",                CL_C,     OPT_std_c9x)                       \
308   OPT("std=gnu++98",            CL_CXX,   OPT_std_gnuplusplus98)             \
309   OPT("std=gnu89",              CL_C,     OPT_std_gnu89)                     \
310   OPT("std=gnu99",              CL_C,     OPT_std_gnu99)                     \
311   OPT("std=gnu9x",              CL_C,     OPT_std_gnu9x)                     \
312   OPT("std=iso9899:1990",       CL_C,     OPT_std_iso9899_1990)              \
313   OPT("std=iso9899:199409",     CL_C,     OPT_std_iso9899_199409)            \
314   OPT("std=iso9899:1999",       CL_C,     OPT_std_iso9899_1999)              \
315   OPT("std=iso9899:199x",       CL_C,     OPT_std_iso9899_199x)              \
316   OPT("traditional-cpp",        CL_ALL,   OPT_traditional_cpp)               \
317   OPT("trigraphs",              CL_ALL,   OPT_trigraphs)                     \
318   OPT("undef",                  CL_ALL,   OPT_undef)                         \
319   OPT("v",                      CL_ALL,   OPT_v)                             \
320   OPT("w",                      CL_ALL,   OPT_w)
321
322 #define OPT(text, flags, code) code,
323 enum opt_code
324 {
325   COMMAND_LINE_OPTIONS
326   N_OPTS
327 };
328 #undef OPT
329
330 struct cl_option
331 {
332   const char *opt_text;
333   unsigned char opt_len;
334   unsigned char flags;
335   ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
336 };
337
338 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
339 #ifdef HOST_EBCDIC
340 static struct cl_option cl_options[] =
341 #else
342 static const struct cl_option cl_options[] =
343 #endif
344 {
345   COMMAND_LINE_OPTIONS
346 };
347 #undef OPT
348 #undef COMMAND_LINE_OPTIONS
349
350 /* Holds switches parsed by c_common_decode_option (), but whose
351    handling is deferred to c_common_post_options ().  */
352 static void defer_opt PARAMS ((enum opt_code, const char *));
353 static struct deferred_opt
354 {
355   enum opt_code code;
356   const char *arg;
357 } *deferred_opts;
358
359
360 #ifdef HOST_EBCDIC
361 static int opt_comp PARAMS ((const void *, const void *));
362
363 /* Run-time sorting of options array.  */
364 static int
365 opt_comp (p1, p2)
366      const void *p1, *p2;
367 {
368   return strcmp (((struct cl_option *) p1)->opt_text,
369                  ((struct cl_option *) p2)->opt_text);
370 }
371 #endif
372
373 /* Complain that switch OPT_INDEX expects an argument but none was
374    provided.  */
375 static void
376 missing_arg (opt_index)
377      size_t opt_index;
378 {
379   const char *opt_text = cl_options[opt_index].opt_text;
380
381   switch (cl_options[opt_index].opt_code)
382     {
383     case OPT__output_pch:
384     case OPT_Wformat_eq:
385     case OPT_d:
386     case OPT_fabi_version:
387     case OPT_fbuiltin_:
388     case OPT_fdump:
389     case OPT_fname_mangling:
390     case OPT_ftabstop:
391     case OPT_ftemplate_depth:
392     case OPT_iprefix:
393     case OPT_iwithprefix:
394     case OPT_iwithprefixbefore:
395     default:
396       error ("missing argument to \"-%s\"", opt_text);
397       break;
398
399     case OPT_fconstant_string_class:
400       error ("no class name specified with \"-%s\"", opt_text);
401       break;
402
403     case OPT_I:
404     case OPT_idirafter:
405     case OPT_isysroot:
406     case OPT_isystem:
407       error ("missing path after \"-%s\"", opt_text);
408       break;
409
410     case OPT_MF:
411     case OPT_MD:
412     case OPT_MMD:
413     case OPT_o:
414       error ("missing filename after \"-%s\"", opt_text);
415       break;
416
417     case OPT_MQ:
418     case OPT_MT:
419       error ("missing target after \"-%s\"", opt_text);
420       break;
421     }
422 }
423
424 /* Perform a binary search to find which option the command-line INPUT
425    matches.  Returns its index in the option array, and N_OPTS on
426    failure.
427
428    Complications arise since some options can be suffixed with an
429    argument, and multiple complete matches can occur, e.g. -pedantic
430    and -pedantic-errors.  Also, some options are only accepted by some
431    languages.  If a switch matches for a different language and
432    doesn't match any alternatives for the true front end, the index of
433    the matched switch is returned anyway.  The caller should check for
434    this case.  */
435 static size_t
436 find_opt (input, lang_flag)
437      const char *input;
438      int lang_flag;
439 {
440   size_t md, mn, mx;
441   size_t opt_len;
442   size_t result = N_OPTS;
443   int comp;
444
445   mn = 0;
446   mx = N_OPTS;
447
448   while (mx > mn)
449     {
450       md = (mn + mx) / 2;
451
452       opt_len = cl_options[md].opt_len;
453       comp = strncmp (input, cl_options[md].opt_text, opt_len);
454
455       if (comp < 0)
456         mx = md;
457       else if (comp > 0)
458         mn = md + 1;
459       else
460         {
461           /* The switch matches.  It it an exact match?  */
462           if (input[opt_len] == '\0')
463             return md;
464           else
465             {
466               mn = md + 1;
467
468               /* If the switch takes no arguments this is not a proper
469                  match, so we continue the search (e.g. input="stdc++"
470                  match was "stdc").  */
471               if (!(cl_options[md].flags & CL_JOINED))
472                 continue;
473
474               /* Is this switch valid for this front end?  */
475               if (!(cl_options[md].flags & lang_flag))
476                 {
477                   /* If subsequently we don't find a better match,
478                      return this and let the caller report it as a bad
479                      match.  */
480                   result = md;
481                   continue;
482                 }
483
484               /* Two scenarios remain: we have the switch's argument,
485                  or we match a longer option.  This can happen with
486                  -iwithprefix and -withprefixbefore.  The longest
487                  possible option match succeeds.
488
489                  Scan forwards, and return an exact match.  Otherwise
490                  return the longest valid option-accepting match (mx).
491                  This loops at most twice with current options.  */
492               mx = md;
493               for (md = md + 1; md < (size_t) N_OPTS; md++)
494                 {
495                   opt_len = cl_options[md].opt_len;
496                   if (strncmp (input, cl_options[md].opt_text, opt_len))
497                     break;
498                   if (input[opt_len] == '\0')
499                     return md;
500                   if (cl_options[md].flags & lang_flag
501                       && cl_options[md].flags & CL_JOINED)
502                     mx = md;
503                 }
504
505               return mx;
506             }
507         }
508     }
509
510   return result;
511 }
512
513 /* Defer option CODE with argument ARG.  */
514 static void
515 defer_opt (code, arg)
516      enum opt_code code;
517      const char *arg;
518 {
519   /* FIXME: this should be in c_common_init_options, which should take
520      argc and argv.  */
521   if (!deferred_opts)
522     {
523       extern int save_argc;
524       deferred_size = save_argc;
525       deferred_opts = (struct deferred_opt *)
526         xmalloc (deferred_size * sizeof (struct deferred_opt));
527     }
528
529   if (deferred_count == deferred_size)
530     abort ();
531
532   deferred_opts[deferred_count].code = code;
533   deferred_opts[deferred_count].arg = arg;
534   deferred_count++;
535 }
536
537 /* Common initialization before parsing options.  */
538 void
539 c_common_init_options (lang)
540      enum c_language_kind lang;
541 {
542 #ifdef HOST_EBCDIC
543   /* For non-ASCII hosts, the cl_options array needs to be sorted at
544      runtime.  */
545   qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
546 #endif
547 #if ENABLE_CHECKING
548  {
549   size_t i;
550
551   for (i = 1; i < N_OPTS; i++)
552     if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
553       error ("options array incorrectly sorted: %s is before %s",
554              cl_options[i - 1].opt_text, cl_options[i].opt_text);
555  }
556 #endif
557
558   c_language = lang;
559   parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
560   cpp_opts = cpp_get_options (parse_in);
561   if (flag_objc)
562     cpp_opts->objc = 1;
563
564   flag_const_strings = (lang == clk_cplusplus);
565   warn_pointer_arith = (lang == clk_cplusplus);
566   if (lang == clk_c)
567     warn_sign_compare = -1;
568 }
569
570 /* Handle one command-line option in (argc, argv).
571    Can be called multiple times, to handle multiple sets of options.
572    Returns number of strings consumed.  */
573 int
574 c_common_decode_option (argc, argv)
575      int argc;
576      char **argv;
577 {
578   static const int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
579   size_t opt_index;
580   const char *opt, *arg = 0;
581   char *dup = 0;
582   bool on = true;
583   int result, lang_flag;
584   const struct cl_option *option;
585   enum opt_code code;
586
587   opt = argv[0];
588
589   /* Interpret "-" or a non-switch as a file name.  */
590   if (opt[0] != '-' || opt[1] == '\0')
591     {
592       if (!in_fname)
593         in_fname = opt;
594       else if (!out_fname)
595         out_fname = opt;
596       else
597         {
598           error ("too many filenames given.  Type %s --help for usage",
599                  progname);
600           return argc;
601         }
602
603       return 1;
604     }
605
606   /* Drop the "no-" from negative switches.  */
607   if ((opt[1] == 'W' || opt[1] == 'f')
608       && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
609     {
610       size_t len = strlen (opt) - 3;
611
612       dup = xmalloc (len + 1);
613       dup[0] = '-';
614       dup[1] = opt[1];
615       memcpy (dup + 2, opt + 5, len - 2 + 1);
616       opt = dup;
617       on = false;
618     }
619
620   result = cpp_handle_option (parse_in, argc, argv);
621
622   /* Skip over '-'.  */
623   lang_flag = lang_flags[(c_language << 1) + flag_objc];
624   opt_index = find_opt (opt + 1, lang_flag);
625   if (opt_index == N_OPTS)
626     goto done;
627
628   result = 1;
629   option = &cl_options[opt_index];
630
631   /* Sort out any argument the switch takes.  */
632   if (option->flags & CL_ARG)
633     {
634       if (option->flags & CL_JOINED)
635         {
636           /* Have arg point to the original switch.  This is because
637              some code, such as disable_builtin_function, expects its
638              argument to be persistent until the program exits.  */
639           arg = argv[0] + cl_options[opt_index].opt_len + 1;
640           if (!on)
641             arg += strlen ("no-");
642         }
643
644       /* If we don't have an argument, and CL_SEPARATE, try the next
645          argument in the vector.  */
646       if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
647         {
648           arg = argv[1];
649           result = 2;
650         }
651
652       if (!arg || *arg == '\0')
653         {
654           missing_arg (opt_index);
655           result = argc;
656           goto done;
657         }
658     }
659
660   /* Complain about the wrong language after we've swallowed any
661      necessary extra argument.  Eventually make this a hard error
662      after the call to find_opt, and return argc.  */
663   if (!(cl_options[opt_index].flags & lang_flag))
664     {
665       complain_wrong_lang (opt_index);
666       goto done;
667     }
668
669   switch (code = option->opt_code)
670     {
671     case N_OPTS: /* Shut GCC up.  */
672       break;
673
674     case OPT__help:
675       print_help ();
676       break;
677
678     case OPT__output_pch:
679       pch_file = arg;
680       break;
681
682     case OPT_C:
683       cpp_opts->discard_comments = 0;
684       break;
685
686     case OPT_CC:
687       cpp_opts->discard_comments = 0;
688       cpp_opts->discard_comments_in_macro_exp = 0;
689       break;
690
691     case OPT_E:
692       flag_preprocess_only = 1;
693       break;
694
695     case OPT_H:
696       cpp_opts->print_include_names = 1;
697       break;
698
699     case OPT_I:
700       if (strcmp (arg, "-"))
701         add_path (xstrdup (arg), BRACKET, 0);
702       else
703         {
704           if (quote_chain_split)
705             error ("-I- specified twice");
706           quote_chain_split = true;
707           split_quote_chain ();
708         }
709       break;
710
711     case OPT_M:
712     case OPT_MM:
713       /* When doing dependencies with -M or -MM, suppress normal
714          preprocessed output, but still do -dM etc. as software
715          depends on this.  Preprocessed output does occur if -MD, -MMD
716          or environment var dependency generation is used.  */
717       cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
718       cpp_opts->no_output = 1;
719       cpp_opts->inhibit_warnings = 1;
720       break;
721
722     case OPT_MD:
723     case OPT_MMD:
724       cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
725       deps_file = arg;
726       break;
727
728     case OPT_MF:
729       deps_seen = true;
730       deps_file = arg;
731       break;
732
733     case OPT_MG:
734       deps_seen = true;
735       cpp_opts->deps.missing_files = true;
736       break;
737
738     case OPT_MP:
739       deps_seen = true;
740       cpp_opts->deps.phony_targets = true;
741       break;
742
743     case OPT_MQ:
744     case OPT_MT:
745       deps_seen = true;
746       defer_opt (code, arg);
747       break;
748
749     case OPT_P:
750       cpp_opts->no_line_commands = 1;
751       break;
752
753     case OPT_Wabi:
754       warn_abi = on;
755       break;
756
757     case OPT_Wall:
758       set_Wunused (on);
759       set_Wformat (on);
760       set_Wimplicit (on);
761       warn_char_subscripts = on;
762       warn_missing_braces = on;
763       warn_parentheses = on;
764       warn_return_type = on;
765       warn_sequence_point = on; /* Was C only.  */
766       warn_sign_compare = on;   /* Was C++ only.  */
767       warn_switch = on;
768       warn_strict_aliasing = on;
769       
770       /* Only warn about unknown pragmas that are not in system
771          headers.  */                                        
772       warn_unknown_pragmas = on;
773
774       /* We save the value of warn_uninitialized, since if they put
775          -Wuninitialized on the command line, we need to generate a
776          warning about not using it without also specifying -O.  */
777       if (warn_uninitialized != 1)
778         warn_uninitialized = (on ? 2 : 0);
779
780       if (c_language == clk_c)
781         /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
782            can turn it off only if it's not explicit.  */
783         warn_main = on * 2;
784       else
785         {
786           /* C++-specific warnings.  */
787           warn_ctor_dtor_privacy = on;
788           warn_nonvdtor = on;
789           warn_reorder = on;
790           warn_nontemplate_friend = on;
791         }
792
793       cpp_opts->warn_trigraphs = on;
794       cpp_opts->warn_comments = on;
795       cpp_opts->warn_num_sign_change = on;
796       cpp_opts->warn_multichar = on;    /* Was C++ only.  */
797       break;
798
799     case OPT_Wbad_function_cast:
800       warn_bad_function_cast = on;
801       break;
802
803     case OPT_Wcast_qual:
804       warn_cast_qual = on;
805       break;
806
807     case OPT_Wchar_subscripts:
808       warn_char_subscripts = on;
809       break;
810
811     case OPT_Wcomment:
812     case OPT_Wcomments:
813       cpp_opts->warn_comments = on;
814       break;
815
816     case OPT_Wconversion:
817       warn_conversion = on;
818       break;
819
820     case OPT_Wctor_dtor_privacy:
821       warn_ctor_dtor_privacy = on;
822       break;
823
824     case OPT_Wdeprecated:
825       warn_deprecated = on;
826       cpp_opts->warn_deprecated = on;
827       break;
828
829     case OPT_Wdiv_by_zero:
830       warn_div_by_zero = on;
831       break;
832
833     case OPT_Weffcxx:
834       warn_ecpp = on;
835       break;
836
837     case OPT_Wendif_labels:
838       cpp_opts->warn_endif_labels = on;
839       break;
840
841     case OPT_Werror:
842       cpp_opts->warnings_are_errors = on;
843       break;
844
845     case OPT_Werror_implicit_function_decl:
846       if (!on)
847         result = 0;
848       else
849         mesg_implicit_function_declaration = 2;
850       break;
851
852     case OPT_Wfloat_equal:
853       warn_float_equal = on;
854       break;
855
856     case OPT_Wformat:
857       set_Wformat (on);
858       break;
859
860     case OPT_Wformat_eq:
861       set_Wformat (atoi (arg));
862       break;
863
864     case OPT_Wformat_extra_args:
865       warn_format_extra_args = on;
866       break;
867
868     case OPT_Wformat_nonliteral:
869       warn_format_nonliteral = on;
870       break;
871
872     case OPT_Wformat_security:
873       warn_format_security = on;
874       break;
875
876     case OPT_Wformat_y2k:
877       warn_format_y2k = on;
878       break;
879
880     case OPT_Wformat_zero_length:
881       warn_format_zero_length = on;
882       break;
883
884     case OPT_Wimplicit:
885       set_Wimplicit (on);
886       break;
887
888     case OPT_Wimplicit_function_decl:
889       mesg_implicit_function_declaration = on;
890       break;
891
892     case OPT_Wimplicit_int:
893       warn_implicit_int = on;
894       break;
895
896     case OPT_Wimport:
897       cpp_opts->warn_import = on;
898       break;
899
900     case OPT_Winvalid_pch:
901       cpp_opts->warn_invalid_pch = on;
902       break;
903
904     case OPT_Wlong_long:
905       warn_long_long = on;
906       break;
907
908     case OPT_Wmain:
909       if (on)
910         warn_main = 1;
911       else
912         warn_main = -1;
913       break;
914
915     case OPT_Wmissing_braces:
916       warn_missing_braces = on;
917       break;
918
919     case OPT_Wmissing_declarations:
920       warn_missing_declarations = on;
921       break;
922
923     case OPT_Wmissing_format_attribute:
924       warn_missing_format_attribute = on;
925       break;
926
927     case OPT_Wmissing_prototypes:
928       warn_missing_prototypes = on;
929       break;
930
931     case OPT_Wmultichar:
932       cpp_opts->warn_multichar = on;
933       break;
934
935     case OPT_Wnested_externs:
936       warn_nested_externs = on;
937       break;
938
939     case OPT_Wnon_template_friend:
940       warn_nontemplate_friend = on;
941       break;
942
943     case OPT_Wnon_virtual_dtor:
944       warn_nonvdtor = on;
945       break;
946
947     case OPT_Wnonnull:
948       warn_nonnull = on;
949       break;
950
951     case OPT_Wold_style_cast:
952       warn_old_style_cast = on;
953       break;
954
955     case OPT_Woverloaded_virtual:
956       warn_overloaded_virtual = on;
957       break;
958
959     case OPT_Wparentheses:
960       warn_parentheses = on;
961       break;
962
963     case OPT_Wpmf_conversions:
964       warn_pmf2ptr = on;
965       break;
966
967     case OPT_Wpointer_arith:
968       warn_pointer_arith = on;
969       break;
970
971     case OPT_Wprotocol:
972       warn_protocol = on;
973       break;
974
975     case OPT_Wselector:
976       warn_selector = on;
977       break;
978
979     case OPT_Wredundant_decls:
980       warn_redundant_decls = on;
981       break;
982
983     case OPT_Wreorder:
984       warn_reorder = on;
985       break;
986
987     case OPT_Wreturn_type:
988       warn_return_type = on;
989       break;
990
991     case OPT_Wsequence_point:
992       warn_sequence_point = on;
993       break;
994
995     case OPT_Wsign_compare:
996       warn_sign_compare = on;
997       break;
998
999     case OPT_Wsign_promo:
1000       warn_sign_promo = on;
1001       break;
1002
1003     case OPT_Wstrict_prototypes:
1004       if (!on && c_language == clk_cplusplus)
1005         warning ("-Wno-strict-prototypes is not supported in C++");
1006       else
1007         warn_strict_prototypes = on;
1008       break;
1009
1010     case OPT_Wsynth:
1011       warn_synth = on;
1012       break;
1013
1014     case OPT_Wsystem_headers:
1015       cpp_opts->warn_system_headers = on;
1016       break;
1017
1018     case OPT_Wtraditional:
1019       warn_traditional = on;
1020       cpp_opts->warn_traditional = on;
1021       break;
1022
1023     case OPT_Wtrigraphs:
1024       cpp_opts->warn_trigraphs = on;
1025       break;
1026
1027     case OPT_Wundeclared_selector:
1028       warn_undeclared_selector = on;
1029       break;
1030
1031     case OPT_Wundef:
1032       cpp_opts->warn_undef = on;
1033       break;
1034
1035     case OPT_Wunknown_pragmas:
1036       /* Set to greater than 1, so that even unknown pragmas in
1037          system headers will be warned about.  */  
1038       warn_unknown_pragmas = on * 2;
1039       break;
1040
1041     case OPT_Wunused_macros:
1042       cpp_opts->warn_unused_macros = on;
1043       break;
1044
1045     case OPT_Wwrite_strings:
1046       if (c_language == clk_c)
1047         flag_const_strings = on;
1048       else
1049         warn_write_strings = on;
1050       break;
1051       
1052     case OPT_ansi:
1053       if (c_language == clk_c)
1054         set_std_c89 (false, true);
1055       else
1056         set_std_cxx98 (true);
1057       break;
1058
1059     case OPT_d:
1060       handle_OPT_d (arg);
1061       break;
1062
1063     case OPT_fcond_mismatch:
1064       if (c_language == clk_c)
1065         {
1066           flag_cond_mismatch = on;
1067           break;
1068         }
1069       /* Fall through.  */
1070
1071     case OPT_fall_virtual:
1072     case OPT_fenum_int_equiv:
1073     case OPT_fguiding_decls:
1074     case OPT_fhonor_std:
1075     case OPT_fhuge_objects:
1076     case OPT_flabels_ok:
1077     case OPT_fname_mangling:
1078     case OPT_fnew_abi:
1079     case OPT_fnonnull_objects:
1080     case OPT_fsquangle:
1081     case OPT_fstrict_prototype:
1082     case OPT_fthis_is_variable:
1083     case OPT_fvtable_thunks:
1084     case OPT_fxref:
1085       warning ("switch \"%s\" is no longer supported", argv[0]);
1086       break;
1087
1088     case OPT_fabi_version:
1089       flag_abi_version = read_integral_parameter (arg, argv[0], 1);
1090       break;
1091
1092     case OPT_faccess_control:
1093       flag_access_control = on;
1094       break;
1095
1096     case OPT_falt_external_templates:
1097       flag_alt_external_templates = on;
1098       if (on)
1099         flag_external_templates = true;
1100     cp_deprecated:
1101       warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
1102       break;
1103
1104     case OPT_fasm:
1105       flag_no_asm = !on;
1106       break;
1107
1108     case OPT_fbuiltin:
1109       flag_no_builtin = !on;
1110       break;
1111
1112     case OPT_fbuiltin_:
1113       if (on)
1114         result = 0;
1115       else
1116         disable_builtin_function (arg);
1117       break;
1118
1119     case OPT_fdollars_in_identifiers:
1120       dollars_in_ident = on;
1121       break;
1122
1123     case OPT_fdump:
1124       if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
1125         result = 0;
1126       break;
1127
1128     case OPT_ffreestanding:
1129       on = !on;
1130       /* Fall through...  */
1131     case OPT_fhosted:
1132       flag_hosted = on;
1133       flag_no_builtin = !on;
1134       /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1135       if (!on && warn_main == 2)
1136         warn_main = 0;
1137       break;
1138
1139     case OPT_fshort_double:
1140       flag_short_double = on;
1141       break;
1142
1143     case OPT_fshort_enums:
1144       flag_short_enums = on;
1145       break;
1146
1147     case OPT_fshort_wchar:
1148       flag_short_wchar = on;
1149       break;
1150
1151     case OPT_fsigned_bitfields:
1152       flag_signed_bitfields = on;
1153       explicit_flag_signed_bitfields = 1;
1154       break;
1155
1156     case OPT_fsigned_char:
1157       flag_signed_char = on;
1158       break;
1159
1160     case OPT_funsigned_bitfields:
1161       flag_signed_bitfields = !on;
1162       explicit_flag_signed_bitfields = 1;
1163       break;
1164
1165     case OPT_funsigned_char:
1166       flag_signed_char = !on;
1167       break;
1168
1169     case OPT_fcheck_new:
1170       flag_check_new = on;
1171       break;
1172
1173     case OPT_fconserve_space:
1174       flag_conserve_space = on;
1175       break;
1176
1177     case OPT_fconst_strings:
1178       flag_const_strings = on;
1179       break;
1180
1181     case OPT_fconstant_string_class:
1182       constant_string_class_name = arg;
1183       break;
1184
1185     case OPT_fdefault_inline:
1186       flag_default_inline = on;
1187       break;
1188
1189     case OPT_felide_constructors:
1190       flag_elide_constructors = on;
1191       break;
1192
1193     case OPT_fenforce_eh_specs:
1194       flag_enforce_eh_specs = on;
1195       break;
1196
1197     case OPT_fexternal_templates:
1198       flag_external_templates = on;
1199       goto cp_deprecated;
1200
1201     case OPT_ffixed_form:
1202     case OPT_ffixed_line_length:
1203       /* Fortran front end options ignored when preprocessing only.  */
1204       if (flag_preprocess_only)
1205         result = -1;
1206       break;
1207
1208     case OPT_ffor_scope:
1209       flag_new_for_scope = on;
1210       break;
1211
1212     case OPT_fgnu_keywords:
1213       flag_no_gnu_keywords = !on;
1214       break;
1215
1216     case OPT_fgnu_runtime:
1217       flag_next_runtime = !on;
1218       break;
1219
1220     case OPT_fhandle_exceptions:
1221       warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1222       flag_exceptions = on;
1223       break;
1224
1225     case OPT_fimplement_inlines:
1226       flag_implement_inlines = on;
1227       break;
1228
1229     case OPT_fimplicit_inline_templates:
1230       flag_implicit_inline_templates = on;
1231       break;
1232
1233     case OPT_fimplicit_templates:
1234       flag_implicit_templates = on;
1235       break;
1236
1237     case OPT_fms_extensions:
1238       flag_ms_extensions = on;
1239       break;
1240
1241     case OPT_fnext_runtime:
1242       flag_next_runtime = on;
1243       break;
1244
1245     case OPT_fnonansi_builtins:
1246       flag_no_nonansi_builtin = !on;
1247       break;
1248
1249     case OPT_foperator_names:
1250       cpp_opts->operator_names = on;
1251       break;
1252
1253     case OPT_foptional_diags:
1254       flag_optional_diags = on;
1255       break;
1256
1257     case OPT_fpch_deps:
1258       cpp_opts->restore_pch_deps = on;
1259       break;
1260
1261     case OPT_fpermissive:
1262       flag_permissive = on;
1263       break;
1264
1265     case OPT_fpreprocessed:
1266       cpp_opts->preprocessed = on;
1267       break;
1268
1269     case OPT_frepo:
1270       flag_use_repository = on;
1271       if (on)
1272         flag_implicit_templates = 0;
1273       break;
1274
1275     case OPT_frtti:
1276       flag_rtti = on;
1277       break;
1278
1279     case OPT_fshow_column:
1280       cpp_opts->show_column = on;
1281       break;
1282
1283     case OPT_fstats:
1284       flag_detailed_statistics = on;
1285       break;
1286
1287     case OPT_ftabstop:
1288       /* Don't recognize -fno-tabstop=.  */
1289       if (!on)
1290         return 0;
1291
1292       /* It is documented that we silently ignore silly values.  */
1293         {
1294           char *endptr;
1295           long tabstop = strtol (arg, &endptr, 10);
1296           if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1297             cpp_opts->tabstop = tabstop;
1298         }
1299       break;
1300
1301     case OPT_ftemplate_depth:
1302       max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
1303       break;
1304
1305     case OPT_fvtable_gc:
1306       flag_vtable_gc = on;
1307       break;
1308
1309     case OPT_fuse_cxa_atexit:
1310       flag_use_cxa_atexit = on;
1311       break;
1312
1313     case OPT_fweak:
1314       flag_weak = on;
1315       break;
1316
1317     case OPT_gen_decls:
1318       flag_gen_declaration = 1;
1319       break;
1320
1321     case OPT_idirafter:
1322       add_path (xstrdup (arg), AFTER, 0);
1323       break;
1324
1325     case OPT_iprefix:
1326       iprefix = arg;
1327       break;
1328
1329     case OPT_isysroot:
1330       sysroot = arg;
1331       break;
1332
1333     case OPT_isystem:
1334       add_path (xstrdup (arg), SYSTEM, 0);
1335       break;
1336
1337     case OPT_iwithprefix:
1338       add_prefixed_path (arg, SYSTEM);
1339       break;
1340
1341     case OPT_iwithprefixbefore:
1342       add_prefixed_path (arg, BRACKET);
1343       break;
1344
1345     case OPT_lang_asm:
1346       cpp_set_lang (parse_in, CLK_ASM);
1347       break;
1348
1349     case OPT_lang_objc:
1350       cpp_opts->objc = 1;
1351       break;
1352
1353     case OPT_nostdinc:
1354       std_inc = false;
1355       break;
1356
1357     case OPT_nostdincplusplus:
1358       std_cxx_inc = false;
1359       break;
1360
1361     case OPT_o:
1362       if (!out_fname)
1363         out_fname = arg;
1364       else
1365         {
1366           error ("output filename specified twice");
1367           result = argc;
1368         }
1369       break;
1370
1371       /* We need to handle the -pedantic switches here, rather than in
1372          c_common_post_options, so that a subsequent -Wno-endif-labels
1373          is not overridden.  */
1374     case OPT_pedantic_errors:
1375       cpp_opts->pedantic_errors = 1;
1376       /* fall through */
1377     case OPT_pedantic:
1378       cpp_opts->pedantic = 1;
1379       cpp_opts->warn_endif_labels = 1;
1380       break;
1381
1382     case OPT_print_objc_runtime_info:
1383       print_struct_values = 1;
1384       break;
1385
1386     case OPT_remap:
1387       cpp_opts->remap = 1;
1388       break;
1389
1390     case OPT_std_cplusplus98:
1391     case OPT_std_gnuplusplus98:
1392       set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
1393       break;
1394
1395     case OPT_std_c89:
1396     case OPT_std_iso9899_1990:
1397     case OPT_std_iso9899_199409:
1398       set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1399       break;
1400
1401     case OPT_std_gnu89:
1402       set_std_c89 (false /* c94 */, false /* ISO */);
1403       break;
1404
1405     case OPT_std_c99:
1406     case OPT_std_c9x:
1407     case OPT_std_iso9899_1999:
1408     case OPT_std_iso9899_199x:
1409       set_std_c99 (true /* ISO */);
1410       break;
1411
1412     case OPT_std_gnu99:
1413     case OPT_std_gnu9x:
1414       set_std_c99 (false /* ISO */);
1415       break;
1416
1417     case OPT_trigraphs:
1418       cpp_opts->trigraphs = 1;
1419       break;
1420
1421     case OPT_traditional_cpp:
1422       cpp_opts->traditional = 1;
1423       break;
1424
1425     case OPT_undef:
1426       flag_undef = 1;
1427       break;
1428
1429     case OPT_w:
1430       cpp_opts->inhibit_warnings = 1;
1431       break;
1432
1433     case OPT_v:
1434       verbose = true;
1435       break;
1436     }
1437
1438  done:
1439   if (dup)
1440     free (dup);
1441   return result;
1442 }
1443
1444 /* Post-switch processing.  */
1445 bool
1446 c_common_post_options ()
1447 {
1448   /* Canonicalize the input and output filenames.  */
1449   if (in_fname == NULL || !strcmp (in_fname, "-"))
1450     in_fname = "";
1451
1452   if (out_fname == NULL || !strcmp (out_fname, "-"))
1453     out_fname = "";
1454
1455   if (cpp_opts->deps.style == DEPS_NONE)
1456     check_deps_environment_vars ();
1457
1458   handle_deferred_opts ();
1459
1460   sanitize_cpp_opts ();
1461
1462   register_include_chains (parse_in, sysroot, iprefix,
1463                            std_inc, std_cxx_inc && c_language == clk_cplusplus,
1464                            verbose);
1465
1466   flag_inline_trees = 1;
1467
1468   /* Use tree inlining if possible.  Function instrumentation is only
1469      done in the RTL level, so we disable tree inlining.  */
1470   if (! flag_instrument_function_entry_exit)
1471     {
1472       if (!flag_no_inline)
1473         flag_no_inline = 1;
1474       if (flag_inline_functions)
1475         {
1476           flag_inline_trees = 2;
1477           flag_inline_functions = 0;
1478         }
1479     }
1480
1481   /* Special format checking options don't work without -Wformat; warn if
1482      they are used.  */
1483   if (warn_format_y2k && !warn_format)
1484     warning ("-Wformat-y2k ignored without -Wformat");
1485   if (warn_format_extra_args && !warn_format)
1486     warning ("-Wformat-extra-args ignored without -Wformat");
1487   if (warn_format_zero_length && !warn_format)
1488     warning ("-Wformat-zero-length ignored without -Wformat");
1489   if (warn_format_nonliteral && !warn_format)
1490     warning ("-Wformat-nonliteral ignored without -Wformat");
1491   if (warn_format_security && !warn_format)
1492     warning ("-Wformat-security ignored without -Wformat");
1493   if (warn_missing_format_attribute && !warn_format)
1494     warning ("-Wmissing-format-attribute ignored without -Wformat");
1495
1496   /* If an error has occurred in cpplib, note it so we fail
1497      immediately.  */
1498   errorcount += cpp_errors (parse_in);
1499
1500   return flag_preprocess_only;
1501 }
1502
1503 /* Preprocess the input file to out_stream.  */
1504 static void
1505 preprocess_file ()
1506 {
1507   /* Open the output now.  We must do so even if no_output is on,
1508      because there may be other output than from the actual
1509      preprocessing (e.g. from -dM).  */
1510   if (out_fname[0] == '\0')
1511     out_stream = stdout;
1512   else
1513     out_stream = fopen (out_fname, "w");
1514
1515   if (out_stream == NULL)
1516     fatal_io_error ("opening output file %s", out_fname);
1517   else
1518     cpp_preprocess_file (parse_in, in_fname, out_stream);
1519 }
1520
1521 /* Front end initialization common to C, ObjC and C++.  */
1522 const char *
1523 c_common_init (filename)
1524      const char *filename;
1525 {
1526   /* Set up preprocessor arithmetic.  Must be done after call to
1527      c_common_nodes_and_builtins for type nodes to be good.  */
1528   cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1529   cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1530   cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1531   cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1532   cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1533
1534   /* Register preprocessor built-ins before calls to
1535      cpp_main_file.  */
1536   cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins;
1537
1538   /* NULL is passed up to toplev.c and we exit quickly.  */
1539   if (flag_preprocess_only)
1540     {
1541       preprocess_file ();
1542       return NULL;
1543     }
1544
1545   /* Do this before initializing pragmas, as then cpplib's hash table
1546      has been set up.  NOTE: we are using our own file name here, not
1547      the one supplied.  */
1548   filename = init_c_lex (in_fname);
1549
1550   init_pragma ();
1551
1552   return filename;
1553 }
1554
1555 /* Common finish hook for the C, ObjC and C++ front ends.  */
1556 void
1557 c_common_finish ()
1558 {
1559   FILE *deps_stream = NULL;
1560
1561   if (cpp_opts->deps.style != DEPS_NONE)
1562     {
1563       /* If -M or -MM was seen without -MF, default output to the
1564          output stream.  */
1565       if (!deps_file)
1566         deps_stream = out_stream;
1567       else
1568         {
1569           deps_stream = fopen (deps_file, deps_append ? "a": "w");
1570           if (!deps_stream)
1571             fatal_io_error ("opening dependency file %s", deps_file);
1572         }
1573     }
1574
1575   /* For performance, avoid tearing down cpplib's internal structures
1576      with cpp_destroy ().  */
1577   errorcount += cpp_finish (parse_in, deps_stream);
1578
1579   if (deps_stream && deps_stream != out_stream
1580       && (ferror (deps_stream) || fclose (deps_stream)))
1581     fatal_io_error ("closing dependency file %s", deps_file);
1582
1583   if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1584     fatal_io_error ("when writing output to %s", out_fname);
1585 }
1586
1587 /* Either of two environment variables can specify output of
1588    dependencies.  Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1589    DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1590    and DEPS_TARGET is the target to mention in the deps.  They also
1591    result in dependency information being appended to the output file
1592    rather than overwriting it, and like Sun's compiler
1593    SUNPRO_DEPENDENCIES suppresses the dependency on the main file.  */
1594 static void
1595 check_deps_environment_vars ()
1596 {
1597   char *spec;
1598
1599   GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1600   if (spec)
1601     cpp_opts->deps.style = DEPS_USER;
1602   else
1603     {
1604       GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1605       if (spec)
1606         {
1607           cpp_opts->deps.style = DEPS_SYSTEM;
1608           cpp_opts->deps.ignore_main_file = true;
1609         }
1610     }
1611
1612   if (spec)
1613     {
1614       /* Find the space before the DEPS_TARGET, if there is one.  */
1615       char *s = strchr (spec, ' ');
1616       if (s)
1617         {
1618           /* Let the caller perform MAKE quoting.  */
1619           defer_opt (OPT_MT, s + 1);
1620           *s = '\0';
1621         }
1622
1623       /* Command line -MF overrides environment variables and default.  */
1624       if (!deps_file)
1625         deps_file = spec;
1626
1627       deps_append = 1;
1628     }
1629 }
1630
1631 /* Handle deferred command line switches.  */
1632 static void
1633 handle_deferred_opts ()
1634 {
1635   size_t i;
1636
1637   for (i = 0; i < deferred_count; i++)
1638     {
1639       struct deferred_opt *opt = &deferred_opts[i];
1640
1641       switch (opt->code)
1642         {
1643         case OPT_MT:
1644         case OPT_MQ:
1645           cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1646           break;
1647
1648         default:
1649           abort ();
1650         }
1651     }
1652
1653   free (deferred_opts);
1654 }
1655
1656 /* These settings are appropriate for GCC, but not necessarily so for
1657    cpplib as a library.  */
1658 static void
1659 sanitize_cpp_opts ()
1660 {
1661   /* If we don't know what style of dependencies to output, complain
1662      if any other dependency switches have been given.  */
1663   if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1664     error ("to generate dependencies you must specify either -M or -MM");
1665
1666   /* -dM and dependencies suppress normal output; do it here so that
1667      the last -d[MDN] switch overrides earlier ones.  */
1668   if (cpp_opts->dump_macros == dump_only)
1669     cpp_opts->no_output = 1;
1670
1671   /* Disable -dD, -dN and -dI if normal output is suppressed.  Allow
1672      -dM since at least glibc relies on -M -dM to work.  */
1673   if (cpp_opts->no_output)
1674     {
1675       if (cpp_opts->dump_macros != dump_only)
1676         cpp_opts->dump_macros = dump_none;
1677       cpp_opts->dump_includes = 0;
1678     }
1679
1680   cpp_opts->unsigned_char = !flag_signed_char;
1681   cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1682
1683   /* We want -Wno-long-long to override -pedantic -std=non-c99
1684      and/or -Wtraditional, whatever the ordering.  */
1685   cpp_opts->warn_long_long
1686     = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1687 }
1688
1689 /* Add include path with a prefix at the front of its name.  */
1690 static void
1691 add_prefixed_path (suffix, chain)
1692      const char *suffix;
1693      size_t chain;
1694 {
1695   const char *prefix;
1696
1697   prefix = iprefix ? iprefix: cpp_GCC_INCLUDE_DIR;
1698   add_path (concat (prefix, suffix), chain, 0);
1699 }
1700
1701 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1702    extensions if ISO).  There is no concept of gnu94.  */
1703 static void
1704 set_std_c89 (c94, iso)
1705      int c94, iso;
1706 {
1707   cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1708   flag_iso = iso;
1709   flag_no_asm = iso;
1710   flag_no_gnu_keywords = iso;
1711   flag_no_nonansi_builtin = iso;
1712   flag_noniso_default_format_attributes = !iso;
1713   flag_isoc94 = c94;
1714   flag_isoc99 = 0;
1715   flag_writable_strings = 0;
1716 }
1717
1718 /* Set the C 99 standard (without GNU extensions if ISO).  */
1719 static void
1720 set_std_c99 (iso)
1721      int iso;
1722 {
1723   cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1724   flag_no_asm = iso;
1725   flag_no_nonansi_builtin = iso;
1726   flag_noniso_default_format_attributes = !iso;
1727   flag_iso = iso;
1728   flag_isoc99 = 1;
1729   flag_isoc94 = 1;
1730   flag_writable_strings = 0;
1731 }
1732
1733 /* Set the C++ 98 standard (without GNU extensions if ISO).  */
1734 static void
1735 set_std_cxx98 (iso)
1736      int iso;
1737 {
1738   cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1739   flag_no_gnu_keywords = iso;
1740   flag_no_nonansi_builtin = iso;
1741   flag_noniso_default_format_attributes = !iso;
1742   flag_iso = iso;
1743 }
1744
1745 /* Handle setting implicit to ON.  */
1746 static void
1747 set_Wimplicit (on)
1748      int on;
1749 {
1750   warn_implicit = on;
1751   warn_implicit_int = on;
1752   if (on)
1753     {
1754       if (mesg_implicit_function_declaration != 2)
1755         mesg_implicit_function_declaration = 1;
1756     }
1757   else
1758     mesg_implicit_function_declaration = 0;
1759 }
1760
1761 /* Args to -d specify what to dump.  Silently ignore
1762    unrecognized options; they may be aimed at toplev.c.  */
1763 static void
1764 handle_OPT_d (arg)
1765      const char *arg;
1766 {
1767   char c;
1768
1769   while ((c = *arg++) != '\0')
1770     switch (c)
1771       {
1772       case 'M':
1773         cpp_opts->dump_macros = dump_only;
1774         break;
1775
1776       case 'N':
1777         cpp_opts->dump_macros = dump_names;
1778         break;
1779
1780       case 'D':
1781         cpp_opts->dump_macros = dump_definitions;
1782         break;
1783
1784       case 'I':
1785         cpp_opts->dump_includes = 1;
1786         break;
1787       }
1788 }
1789
1790 /* Write a slash-separated list of languages in FLAGS to BUF.  */
1791 static void
1792 write_langs (buf, flags)
1793      char *buf;
1794      int flags;
1795 {
1796   *buf = '\0';
1797   if (flags & CL_C_ONLY)
1798     strcat (buf, "C");
1799   if (flags & CL_OBJC_ONLY)
1800     {
1801       if (*buf)
1802         strcat (buf, "/");
1803       strcat (buf, "ObjC");
1804     }
1805   if (flags & CL_CXX_ONLY)
1806     {
1807       if (*buf)
1808         strcat (buf, "/");
1809       strcat (buf, "C++");
1810     }
1811 }
1812
1813 /* Complain that switch OPT_INDEX does not apply to this front end.  */
1814 static void
1815 complain_wrong_lang (opt_index)
1816      size_t opt_index;
1817 {
1818   char ok_langs[60], bad_langs[60];
1819   int ok_flags = cl_options[opt_index].flags;
1820
1821   write_langs (ok_langs, ok_flags);
1822   write_langs (bad_langs, ~ok_flags);
1823   warning ("\"-%s\" is valid for %s but not for %s",
1824            cl_options[opt_index].opt_text, ok_langs, bad_langs);
1825 }
1826
1827 /* Handle --help output.  */
1828 static void
1829 print_help ()
1830 {
1831   /* To keep the lines from getting too long for some compilers, limit
1832      to about 500 characters (6 lines) per chunk.  */
1833   fputs (_("\
1834 Switches:\n\
1835   -include <file>           Include the contents of <file> before other files\n\
1836   -imacros <file>           Accept definition of macros in <file>\n\
1837   -iprefix <path>           Specify <path> as a prefix for next two options\n\
1838   -iwithprefix <dir>        Add <dir> to the end of the system include path\n\
1839   -iwithprefixbefore <dir>  Add <dir> to the end of the main include path\n\
1840   -isystem <dir>            Add <dir> to the start of the system include path\n\
1841 "), stdout);
1842   fputs (_("\
1843   -idirafter <dir>          Add <dir> to the end of the system include path\n\
1844   -I <dir>                  Add <dir> to the end of the main include path\n\
1845   -I-                       Fine-grained include path control; see info docs\n\
1846   -nostdinc                 Do not search system include directories\n\
1847                              (dirs specified with -isystem will still be used)\n\
1848   -nostdinc++               Do not search system include directories for C++\n\
1849   -o <file>                 Put output into <file>\n\
1850 "), stdout);
1851   fputs (_("\
1852   -trigraphs                Support ISO C trigraphs\n\
1853   -std=<std name>           Specify the conformance standard; one of:\n\
1854                             gnu89, gnu99, c89, c99, iso9899:1990,\n\
1855                             iso9899:199409, iso9899:1999, c++98\n\
1856   -w                        Inhibit warning messages\n\
1857   -W[no-]trigraphs          Warn if trigraphs are encountered\n\
1858   -W[no-]comment{s}         Warn if one comment starts inside another\n\
1859 "), stdout);
1860   fputs (_("\
1861   -W[no-]traditional        Warn about features not present in traditional C\n\
1862   -W[no-]undef              Warn if an undefined macro is used by #if\n\
1863   -W[no-]import             Warn about the use of the #import directive\n\
1864 "), stdout);
1865   fputs (_("\
1866   -W[no-]error              Treat all warnings as errors\n\
1867   -W[no-]system-headers     Do not suppress warnings from system headers\n\
1868   -W[no-]all                Enable most preprocessor warnings\n\
1869 "), stdout);
1870   fputs (_("\
1871   -M                        Generate make dependencies\n\
1872   -MM                       As -M, but ignore system header files\n\
1873   -MD                       Generate make dependencies and compile\n\
1874   -MMD                      As -MD, but ignore system header files\n\
1875   -MF <file>                Write dependency output to the given file\n\
1876   -MG                       Treat missing header file as generated files\n\
1877 "), stdout);
1878   fputs (_("\
1879   -MP                       Generate phony targets for all headers\n\
1880   -MQ <target>              Add a MAKE-quoted target\n\
1881   -MT <target>              Add an unquoted target\n\
1882 "), stdout);
1883   fputs (_("\
1884   -D<macro>                 Define a <macro> with string '1' as its value\n\
1885   -D<macro>=<val>           Define a <macro> with <val> as its value\n\
1886   -A<question>=<answer>     Assert the <answer> to <question>\n\
1887   -A-<question>=<answer>    Disable the <answer> to <question>\n\
1888   -U<macro>                 Undefine <macro> \n\
1889   -v                        Display the version number\n\
1890 "), stdout);
1891   fputs (_("\
1892   -H                        Print the name of header files as they are used\n\
1893   -C                        Do not discard comments\n\
1894   -dM                       Display a list of macro definitions active at end\n\
1895   -dD                       Preserve macro definitions in output\n\
1896   -dN                       As -dD except that only the names are preserved\n\
1897   -dI                       Include #include directives in the output\n\
1898 "), stdout);
1899   fputs (_("\
1900   -f[no-]preprocessed       Treat the input file as already preprocessed\n\
1901   -ftabstop=<number>        Distance between tab stops for column reporting\n\
1902   -isysroot <dir>           Set <dir> to be the system root directory\n\
1903   -P                        Do not generate #line directives\n\
1904   -remap                    Remap file names when including files\n\
1905   --help                    Display this information\n\
1906 "), stdout);
1907 }