110d565efSmrg /* C/ObjC/C++ command line option handling.
2*ec02198aSmrg Copyright (C) 2002-2020 Free Software Foundation, Inc.
310d565efSmrg Contributed by Neil Booth.
410d565efSmrg
510d565efSmrg This file is part of GCC.
610d565efSmrg
710d565efSmrg GCC is free software; you can redistribute it and/or modify it under
810d565efSmrg the terms of the GNU General Public License as published by the Free
910d565efSmrg Software Foundation; either version 3, or (at your option) any later
1010d565efSmrg version.
1110d565efSmrg
1210d565efSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1310d565efSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1410d565efSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1510d565efSmrg for more details.
1610d565efSmrg
1710d565efSmrg You should have received a copy of the GNU General Public License
1810d565efSmrg along with GCC; see the file COPYING3. If not see
1910d565efSmrg <http://www.gnu.org/licenses/>. */
2010d565efSmrg
2110d565efSmrg #include "config.h"
2210d565efSmrg #include "system.h"
2310d565efSmrg #include "coretypes.h"
2410d565efSmrg #include "tm.h"
2510d565efSmrg #include "c-target.h"
2610d565efSmrg #include "c-common.h"
2710d565efSmrg #include "memmodel.h"
2810d565efSmrg #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
2910d565efSmrg #include "diagnostic.h"
3010d565efSmrg #include "c-pragma.h"
3110d565efSmrg #include "flags.h"
3210d565efSmrg #include "toplev.h"
3310d565efSmrg #include "langhooks.h"
3410d565efSmrg #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
3510d565efSmrg #include "intl.h"
3610d565efSmrg #include "cppdefault.h"
3710d565efSmrg #include "incpath.h"
3810d565efSmrg #include "debug.h" /* For debug_hooks. */
3910d565efSmrg #include "opts.h"
4010d565efSmrg #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
4110d565efSmrg #include "mkdeps.h"
4210d565efSmrg #include "dumpfile.h"
43c7a68eb7Smrg #include "file-prefix-map.h" /* add_*_prefix_map() */
4410d565efSmrg
4510d565efSmrg #ifndef DOLLARS_IN_IDENTIFIERS
4610d565efSmrg # define DOLLARS_IN_IDENTIFIERS true
4710d565efSmrg #endif
4810d565efSmrg
4910d565efSmrg #ifndef TARGET_SYSTEM_ROOT
5010d565efSmrg # define TARGET_SYSTEM_ROOT NULL
5110d565efSmrg #endif
5210d565efSmrg
5310d565efSmrg #ifndef TARGET_OPTF
5410d565efSmrg #define TARGET_OPTF(ARG)
5510d565efSmrg #endif
5610d565efSmrg
5710d565efSmrg /* CPP's options. */
5810d565efSmrg cpp_options *cpp_opts;
5910d565efSmrg
6010d565efSmrg /* Input filename. */
6110d565efSmrg static const char *this_input_filename;
6210d565efSmrg
6310d565efSmrg /* Filename and stream for preprocessed output. */
6410d565efSmrg static const char *out_fname;
6510d565efSmrg static FILE *out_stream;
6610d565efSmrg
6710d565efSmrg /* Append dependencies to deps_file. */
6810d565efSmrg static bool deps_append;
6910d565efSmrg
7010d565efSmrg /* If dependency switches (-MF etc.) have been given. */
7110d565efSmrg static bool deps_seen;
7210d565efSmrg
7310d565efSmrg /* If -v seen. */
7410d565efSmrg static bool verbose;
7510d565efSmrg
7610d565efSmrg /* Dependency output file. */
7710d565efSmrg static const char *deps_file;
7810d565efSmrg
7910d565efSmrg /* The prefix given by -iprefix, if any. */
8010d565efSmrg static const char *iprefix;
8110d565efSmrg
8210d565efSmrg /* The multilib directory given by -imultilib, if any. */
8310d565efSmrg static const char *imultilib;
8410d565efSmrg
8510d565efSmrg /* The system root, if any. Overridden by -isysroot. */
8610d565efSmrg static const char *sysroot = TARGET_SYSTEM_ROOT;
8710d565efSmrg
8810d565efSmrg /* Zero disables all standard directories for headers. */
8910d565efSmrg static bool std_inc = true;
9010d565efSmrg
9110d565efSmrg /* Zero disables the C++-specific standard directories for headers. */
9210d565efSmrg static bool std_cxx_inc = true;
9310d565efSmrg
9410d565efSmrg /* If the quote chain has been split by -I-. */
9510d565efSmrg static bool quote_chain_split;
9610d565efSmrg
9710d565efSmrg /* Number of deferred options. */
9810d565efSmrg static size_t deferred_count;
9910d565efSmrg
10010d565efSmrg /* Number of deferred options scanned for -include. */
10110d565efSmrg static size_t include_cursor;
10210d565efSmrg
10310d565efSmrg /* Dump files/flags to use during parsing. */
10410d565efSmrg static FILE *original_dump_file = NULL;
105c7a68eb7Smrg static dump_flags_t original_dump_flags;
10610d565efSmrg
10710d565efSmrg /* Whether any standard preincluded header has been preincluded. */
10810d565efSmrg static bool done_preinclude;
10910d565efSmrg
11010d565efSmrg static void handle_OPT_d (const char *);
11110d565efSmrg static void set_std_cxx98 (int);
11210d565efSmrg static void set_std_cxx11 (int);
11310d565efSmrg static void set_std_cxx14 (int);
114c7a68eb7Smrg static void set_std_cxx17 (int);
115c7a68eb7Smrg static void set_std_cxx2a (int);
11610d565efSmrg static void set_std_c89 (int, int);
11710d565efSmrg static void set_std_c99 (int);
11810d565efSmrg static void set_std_c11 (int);
119c7a68eb7Smrg static void set_std_c17 (int);
1200fc04c29Smrg static void set_std_c2x (int);
12110d565efSmrg static void check_deps_environment_vars (void);
12210d565efSmrg static void handle_deferred_opts (void);
12310d565efSmrg static void sanitize_cpp_opts (void);
124c7a68eb7Smrg static void add_prefixed_path (const char *, incpath_kind);
12510d565efSmrg static void push_command_line_include (void);
12610d565efSmrg static void cb_file_change (cpp_reader *, const line_map_ordinary *);
12710d565efSmrg static void cb_dir_change (cpp_reader *, const char *);
12810d565efSmrg static void c_finish_options (void);
12910d565efSmrg
13010d565efSmrg #ifndef STDC_0_IN_SYSTEM_HEADERS
13110d565efSmrg #define STDC_0_IN_SYSTEM_HEADERS 0
13210d565efSmrg #endif
13310d565efSmrg
13410d565efSmrg /* Holds switches parsed by c_common_handle_option (), but whose
13510d565efSmrg handling is deferred to c_common_post_options (). */
13610d565efSmrg static void defer_opt (enum opt_code, const char *);
13710d565efSmrg static struct deferred_opt
13810d565efSmrg {
13910d565efSmrg enum opt_code code;
14010d565efSmrg const char *arg;
14110d565efSmrg } *deferred_opts;
14210d565efSmrg
14310d565efSmrg
14410d565efSmrg extern const unsigned int
14510d565efSmrg c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
14610d565efSmrg
14710d565efSmrg /* Defer option CODE with argument ARG. */
14810d565efSmrg static void
defer_opt(enum opt_code code,const char * arg)14910d565efSmrg defer_opt (enum opt_code code, const char *arg)
15010d565efSmrg {
15110d565efSmrg deferred_opts[deferred_count].code = code;
15210d565efSmrg deferred_opts[deferred_count].arg = arg;
15310d565efSmrg deferred_count++;
15410d565efSmrg }
15510d565efSmrg
15610d565efSmrg /* Return language mask for option parsing. */
15710d565efSmrg unsigned int
c_common_option_lang_mask(void)15810d565efSmrg c_common_option_lang_mask (void)
15910d565efSmrg {
16010d565efSmrg static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
16110d565efSmrg
16210d565efSmrg return lang_flags[c_language];
16310d565efSmrg }
16410d565efSmrg
16510d565efSmrg /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
16610d565efSmrg static void
c_diagnostic_finalizer(diagnostic_context * context,diagnostic_info * diagnostic,diagnostic_t)16710d565efSmrg c_diagnostic_finalizer (diagnostic_context *context,
1680fc04c29Smrg diagnostic_info *diagnostic,
1690fc04c29Smrg diagnostic_t)
17010d565efSmrg {
171*ec02198aSmrg char *saved_prefix = pp_take_prefix (context->printer);
172*ec02198aSmrg pp_set_prefix (context->printer, NULL);
173*ec02198aSmrg pp_newline (context->printer);
17410d565efSmrg diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
17510d565efSmrg /* By default print macro expansion contexts in the diagnostic
17610d565efSmrg finalizer -- for tokens resulting from macro expansion. */
17710d565efSmrg virt_loc_aware_diagnostic_finalizer (context, diagnostic);
178*ec02198aSmrg pp_set_prefix (context->printer, saved_prefix);
17910d565efSmrg pp_flush (context->printer);
18010d565efSmrg }
18110d565efSmrg
18210d565efSmrg /* Common default settings for diagnostics. */
18310d565efSmrg void
c_common_diagnostics_set_defaults(diagnostic_context * context)18410d565efSmrg c_common_diagnostics_set_defaults (diagnostic_context *context)
18510d565efSmrg {
18610d565efSmrg diagnostic_finalizer (context) = c_diagnostic_finalizer;
18710d565efSmrg context->opt_permissive = OPT_fpermissive;
18810d565efSmrg }
18910d565efSmrg
19010d565efSmrg /* Whether options from all C-family languages should be accepted
19110d565efSmrg quietly. */
19210d565efSmrg static bool accept_all_c_family_options = false;
19310d565efSmrg
19410d565efSmrg /* Return whether to complain about a wrong-language option. */
19510d565efSmrg bool
c_common_complain_wrong_lang_p(const struct cl_option * option)19610d565efSmrg c_common_complain_wrong_lang_p (const struct cl_option *option)
19710d565efSmrg {
19810d565efSmrg if (accept_all_c_family_options
19910d565efSmrg && (option->flags & c_family_lang_mask))
20010d565efSmrg return false;
20110d565efSmrg
20210d565efSmrg return true;
20310d565efSmrg }
20410d565efSmrg
20510d565efSmrg /* Initialize options structure OPTS. */
20610d565efSmrg void
c_common_init_options_struct(struct gcc_options * opts)20710d565efSmrg c_common_init_options_struct (struct gcc_options *opts)
20810d565efSmrg {
20910d565efSmrg opts->x_flag_exceptions = c_dialect_cxx ();
21010d565efSmrg opts->x_warn_pointer_arith = c_dialect_cxx ();
21110d565efSmrg opts->x_warn_write_strings = c_dialect_cxx ();
21210d565efSmrg opts->x_flag_warn_unused_result = true;
21310d565efSmrg
21410d565efSmrg /* By default, C99-like requirements for complex multiply and divide. */
21510d565efSmrg opts->x_flag_complex_method = 2;
21610d565efSmrg }
21710d565efSmrg
21810d565efSmrg /* Common initialization before calling option handlers. */
21910d565efSmrg void
c_common_init_options(unsigned int decoded_options_count,struct cl_decoded_option * decoded_options)22010d565efSmrg c_common_init_options (unsigned int decoded_options_count,
22110d565efSmrg struct cl_decoded_option *decoded_options)
22210d565efSmrg {
22310d565efSmrg unsigned int i;
22410d565efSmrg struct cpp_callbacks *cb;
22510d565efSmrg
22610d565efSmrg g_string_concat_db
22710d565efSmrg = new (ggc_alloc <string_concat_db> ()) string_concat_db ();
22810d565efSmrg
22910d565efSmrg parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
23010d565efSmrg ident_hash, line_table);
23110d565efSmrg cb = cpp_get_callbacks (parse_in);
2320fc04c29Smrg cb->diagnostic = c_cpp_diagnostic;
23310d565efSmrg
23410d565efSmrg cpp_opts = cpp_get_options (parse_in);
23510d565efSmrg cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
23610d565efSmrg cpp_opts->objc = c_dialect_objc ();
23710d565efSmrg
23810d565efSmrg /* Reset to avoid warnings on internal definitions. We set it just
23910d565efSmrg before passing on command-line options to cpplib. */
24010d565efSmrg cpp_opts->warn_dollars = 0;
24110d565efSmrg
24210d565efSmrg deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
24310d565efSmrg
24410d565efSmrg if (c_language == clk_c)
24510d565efSmrg {
246c7a68eb7Smrg /* The default for C is gnu17. */
247c7a68eb7Smrg set_std_c17 (false /* ISO */);
24810d565efSmrg
24910d565efSmrg /* If preprocessing assembly language, accept any of the C-family
25010d565efSmrg front end options since the driver may pass them through. */
25110d565efSmrg for (i = 1; i < decoded_options_count; i++)
25210d565efSmrg if (decoded_options[i].opt_index == OPT_lang_asm)
25310d565efSmrg {
25410d565efSmrg accept_all_c_family_options = true;
25510d565efSmrg break;
25610d565efSmrg }
25710d565efSmrg }
25810d565efSmrg
25910d565efSmrg /* Set C++ standard to C++14 if not specified on the command line. */
26010d565efSmrg if (c_dialect_cxx ())
26110d565efSmrg set_std_cxx14 (/*ISO*/false);
26210d565efSmrg
26310d565efSmrg global_dc->colorize_source_p = true;
26410d565efSmrg }
26510d565efSmrg
26610d565efSmrg /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
26710d565efSmrg form of an -f or -W option was given. Returns false if the switch was
26810d565efSmrg invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
26910d565efSmrg bool
c_common_handle_option(size_t scode,const char * arg,HOST_WIDE_INT value,int kind,location_t loc,const struct cl_option_handlers * handlers)2700fc04c29Smrg c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
27110d565efSmrg int kind, location_t loc,
27210d565efSmrg const struct cl_option_handlers *handlers)
27310d565efSmrg {
27410d565efSmrg const struct cl_option *option = &cl_options[scode];
27510d565efSmrg enum opt_code code = (enum opt_code) scode;
27610d565efSmrg bool result = true;
27710d565efSmrg
27810d565efSmrg /* Prevent resetting the language standard to a C dialect when the driver
27910d565efSmrg has already determined that we're looking at assembler input. */
28010d565efSmrg bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
28110d565efSmrg
28210d565efSmrg switch (code)
28310d565efSmrg {
28410d565efSmrg default:
28510d565efSmrg if (cl_options[code].flags & c_family_lang_mask)
28610d565efSmrg {
28710d565efSmrg if ((option->flags & CL_TARGET)
28810d565efSmrg && ! targetcm.handle_c_option (scode, arg, value))
28910d565efSmrg result = false;
29010d565efSmrg break;
29110d565efSmrg }
29210d565efSmrg result = false;
29310d565efSmrg break;
29410d565efSmrg
29510d565efSmrg case OPT__output_pch_:
29610d565efSmrg pch_file = arg;
29710d565efSmrg break;
29810d565efSmrg
29910d565efSmrg case OPT_A:
30010d565efSmrg defer_opt (code, arg);
30110d565efSmrg break;
30210d565efSmrg
30310d565efSmrg case OPT_C:
30410d565efSmrg cpp_opts->discard_comments = 0;
30510d565efSmrg break;
30610d565efSmrg
30710d565efSmrg case OPT_CC:
30810d565efSmrg cpp_opts->discard_comments = 0;
30910d565efSmrg cpp_opts->discard_comments_in_macro_exp = 0;
31010d565efSmrg break;
31110d565efSmrg
31210d565efSmrg case OPT_cxx_isystem:
313c7a68eb7Smrg add_path (xstrdup (arg), INC_SYSTEM, 1, true);
31410d565efSmrg break;
31510d565efSmrg
31610d565efSmrg case OPT_D:
31710d565efSmrg defer_opt (code, arg);
31810d565efSmrg break;
31910d565efSmrg
32010d565efSmrg case OPT_H:
32110d565efSmrg cpp_opts->print_include_names = 1;
32210d565efSmrg break;
32310d565efSmrg
32410d565efSmrg case OPT_F:
32510d565efSmrg TARGET_OPTF (xstrdup (arg));
32610d565efSmrg break;
32710d565efSmrg
32810d565efSmrg case OPT_I:
32910d565efSmrg if (strcmp (arg, "-"))
330c7a68eb7Smrg add_path (xstrdup (arg), INC_BRACKET, 0, true);
33110d565efSmrg else
33210d565efSmrg {
33310d565efSmrg if (quote_chain_split)
3340fc04c29Smrg error ("%<-I-%> specified twice");
33510d565efSmrg quote_chain_split = true;
33610d565efSmrg split_quote_chain ();
3370fc04c29Smrg inform (input_location, "obsolete option %<-I-%> used, "
3380fc04c29Smrg "please use %<-iquote%> instead");
33910d565efSmrg }
34010d565efSmrg break;
34110d565efSmrg
34210d565efSmrg case OPT_M:
34310d565efSmrg case OPT_MM:
34410d565efSmrg /* When doing dependencies with -M or -MM, suppress normal
34510d565efSmrg preprocessed output, but still do -dM etc. as software
34610d565efSmrg depends on this. Preprocessed output does occur if -MD, -MMD
34710d565efSmrg or environment var dependency generation is used. */
34810d565efSmrg cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
34910d565efSmrg flag_no_output = 1;
35010d565efSmrg break;
35110d565efSmrg
35210d565efSmrg case OPT_MD:
35310d565efSmrg case OPT_MMD:
35410d565efSmrg cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
35510d565efSmrg cpp_opts->deps.need_preprocessor_output = true;
35610d565efSmrg deps_file = arg;
35710d565efSmrg break;
35810d565efSmrg
35910d565efSmrg case OPT_MF:
36010d565efSmrg deps_seen = true;
36110d565efSmrg deps_file = arg;
36210d565efSmrg break;
36310d565efSmrg
36410d565efSmrg case OPT_MG:
36510d565efSmrg deps_seen = true;
36610d565efSmrg cpp_opts->deps.missing_files = true;
36710d565efSmrg break;
36810d565efSmrg
36910d565efSmrg case OPT_MP:
37010d565efSmrg deps_seen = true;
37110d565efSmrg cpp_opts->deps.phony_targets = true;
37210d565efSmrg break;
37310d565efSmrg
37410d565efSmrg case OPT_MQ:
37510d565efSmrg case OPT_MT:
37610d565efSmrg deps_seen = true;
37710d565efSmrg defer_opt (code, arg);
37810d565efSmrg break;
37910d565efSmrg
38010d565efSmrg case OPT_P:
38110d565efSmrg flag_no_line_commands = 1;
38210d565efSmrg break;
38310d565efSmrg
38410d565efSmrg case OPT_U:
38510d565efSmrg defer_opt (code, arg);
38610d565efSmrg break;
38710d565efSmrg
38810d565efSmrg case OPT_Wall:
38910d565efSmrg /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
39010d565efSmrg
39110d565efSmrg cpp_opts->warn_num_sign_change = value;
39210d565efSmrg break;
39310d565efSmrg
39410d565efSmrg case OPT_Wunknown_pragmas:
39510d565efSmrg /* Set to greater than 1, so that even unknown pragmas in
39610d565efSmrg system headers will be warned about. */
39710d565efSmrg /* ??? There is no way to handle this automatically for now. */
39810d565efSmrg warn_unknown_pragmas = value * 2;
39910d565efSmrg break;
40010d565efSmrg
40110d565efSmrg case OPT_ansi:
40210d565efSmrg if (!c_dialect_cxx ())
40310d565efSmrg set_std_c89 (false, true);
40410d565efSmrg else
40510d565efSmrg set_std_cxx98 (true);
40610d565efSmrg break;
40710d565efSmrg
40810d565efSmrg case OPT_d:
40910d565efSmrg handle_OPT_d (arg);
41010d565efSmrg break;
41110d565efSmrg
41210d565efSmrg case OPT_Wabi_:
41310d565efSmrg warn_abi = true;
41410d565efSmrg if (value == 1)
41510d565efSmrg {
41610d565efSmrg warning (0, "%<-Wabi=1%> is not supported, using =2");
41710d565efSmrg value = 2;
41810d565efSmrg }
41910d565efSmrg warn_abi_version = value;
42010d565efSmrg break;
42110d565efSmrg
42210d565efSmrg case OPT_fcanonical_system_headers:
42310d565efSmrg cpp_opts->canonical_system_headers = value;
42410d565efSmrg break;
42510d565efSmrg
42610d565efSmrg case OPT_fcond_mismatch:
42710d565efSmrg if (!c_dialect_cxx ())
42810d565efSmrg {
42910d565efSmrg flag_cond_mismatch = value;
43010d565efSmrg break;
43110d565efSmrg }
43210d565efSmrg warning (0, "switch %qs is no longer supported", option->opt_text);
43310d565efSmrg break;
43410d565efSmrg
43510d565efSmrg case OPT_fbuiltin_:
43610d565efSmrg if (value)
43710d565efSmrg result = false;
43810d565efSmrg else
43910d565efSmrg disable_builtin_function (arg);
44010d565efSmrg break;
44110d565efSmrg
44210d565efSmrg case OPT_fdirectives_only:
44310d565efSmrg cpp_opts->directives_only = value;
44410d565efSmrg break;
44510d565efSmrg
44610d565efSmrg case OPT_fdollars_in_identifiers:
44710d565efSmrg cpp_opts->dollars_in_ident = value;
44810d565efSmrg break;
44910d565efSmrg
450c7a68eb7Smrg case OPT_fmacro_prefix_map_:
451c7a68eb7Smrg add_macro_prefix_map (arg);
452c7a68eb7Smrg break;
453c7a68eb7Smrg
45410d565efSmrg case OPT_ffreestanding:
45510d565efSmrg value = !value;
45610d565efSmrg /* Fall through. */
45710d565efSmrg case OPT_fhosted:
45810d565efSmrg flag_hosted = value;
45910d565efSmrg flag_no_builtin = !value;
46010d565efSmrg break;
46110d565efSmrg
46210d565efSmrg case OPT_fconstant_string_class_:
46310d565efSmrg constant_string_class_name = arg;
46410d565efSmrg break;
46510d565efSmrg
46610d565efSmrg case OPT_fextended_identifiers:
46710d565efSmrg cpp_opts->extended_identifiers = value;
46810d565efSmrg break;
46910d565efSmrg
470*ec02198aSmrg case OPT_fmax_include_depth_:
471*ec02198aSmrg cpp_opts->max_include_depth = value;
472*ec02198aSmrg break;
473*ec02198aSmrg
47410d565efSmrg case OPT_foperator_names:
47510d565efSmrg cpp_opts->operator_names = value;
47610d565efSmrg break;
47710d565efSmrg
47810d565efSmrg case OPT_fpch_deps:
47910d565efSmrg cpp_opts->restore_pch_deps = value;
48010d565efSmrg break;
48110d565efSmrg
48210d565efSmrg case OPT_fpch_preprocess:
48310d565efSmrg flag_pch_preprocess = value;
48410d565efSmrg break;
48510d565efSmrg
48610d565efSmrg case OPT_fpermissive:
48710d565efSmrg flag_permissive = value;
48810d565efSmrg global_dc->permissive = value;
48910d565efSmrg break;
49010d565efSmrg
49110d565efSmrg case OPT_fpreprocessed:
49210d565efSmrg cpp_opts->preprocessed = value;
49310d565efSmrg break;
49410d565efSmrg
49510d565efSmrg case OPT_fdebug_cpp:
49610d565efSmrg cpp_opts->debug = 1;
49710d565efSmrg break;
49810d565efSmrg
49910d565efSmrg case OPT_ftrack_macro_expansion:
50010d565efSmrg if (value)
50110d565efSmrg value = 2;
50210d565efSmrg /* Fall Through. */
50310d565efSmrg
50410d565efSmrg case OPT_ftrack_macro_expansion_:
50510d565efSmrg if (arg && *arg != '\0')
50610d565efSmrg cpp_opts->track_macro_expansion = value;
50710d565efSmrg else
50810d565efSmrg cpp_opts->track_macro_expansion = 2;
50910d565efSmrg break;
51010d565efSmrg
51110d565efSmrg case OPT_ftabstop_:
51210d565efSmrg /* It is documented that we silently ignore silly values. */
51310d565efSmrg if (value >= 1 && value <= 100)
51410d565efSmrg cpp_opts->tabstop = value;
51510d565efSmrg break;
51610d565efSmrg
51710d565efSmrg case OPT_fexec_charset_:
51810d565efSmrg cpp_opts->narrow_charset = arg;
51910d565efSmrg break;
52010d565efSmrg
52110d565efSmrg case OPT_fwide_exec_charset_:
52210d565efSmrg cpp_opts->wide_charset = arg;
52310d565efSmrg break;
52410d565efSmrg
52510d565efSmrg case OPT_finput_charset_:
52610d565efSmrg cpp_opts->input_charset = arg;
52710d565efSmrg break;
52810d565efSmrg
52910d565efSmrg case OPT_ftemplate_depth_:
53010d565efSmrg max_tinst_depth = value;
53110d565efSmrg break;
53210d565efSmrg
53310d565efSmrg case OPT_fvisibility_inlines_hidden:
53410d565efSmrg visibility_options.inlines_hidden = value;
53510d565efSmrg break;
53610d565efSmrg
53710d565efSmrg case OPT_femit_struct_debug_baseonly:
53810d565efSmrg set_struct_debug_option (&global_options, loc, "base");
53910d565efSmrg break;
54010d565efSmrg
54110d565efSmrg case OPT_femit_struct_debug_reduced:
54210d565efSmrg set_struct_debug_option (&global_options, loc,
54310d565efSmrg "dir:ord:sys,dir:gen:any,ind:base");
54410d565efSmrg break;
54510d565efSmrg
54610d565efSmrg case OPT_femit_struct_debug_detailed_:
54710d565efSmrg set_struct_debug_option (&global_options, loc, arg);
54810d565efSmrg break;
54910d565efSmrg
55010d565efSmrg case OPT_fext_numeric_literals:
55110d565efSmrg cpp_opts->ext_numeric_literals = value;
55210d565efSmrg break;
55310d565efSmrg
55410d565efSmrg case OPT_idirafter:
555c7a68eb7Smrg add_path (xstrdup (arg), INC_AFTER, 0, true);
55610d565efSmrg break;
55710d565efSmrg
55810d565efSmrg case OPT_imacros:
55910d565efSmrg case OPT_include:
56010d565efSmrg defer_opt (code, arg);
56110d565efSmrg break;
56210d565efSmrg
56310d565efSmrg case OPT_imultilib:
56410d565efSmrg imultilib = arg;
56510d565efSmrg break;
56610d565efSmrg
56710d565efSmrg case OPT_iprefix:
56810d565efSmrg iprefix = arg;
56910d565efSmrg break;
57010d565efSmrg
57110d565efSmrg case OPT_iquote:
572c7a68eb7Smrg add_path (xstrdup (arg), INC_QUOTE, 0, true);
57310d565efSmrg break;
57410d565efSmrg
57510d565efSmrg case OPT_iremap:
57610d565efSmrg add_cpp_remap_path (arg);
57710d565efSmrg break;
57810d565efSmrg
57910d565efSmrg case OPT_isysroot:
58010d565efSmrg sysroot = arg;
58110d565efSmrg break;
58210d565efSmrg
58310d565efSmrg case OPT_isystem:
584c7a68eb7Smrg add_path (xstrdup (arg), INC_SYSTEM, 0, true);
58510d565efSmrg break;
58610d565efSmrg
58710d565efSmrg case OPT_iwithprefix:
588c7a68eb7Smrg add_prefixed_path (arg, INC_SYSTEM);
58910d565efSmrg break;
59010d565efSmrg
59110d565efSmrg case OPT_iwithprefixbefore:
592c7a68eb7Smrg add_prefixed_path (arg, INC_BRACKET);
59310d565efSmrg break;
59410d565efSmrg
59510d565efSmrg case OPT_lang_asm:
59610d565efSmrg cpp_set_lang (parse_in, CLK_ASM);
59710d565efSmrg cpp_opts->dollars_in_ident = false;
59810d565efSmrg break;
59910d565efSmrg
60010d565efSmrg case OPT_nostdinc:
60110d565efSmrg std_inc = false;
60210d565efSmrg break;
60310d565efSmrg
60410d565efSmrg case OPT_nostdinc__:
60510d565efSmrg std_cxx_inc = false;
60610d565efSmrg break;
60710d565efSmrg
60810d565efSmrg case OPT_o:
60910d565efSmrg if (!out_fname)
61010d565efSmrg out_fname = arg;
61110d565efSmrg else
61210d565efSmrg error ("output filename specified twice");
61310d565efSmrg break;
61410d565efSmrg
61510d565efSmrg case OPT_print_objc_runtime_info:
61610d565efSmrg print_struct_values = 1;
61710d565efSmrg break;
61810d565efSmrg
61910d565efSmrg case OPT_remap:
62010d565efSmrg cpp_opts->remap = 1;
62110d565efSmrg break;
62210d565efSmrg
62310d565efSmrg case OPT_std_c__98:
62410d565efSmrg case OPT_std_gnu__98:
62510d565efSmrg if (!preprocessing_asm_p)
62610d565efSmrg set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
62710d565efSmrg break;
62810d565efSmrg
62910d565efSmrg case OPT_std_c__11:
63010d565efSmrg case OPT_std_gnu__11:
63110d565efSmrg if (!preprocessing_asm_p)
63210d565efSmrg set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
63310d565efSmrg break;
63410d565efSmrg
63510d565efSmrg case OPT_std_c__14:
63610d565efSmrg case OPT_std_gnu__14:
63710d565efSmrg if (!preprocessing_asm_p)
63810d565efSmrg set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
63910d565efSmrg break;
64010d565efSmrg
641c7a68eb7Smrg case OPT_std_c__17:
642c7a68eb7Smrg case OPT_std_gnu__17:
64310d565efSmrg if (!preprocessing_asm_p)
644c7a68eb7Smrg set_std_cxx17 (code == OPT_std_c__17 /* ISO */);
645c7a68eb7Smrg break;
646c7a68eb7Smrg
647c7a68eb7Smrg case OPT_std_c__2a:
648c7a68eb7Smrg case OPT_std_gnu__2a:
649c7a68eb7Smrg if (!preprocessing_asm_p)
650c7a68eb7Smrg set_std_cxx2a (code == OPT_std_c__2a /* ISO */);
65110d565efSmrg break;
65210d565efSmrg
65310d565efSmrg case OPT_std_c90:
65410d565efSmrg case OPT_std_iso9899_199409:
65510d565efSmrg if (!preprocessing_asm_p)
65610d565efSmrg set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
65710d565efSmrg break;
65810d565efSmrg
65910d565efSmrg case OPT_std_gnu90:
66010d565efSmrg if (!preprocessing_asm_p)
66110d565efSmrg set_std_c89 (false /* c94 */, false /* ISO */);
66210d565efSmrg break;
66310d565efSmrg
66410d565efSmrg case OPT_std_c99:
66510d565efSmrg if (!preprocessing_asm_p)
66610d565efSmrg set_std_c99 (true /* ISO */);
66710d565efSmrg break;
66810d565efSmrg
66910d565efSmrg case OPT_std_gnu99:
67010d565efSmrg if (!preprocessing_asm_p)
67110d565efSmrg set_std_c99 (false /* ISO */);
67210d565efSmrg break;
67310d565efSmrg
67410d565efSmrg case OPT_std_c11:
67510d565efSmrg if (!preprocessing_asm_p)
67610d565efSmrg set_std_c11 (true /* ISO */);
67710d565efSmrg break;
67810d565efSmrg
67910d565efSmrg case OPT_std_gnu11:
68010d565efSmrg if (!preprocessing_asm_p)
68110d565efSmrg set_std_c11 (false /* ISO */);
68210d565efSmrg break;
68310d565efSmrg
684c7a68eb7Smrg case OPT_std_c17:
685c7a68eb7Smrg if (!preprocessing_asm_p)
686c7a68eb7Smrg set_std_c17 (true /* ISO */);
687c7a68eb7Smrg break;
688c7a68eb7Smrg
689c7a68eb7Smrg case OPT_std_gnu17:
690c7a68eb7Smrg if (!preprocessing_asm_p)
691c7a68eb7Smrg set_std_c17 (false /* ISO */);
692c7a68eb7Smrg break;
693c7a68eb7Smrg
6940fc04c29Smrg case OPT_std_c2x:
6950fc04c29Smrg if (!preprocessing_asm_p)
6960fc04c29Smrg set_std_c2x (true /* ISO */);
6970fc04c29Smrg break;
6980fc04c29Smrg
6990fc04c29Smrg case OPT_std_gnu2x:
7000fc04c29Smrg if (!preprocessing_asm_p)
7010fc04c29Smrg set_std_c2x (false /* ISO */);
7020fc04c29Smrg break;
7030fc04c29Smrg
70410d565efSmrg case OPT_trigraphs:
70510d565efSmrg cpp_opts->trigraphs = 1;
70610d565efSmrg break;
70710d565efSmrg
70810d565efSmrg case OPT_traditional_cpp:
70910d565efSmrg cpp_opts->traditional = 1;
71010d565efSmrg break;
71110d565efSmrg
71210d565efSmrg case OPT_v:
71310d565efSmrg verbose = true;
71410d565efSmrg break;
71510d565efSmrg }
71610d565efSmrg
71710d565efSmrg switch (c_language)
71810d565efSmrg {
71910d565efSmrg case clk_c:
72010d565efSmrg C_handle_option_auto (&global_options, &global_options_set,
72110d565efSmrg scode, arg, value,
72210d565efSmrg c_family_lang_mask, kind,
72310d565efSmrg loc, handlers, global_dc);
72410d565efSmrg break;
72510d565efSmrg
72610d565efSmrg case clk_objc:
72710d565efSmrg ObjC_handle_option_auto (&global_options, &global_options_set,
72810d565efSmrg scode, arg, value,
72910d565efSmrg c_family_lang_mask, kind,
73010d565efSmrg loc, handlers, global_dc);
73110d565efSmrg break;
73210d565efSmrg
73310d565efSmrg case clk_cxx:
73410d565efSmrg CXX_handle_option_auto (&global_options, &global_options_set,
73510d565efSmrg scode, arg, value,
73610d565efSmrg c_family_lang_mask, kind,
73710d565efSmrg loc, handlers, global_dc);
73810d565efSmrg break;
73910d565efSmrg
74010d565efSmrg case clk_objcxx:
74110d565efSmrg ObjCXX_handle_option_auto (&global_options, &global_options_set,
74210d565efSmrg scode, arg, value,
74310d565efSmrg c_family_lang_mask, kind,
74410d565efSmrg loc, handlers, global_dc);
74510d565efSmrg break;
74610d565efSmrg
74710d565efSmrg default:
74810d565efSmrg gcc_unreachable ();
74910d565efSmrg }
75010d565efSmrg
75110d565efSmrg cpp_handle_option_auto (&global_options, scode, cpp_opts);
75210d565efSmrg return result;
75310d565efSmrg }
75410d565efSmrg
75510d565efSmrg /* Default implementation of TARGET_HANDLE_C_OPTION. */
75610d565efSmrg
75710d565efSmrg bool
default_handle_c_option(size_t code ATTRIBUTE_UNUSED,const char * arg ATTRIBUTE_UNUSED,int value ATTRIBUTE_UNUSED)75810d565efSmrg default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
75910d565efSmrg const char *arg ATTRIBUTE_UNUSED,
76010d565efSmrg int value ATTRIBUTE_UNUSED)
76110d565efSmrg {
76210d565efSmrg return false;
76310d565efSmrg }
76410d565efSmrg
76510d565efSmrg /* Post-switch processing. */
76610d565efSmrg bool
c_common_post_options(const char ** pfilename)76710d565efSmrg c_common_post_options (const char **pfilename)
76810d565efSmrg {
76910d565efSmrg struct cpp_callbacks *cb;
77010d565efSmrg
77110d565efSmrg /* Canonicalize the input and output filenames. */
77210d565efSmrg if (in_fnames == NULL)
77310d565efSmrg {
77410d565efSmrg in_fnames = XNEWVEC (const char *, 1);
77510d565efSmrg in_fnames[0] = "";
77610d565efSmrg }
77710d565efSmrg else if (strcmp (in_fnames[0], "-") == 0)
77810d565efSmrg {
77910d565efSmrg if (pch_file)
78010d565efSmrg error ("cannot use %<-%> as input filename for a precompiled header");
78110d565efSmrg
78210d565efSmrg in_fnames[0] = "";
78310d565efSmrg }
78410d565efSmrg
78510d565efSmrg if (out_fname == NULL || !strcmp (out_fname, "-"))
78610d565efSmrg out_fname = "";
78710d565efSmrg
78810d565efSmrg if (cpp_opts->deps.style == DEPS_NONE)
78910d565efSmrg check_deps_environment_vars ();
79010d565efSmrg
79110d565efSmrg handle_deferred_opts ();
79210d565efSmrg
79310d565efSmrg sanitize_cpp_opts ();
79410d565efSmrg
79510d565efSmrg register_include_chains (parse_in, sysroot, iprefix, imultilib,
79610d565efSmrg std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
79710d565efSmrg
79810d565efSmrg #ifdef C_COMMON_OVERRIDE_OPTIONS
79910d565efSmrg /* Some machines may reject certain combinations of C
80010d565efSmrg language-specific options. */
80110d565efSmrg C_COMMON_OVERRIDE_OPTIONS;
80210d565efSmrg #endif
80310d565efSmrg
80410d565efSmrg /* Excess precision other than "fast" requires front-end
80510d565efSmrg support. */
80610d565efSmrg if (c_dialect_cxx ())
80710d565efSmrg {
808*ec02198aSmrg if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
8090fc04c29Smrg sorry ("%<-fexcess-precision=standard%> for C++");
810*ec02198aSmrg flag_excess_precision = EXCESS_PRECISION_FAST;
81110d565efSmrg }
812*ec02198aSmrg else if (flag_excess_precision == EXCESS_PRECISION_DEFAULT)
813*ec02198aSmrg flag_excess_precision = (flag_iso ? EXCESS_PRECISION_STANDARD
81410d565efSmrg : EXCESS_PRECISION_FAST);
81510d565efSmrg
81610d565efSmrg /* ISO C restricts floating-point expression contraction to within
81710d565efSmrg source-language expressions (-ffp-contract=on, currently an alias
81810d565efSmrg for -ffp-contract=off). */
81910d565efSmrg if (flag_iso
82010d565efSmrg && !c_dialect_cxx ()
82110d565efSmrg && (global_options_set.x_flag_fp_contract_mode
82210d565efSmrg == (enum fp_contract_mode) 0)
82310d565efSmrg && flag_unsafe_math_optimizations == 0)
82410d565efSmrg flag_fp_contract_mode = FP_CONTRACT_OFF;
82510d565efSmrg
82610d565efSmrg /* If we are compiling C, and we are outside of a standards mode,
82710d565efSmrg we can permit the new values from ISO/IEC TS 18661-3 for
82810d565efSmrg FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
82910d565efSmrg the set specified in ISO C99/C11. */
83010d565efSmrg if (!flag_iso
83110d565efSmrg && !c_dialect_cxx ()
83210d565efSmrg && (global_options_set.x_flag_permitted_flt_eval_methods
83310d565efSmrg == PERMITTED_FLT_EVAL_METHODS_DEFAULT))
83410d565efSmrg flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_TS_18661;
83510d565efSmrg else
83610d565efSmrg flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
83710d565efSmrg
838*ec02198aSmrg /* C2X Annex F does not permit certain built-in functions to raise
839*ec02198aSmrg "inexact". */
840*ec02198aSmrg if (flag_isoc2x)
841*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set,
842*ec02198aSmrg flag_fp_int_builtin_inexact, 0);
843*ec02198aSmrg
84410d565efSmrg /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
84510d565efSmrg inline semantics are not supported in GNU89 or C89 mode. */
84610d565efSmrg if (flag_gnu89_inline == -1)
84710d565efSmrg flag_gnu89_inline = !flag_isoc99;
84810d565efSmrg else if (!flag_gnu89_inline && !flag_isoc99)
8490fc04c29Smrg error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
85010d565efSmrg
851*ec02198aSmrg /* Default to ObjC sjlj exception handling if NeXT runtime < v2. */
85210d565efSmrg if (flag_objc_sjlj_exceptions < 0)
853*ec02198aSmrg flag_objc_sjlj_exceptions = (flag_next_runtime && flag_objc_abi < 2);
85410d565efSmrg if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
85510d565efSmrg flag_exceptions = 1;
85610d565efSmrg
85710d565efSmrg /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
85810d565efSmrg pattern recognition. */
859*ec02198aSmrg if (flag_no_builtin)
860*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set,
861*ec02198aSmrg flag_tree_loop_distribute_patterns, 0);
86210d565efSmrg
86310d565efSmrg /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
86410d565efSmrg It is never enabled in C++, as the minimum limit is not normative
86510d565efSmrg in that standard. */
86610d565efSmrg if (c_dialect_cxx ())
86710d565efSmrg warn_overlength_strings = 0;
86810d565efSmrg
86910d565efSmrg /* Wmain is enabled by default in C++ but not in C. */
87010d565efSmrg /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
87110d565efSmrg even if -Wall or -Wpedantic was given (warn_main will be 2 if set
87210d565efSmrg by -Wall, 1 if set by -Wmain). */
87310d565efSmrg if (warn_main == -1)
87410d565efSmrg warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
87510d565efSmrg else if (warn_main == 2)
87610d565efSmrg warn_main = flag_hosted ? 1 : 0;
87710d565efSmrg
87810d565efSmrg /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
87910d565efSmrg yet been set, it is disabled by default. In C++, it is enabled
88010d565efSmrg by default. */
88110d565efSmrg if (warn_enum_compare == -1)
88210d565efSmrg warn_enum_compare = c_dialect_cxx () ? 1 : 0;
88310d565efSmrg
88410d565efSmrg /* -Wpacked-bitfield-compat is on by default for the C languages. The
88510d565efSmrg warning is issued in stor-layout.c which is not part of the front-end so
88610d565efSmrg we need to selectively turn it on here. */
88710d565efSmrg if (warn_packed_bitfield_compat == -1)
88810d565efSmrg warn_packed_bitfield_compat = 1;
88910d565efSmrg
89010d565efSmrg /* Special format checking options don't work without -Wformat; warn if
89110d565efSmrg they are used. */
89210d565efSmrg if (!warn_format)
89310d565efSmrg {
89410d565efSmrg warning (OPT_Wformat_y2k,
8950fc04c29Smrg "%<-Wformat-y2k%> ignored without %<-Wformat%>");
89610d565efSmrg warning (OPT_Wformat_extra_args,
8970fc04c29Smrg "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
89810d565efSmrg warning (OPT_Wformat_zero_length,
8990fc04c29Smrg "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
90010d565efSmrg warning (OPT_Wformat_nonliteral,
9010fc04c29Smrg "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
90210d565efSmrg warning (OPT_Wformat_contains_nul,
9030fc04c29Smrg "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
90410d565efSmrg warning (OPT_Wformat_security,
9050fc04c29Smrg "%<-Wformat-security%> ignored without %<-Wformat%>");
90610d565efSmrg }
90710d565efSmrg
90810d565efSmrg /* -Wimplicit-function-declaration is enabled by default for C99. */
90910d565efSmrg if (warn_implicit_function_declaration == -1)
91010d565efSmrg warn_implicit_function_declaration = flag_isoc99;
91110d565efSmrg
91210d565efSmrg /* -Wimplicit-int is enabled by default for C99. */
91310d565efSmrg if (warn_implicit_int == -1)
91410d565efSmrg warn_implicit_int = flag_isoc99;
91510d565efSmrg
916*ec02198aSmrg /* -Wold-style-definition is enabled by default for C2X. */
917*ec02198aSmrg if (warn_old_style_definition == -1)
918*ec02198aSmrg warn_old_style_definition = flag_isoc2x;
919*ec02198aSmrg
92010d565efSmrg /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
92110d565efSmrg if (warn_shift_overflow == -1)
92210d565efSmrg warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
92310d565efSmrg
924*ec02198aSmrg /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
925*ec02198aSmrg modes. */
92610d565efSmrg if (warn_shift_negative_value == -1)
92710d565efSmrg warn_shift_negative_value = (extra_warnings
928*ec02198aSmrg && (cxx_dialect >= cxx11 || flag_isoc99)
929*ec02198aSmrg && cxx_dialect < cxx2a);
93010d565efSmrg
93110d565efSmrg /* -Wregister is enabled by default in C++17. */
932*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_register,
933*ec02198aSmrg cxx_dialect >= cxx17);
934*ec02198aSmrg
935*ec02198aSmrg /* -Wcomma-subscript is enabled by default in C++20. */
936*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set,
937*ec02198aSmrg warn_comma_subscript,
938*ec02198aSmrg cxx_dialect >= cxx2a && warn_deprecated);
939*ec02198aSmrg
940*ec02198aSmrg /* -Wvolatile is enabled by default in C++20. */
941*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile,
942*ec02198aSmrg cxx_dialect >= cxx2a && warn_deprecated);
94310d565efSmrg
94410d565efSmrg /* Declone C++ 'structors if -Os. */
94510d565efSmrg if (flag_declone_ctor_dtor == -1)
94610d565efSmrg flag_declone_ctor_dtor = optimize_size;
94710d565efSmrg
94810d565efSmrg if (flag_abi_compat_version == 1)
94910d565efSmrg {
95010d565efSmrg warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
95110d565efSmrg flag_abi_compat_version = 2;
95210d565efSmrg }
95310d565efSmrg
954c7a68eb7Smrg /* Change flag_abi_version to be the actual current ABI level, for the
955c7a68eb7Smrg benefit of c_cpp_builtins, and to make comparison simpler. */
956*ec02198aSmrg const int latest_abi_version = 15;
957c7a68eb7Smrg /* Generate compatibility aliases for ABI v11 (7.1) by default. */
958c7a68eb7Smrg const int abi_compat_default = 11;
959c7a68eb7Smrg
960c7a68eb7Smrg #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
961c7a68eb7Smrg clamp (flag_abi_version);
962c7a68eb7Smrg clamp (warn_abi_version);
963c7a68eb7Smrg clamp (flag_abi_compat_version);
964c7a68eb7Smrg #undef clamp
965c7a68eb7Smrg
966c7a68eb7Smrg /* Default -Wabi= or -fabi-compat-version= from each other. */
967c7a68eb7Smrg if (warn_abi_version == -1 && flag_abi_compat_version != -1)
968c7a68eb7Smrg warn_abi_version = flag_abi_compat_version;
969c7a68eb7Smrg else if (flag_abi_compat_version == -1 && warn_abi_version != -1)
970c7a68eb7Smrg flag_abi_compat_version = warn_abi_version;
971c7a68eb7Smrg else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
972c7a68eb7Smrg {
973c7a68eb7Smrg warn_abi_version = latest_abi_version;
974c7a68eb7Smrg if (flag_abi_version == latest_abi_version)
975c7a68eb7Smrg {
9760fc04c29Smrg auto_diagnostic_group d;
9770fc04c29Smrg if (warning (OPT_Wabi, "%<-Wabi%> won%'t warn about anything"))
978c7a68eb7Smrg {
9790fc04c29Smrg inform (input_location, "%<-Wabi%> warns about differences "
980c7a68eb7Smrg "from the most up-to-date ABI, which is also used "
981c7a68eb7Smrg "by default");
9820fc04c29Smrg inform (input_location, "use e.g. %<-Wabi=11%> to warn about "
983c7a68eb7Smrg "changes from GCC 7");
984c7a68eb7Smrg }
985c7a68eb7Smrg flag_abi_compat_version = abi_compat_default;
986c7a68eb7Smrg }
987c7a68eb7Smrg else
988c7a68eb7Smrg flag_abi_compat_version = latest_abi_version;
989c7a68eb7Smrg }
99010d565efSmrg
99110d565efSmrg /* By default, enable the new inheriting constructor semantics along with ABI
99210d565efSmrg 11. New and old should coexist fine, but it is a change in what
99310d565efSmrg artificial symbols are generated. */
994*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set,
995*ec02198aSmrg flag_new_inheriting_ctors,
996*ec02198aSmrg abi_version_at_least (11));
99710d565efSmrg
998c7a68eb7Smrg /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
999*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_new_ttp,
1000*ec02198aSmrg cxx_dialect >= cxx17);
1001*ec02198aSmrg
1002*ec02198aSmrg /* C++11 guarantees forward progress. */
1003*ec02198aSmrg SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
1004*ec02198aSmrg optimize >= 2 && cxx_dialect >= cxx11);
100510d565efSmrg
100610d565efSmrg if (cxx_dialect >= cxx11)
100710d565efSmrg {
100810d565efSmrg /* If we're allowing C++0x constructs, don't warn about C++98
100910d565efSmrg identifiers which are keywords in C++0x. */
101010d565efSmrg warn_cxx11_compat = 0;
101110d565efSmrg cpp_opts->cpp_warn_cxx11_compat = 0;
101210d565efSmrg
101310d565efSmrg if (warn_narrowing == -1)
101410d565efSmrg warn_narrowing = 1;
101510d565efSmrg
101610d565efSmrg /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
1017c7a68eb7Smrg for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals. */
101810d565efSmrg if (flag_iso && !global_options_set.x_flag_ext_numeric_literals)
101910d565efSmrg cpp_opts->ext_numeric_literals = 0;
102010d565efSmrg }
102110d565efSmrg else if (warn_narrowing == -1)
102210d565efSmrg warn_narrowing = 0;
102310d565efSmrg
102410d565efSmrg /* C++17 has stricter evaluation order requirements; let's use some of them
102510d565efSmrg for earlier C++ as well, so chaining works as expected. */
102610d565efSmrg if (c_dialect_cxx ()
102710d565efSmrg && flag_strong_eval_order == -1)
1028c7a68eb7Smrg flag_strong_eval_order = (cxx_dialect >= cxx17 ? 2 : 1);
102910d565efSmrg
103010d565efSmrg /* Global sized deallocation is new in C++14. */
103110d565efSmrg if (flag_sized_deallocation == -1)
103210d565efSmrg flag_sized_deallocation = (cxx_dialect >= cxx14);
103310d565efSmrg
10340fc04c29Smrg /* char8_t support is new in C++2A. */
10350fc04c29Smrg if (flag_char8_t == -1)
10360fc04c29Smrg flag_char8_t = (cxx_dialect >= cxx2a);
10370fc04c29Smrg
103810d565efSmrg if (flag_extern_tls_init)
103910d565efSmrg {
1040c7a68eb7Smrg if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
1041c7a68eb7Smrg {
104210d565efSmrg /* Lazy TLS initialization for a variable in another TU requires
104310d565efSmrg alias and weak reference support. */
104410d565efSmrg if (flag_extern_tls_init > 0)
104510d565efSmrg sorry ("external TLS initialization functions not supported "
104610d565efSmrg "on this target");
1047c7a68eb7Smrg
104810d565efSmrg flag_extern_tls_init = 0;
104910d565efSmrg }
1050c7a68eb7Smrg else
1051c7a68eb7Smrg flag_extern_tls_init = 1;
1052c7a68eb7Smrg }
1053c7a68eb7Smrg
10540fc04c29Smrg /* Enable by default only for C++ and C++ with ObjC extensions. */
10550fc04c29Smrg if (warn_return_type == -1 && c_dialect_cxx ())
10560fc04c29Smrg warn_return_type = 1;
1057c7a68eb7Smrg
1058*ec02198aSmrg /* C++2a is the final version of concepts. We still use -fconcepts
1059*ec02198aSmrg to know when concepts are enabled. Note that -fconcepts-ts can
1060*ec02198aSmrg be used to include additional features, although modified to
1061*ec02198aSmrg work with the standard. */
1062*ec02198aSmrg if (cxx_dialect >= cxx2a || flag_concepts_ts)
1063*ec02198aSmrg flag_concepts = 1;
1064*ec02198aSmrg else if (flag_concepts)
1065*ec02198aSmrg /* For -std=c++17 -fconcepts, imply -fconcepts-ts. */
1066*ec02198aSmrg flag_concepts_ts = 1;
1067*ec02198aSmrg
1068c7a68eb7Smrg if (num_in_fnames > 1)
1069*ec02198aSmrg error ("too many filenames given; type %<%s %s%> for usage",
1070*ec02198aSmrg progname, "--help");
107110d565efSmrg
107210d565efSmrg if (flag_preprocess_only)
107310d565efSmrg {
107410d565efSmrg /* Open the output now. We must do so even if flag_no_output is
107510d565efSmrg on, because there may be other output than from the actual
107610d565efSmrg preprocessing (e.g. from -dM). */
107710d565efSmrg if (out_fname[0] == '\0')
107810d565efSmrg out_stream = stdout;
107910d565efSmrg else
108010d565efSmrg out_stream = fopen (out_fname, "w");
108110d565efSmrg
108210d565efSmrg if (out_stream == NULL)
108310d565efSmrg {
108410d565efSmrg fatal_error (input_location, "opening output file %s: %m", out_fname);
108510d565efSmrg return false;
108610d565efSmrg }
108710d565efSmrg
108810d565efSmrg init_pp_output (out_stream);
108910d565efSmrg }
109010d565efSmrg else
109110d565efSmrg {
109210d565efSmrg init_c_lex ();
109310d565efSmrg
109410d565efSmrg /* When writing a PCH file, avoid reading some other PCH file,
109510d565efSmrg because the default address space slot then can't be used
109610d565efSmrg for the output PCH file. */
109710d565efSmrg if (pch_file)
109810d565efSmrg {
109910d565efSmrg c_common_no_more_pch ();
110010d565efSmrg /* Only -g0 and -gdwarf* are supported with PCH, for other
110110d565efSmrg debug formats we warn here and refuse to load any PCH files. */
110210d565efSmrg if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
110310d565efSmrg warning (OPT_Wdeprecated,
1104*ec02198aSmrg "the %qs debug format cannot be used with "
110510d565efSmrg "pre-compiled headers", debug_type_names[write_symbols]);
110610d565efSmrg }
110710d565efSmrg else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
110810d565efSmrg c_common_no_more_pch ();
110910d565efSmrg
111010d565efSmrg /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
111110d565efSmrg input_location = UNKNOWN_LOCATION;
111210d565efSmrg }
111310d565efSmrg
111410d565efSmrg cb = cpp_get_callbacks (parse_in);
111510d565efSmrg cb->file_change = cb_file_change;
111610d565efSmrg cb->dir_change = cb_dir_change;
111710d565efSmrg cpp_post_options (parse_in);
111810d565efSmrg init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
111910d565efSmrg
112010d565efSmrg input_location = UNKNOWN_LOCATION;
112110d565efSmrg
112210d565efSmrg *pfilename = this_input_filename
112310d565efSmrg = cpp_read_main_file (parse_in, in_fnames[0]);
112410d565efSmrg /* Don't do any compilation or preprocessing if there is no input file. */
112510d565efSmrg if (this_input_filename == NULL)
112610d565efSmrg {
112710d565efSmrg errorcount++;
112810d565efSmrg return false;
112910d565efSmrg }
113010d565efSmrg
113110d565efSmrg if (flag_working_directory
113210d565efSmrg && flag_preprocess_only && !flag_no_line_commands)
113310d565efSmrg pp_dir_change (parse_in, get_src_pwd ());
113410d565efSmrg
113510d565efSmrg /* Disable LTO output when outputting a precompiled header. */
113610d565efSmrg if (pch_file && flag_lto)
113710d565efSmrg {
113810d565efSmrg flag_lto = 0;
113910d565efSmrg flag_generate_lto = 0;
114010d565efSmrg }
114110d565efSmrg
114210d565efSmrg return flag_preprocess_only;
114310d565efSmrg }
114410d565efSmrg
114510d565efSmrg /* Front end initialization common to C, ObjC and C++. */
114610d565efSmrg bool
c_common_init(void)114710d565efSmrg c_common_init (void)
114810d565efSmrg {
114910d565efSmrg /* Set up preprocessor arithmetic. Must be done after call to
115010d565efSmrg c_common_nodes_and_builtins for type nodes to be good. */
115110d565efSmrg cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
115210d565efSmrg cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
115310d565efSmrg cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
115410d565efSmrg cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
115510d565efSmrg cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
115610d565efSmrg cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
115710d565efSmrg
115810d565efSmrg /* This can't happen until after wchar_precision and bytes_big_endian
115910d565efSmrg are known. */
116010d565efSmrg cpp_init_iconv (parse_in);
116110d565efSmrg
116210d565efSmrg if (version_flag)
116310d565efSmrg {
116410d565efSmrg int i;
116510d565efSmrg fputs ("Compiler executable checksum: ", stderr);
116610d565efSmrg for (i = 0; i < 16; i++)
116710d565efSmrg fprintf (stderr, "%02x", executable_checksum[i]);
116810d565efSmrg putc ('\n', stderr);
116910d565efSmrg }
117010d565efSmrg
117110d565efSmrg /* Has to wait until now so that cpplib has its hash table. */
117210d565efSmrg init_pragma ();
117310d565efSmrg
117410d565efSmrg if (flag_preprocess_only)
117510d565efSmrg {
117610d565efSmrg c_finish_options ();
117710d565efSmrg preprocess_file (parse_in);
117810d565efSmrg return false;
117910d565efSmrg }
118010d565efSmrg
118110d565efSmrg return true;
118210d565efSmrg }
118310d565efSmrg
118410d565efSmrg /* Initialize the integrated preprocessor after debug output has been
118510d565efSmrg initialized; loop over each input file. */
118610d565efSmrg void
c_common_parse_file(void)118710d565efSmrg c_common_parse_file (void)
118810d565efSmrg {
118910d565efSmrg unsigned int i;
119010d565efSmrg
119110d565efSmrg i = 0;
119210d565efSmrg for (;;)
119310d565efSmrg {
119410d565efSmrg c_finish_options ();
1195c7a68eb7Smrg /* Open the dump file to use for the original dump output
119610d565efSmrg here, to be used during parsing for the current file. */
119710d565efSmrg original_dump_file = dump_begin (TDI_original, &original_dump_flags);
119810d565efSmrg pch_init ();
119910d565efSmrg push_file_scope ();
120010d565efSmrg c_parse_file ();
120110d565efSmrg pop_file_scope ();
120210d565efSmrg /* And end the main input file, if the debug writer wants it */
120310d565efSmrg if (debug_hooks->start_end_main_source_file)
120410d565efSmrg (*debug_hooks->end_source_file) (0);
120510d565efSmrg if (++i >= num_in_fnames)
120610d565efSmrg break;
120710d565efSmrg cpp_undef_all (parse_in);
120810d565efSmrg cpp_clear_file_cache (parse_in);
120910d565efSmrg this_input_filename
121010d565efSmrg = cpp_read_main_file (parse_in, in_fnames[i]);
121110d565efSmrg if (original_dump_file)
121210d565efSmrg {
121310d565efSmrg dump_end (TDI_original, original_dump_file);
121410d565efSmrg original_dump_file = NULL;
121510d565efSmrg }
121610d565efSmrg /* If an input file is missing, abandon further compilation.
121710d565efSmrg cpplib has issued a diagnostic. */
121810d565efSmrg if (!this_input_filename)
121910d565efSmrg break;
122010d565efSmrg }
122110d565efSmrg
122210d565efSmrg c_parse_final_cleanups ();
122310d565efSmrg }
122410d565efSmrg
122510d565efSmrg /* Returns the appropriate dump file for PHASE to dump with FLAGS. */
1226c7a68eb7Smrg
122710d565efSmrg FILE *
get_dump_info(int phase,dump_flags_t * flags)1228c7a68eb7Smrg get_dump_info (int phase, dump_flags_t *flags)
122910d565efSmrg {
1230c7a68eb7Smrg gcc_assert (phase == TDI_original);
1231c7a68eb7Smrg
123210d565efSmrg *flags = original_dump_flags;
123310d565efSmrg return original_dump_file;
123410d565efSmrg }
123510d565efSmrg
123610d565efSmrg /* Common finish hook for the C, ObjC and C++ front ends. */
123710d565efSmrg void
c_common_finish(void)123810d565efSmrg c_common_finish (void)
123910d565efSmrg {
124010d565efSmrg FILE *deps_stream = NULL;
124110d565efSmrg
1242c7a68eb7Smrg /* Note that we write the dependencies even if there are errors. This is
1243c7a68eb7Smrg useful for handling outdated generated headers that now trigger errors
1244c7a68eb7Smrg (for example, with #error) which would be resolved by re-generating
1245c7a68eb7Smrg them. In a sense, this complements -MG. */
1246c7a68eb7Smrg if (cpp_opts->deps.style != DEPS_NONE)
124710d565efSmrg {
124810d565efSmrg /* If -M or -MM was seen without -MF, default output to the
124910d565efSmrg output stream. */
125010d565efSmrg if (!deps_file)
125110d565efSmrg deps_stream = out_stream;
1252c7a68eb7Smrg else if (deps_file[0] == '-' && deps_file[1] == '\0')
1253c7a68eb7Smrg deps_stream = stdout;
125410d565efSmrg else
125510d565efSmrg {
125610d565efSmrg deps_stream = fopen (deps_file, deps_append ? "a": "w");
125710d565efSmrg if (!deps_stream)
125810d565efSmrg fatal_error (input_location, "opening dependency file %s: %m",
125910d565efSmrg deps_file);
126010d565efSmrg }
126110d565efSmrg }
126210d565efSmrg
126310d565efSmrg /* For performance, avoid tearing down cpplib's internal structures
126410d565efSmrg with cpp_destroy (). */
126510d565efSmrg cpp_finish (parse_in, deps_stream);
126610d565efSmrg
1267c7a68eb7Smrg if (deps_stream && deps_stream != out_stream && deps_stream != stdout
126810d565efSmrg && (ferror (deps_stream) || fclose (deps_stream)))
126910d565efSmrg fatal_error (input_location, "closing dependency file %s: %m", deps_file);
127010d565efSmrg
127110d565efSmrg if (out_stream && (ferror (out_stream) || fclose (out_stream)))
127210d565efSmrg fatal_error (input_location, "when writing output to %s: %m", out_fname);
127310d565efSmrg }
127410d565efSmrg
127510d565efSmrg /* Either of two environment variables can specify output of
127610d565efSmrg dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
127710d565efSmrg DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
127810d565efSmrg and DEPS_TARGET is the target to mention in the deps. They also
127910d565efSmrg result in dependency information being appended to the output file
128010d565efSmrg rather than overwriting it, and like Sun's compiler
128110d565efSmrg SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
128210d565efSmrg static void
check_deps_environment_vars(void)128310d565efSmrg check_deps_environment_vars (void)
128410d565efSmrg {
128510d565efSmrg char *spec;
128610d565efSmrg
128710d565efSmrg spec = getenv ("DEPENDENCIES_OUTPUT");
128810d565efSmrg if (spec)
128910d565efSmrg cpp_opts->deps.style = DEPS_USER;
129010d565efSmrg else
129110d565efSmrg {
129210d565efSmrg spec = getenv ("SUNPRO_DEPENDENCIES");
129310d565efSmrg if (spec)
129410d565efSmrg {
129510d565efSmrg cpp_opts->deps.style = DEPS_SYSTEM;
129610d565efSmrg cpp_opts->deps.ignore_main_file = true;
129710d565efSmrg }
129810d565efSmrg }
129910d565efSmrg
130010d565efSmrg if (spec)
130110d565efSmrg {
130210d565efSmrg /* Find the space before the DEPS_TARGET, if there is one. */
130310d565efSmrg char *s = strchr (spec, ' ');
130410d565efSmrg if (s)
130510d565efSmrg {
130610d565efSmrg /* Let the caller perform MAKE quoting. */
130710d565efSmrg defer_opt (OPT_MT, s + 1);
130810d565efSmrg *s = '\0';
130910d565efSmrg }
131010d565efSmrg
131110d565efSmrg /* Command line -MF overrides environment variables and default. */
131210d565efSmrg if (!deps_file)
131310d565efSmrg deps_file = spec;
131410d565efSmrg
131510d565efSmrg deps_append = 1;
131610d565efSmrg deps_seen = true;
131710d565efSmrg }
131810d565efSmrg }
131910d565efSmrg
132010d565efSmrg /* Handle deferred command line switches. */
132110d565efSmrg static void
handle_deferred_opts(void)132210d565efSmrg handle_deferred_opts (void)
132310d565efSmrg {
132410d565efSmrg /* Avoid allocating the deps buffer if we don't need it.
132510d565efSmrg (This flag may be true without there having been -MT or -MQ
132610d565efSmrg options, but we'll still need the deps buffer.) */
132710d565efSmrg if (!deps_seen)
132810d565efSmrg return;
132910d565efSmrg
1330*ec02198aSmrg mkdeps *deps = cpp_get_deps (parse_in);
133110d565efSmrg
1332*ec02198aSmrg for (size_t i = 0; i < deferred_count; i++)
133310d565efSmrg {
133410d565efSmrg struct deferred_opt *opt = &deferred_opts[i];
133510d565efSmrg
133610d565efSmrg if (opt->code == OPT_MT || opt->code == OPT_MQ)
133710d565efSmrg deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
133810d565efSmrg }
133910d565efSmrg }
134010d565efSmrg
134110d565efSmrg /* These settings are appropriate for GCC, but not necessarily so for
134210d565efSmrg cpplib as a library. */
134310d565efSmrg static void
sanitize_cpp_opts(void)134410d565efSmrg sanitize_cpp_opts (void)
134510d565efSmrg {
134610d565efSmrg /* If we don't know what style of dependencies to output, complain
134710d565efSmrg if any other dependency switches have been given. */
134810d565efSmrg if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
13490fc04c29Smrg error ("to generate dependencies you must specify either %<-M%> "
13500fc04c29Smrg "or %<-MM%>");
135110d565efSmrg
135210d565efSmrg /* -dM and dependencies suppress normal output; do it here so that
135310d565efSmrg the last -d[MDN] switch overrides earlier ones. */
135410d565efSmrg if (flag_dump_macros == 'M')
135510d565efSmrg flag_no_output = 1;
135610d565efSmrg
135710d565efSmrg /* By default, -fdirectives-only implies -dD. This allows subsequent phases
135810d565efSmrg to perform proper macro expansion. */
135910d565efSmrg if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
136010d565efSmrg flag_dump_macros = 'D';
136110d565efSmrg
136210d565efSmrg /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
136310d565efSmrg -dM since at least glibc relies on -M -dM to work. */
136410d565efSmrg /* Also, flag_no_output implies flag_no_line_commands, always. */
136510d565efSmrg if (flag_no_output)
136610d565efSmrg {
136710d565efSmrg if (flag_dump_macros != 'M')
136810d565efSmrg flag_dump_macros = 0;
136910d565efSmrg flag_dump_includes = 0;
137010d565efSmrg flag_no_line_commands = 1;
137110d565efSmrg }
137210d565efSmrg else if (cpp_opts->deps.missing_files)
13730fc04c29Smrg error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
137410d565efSmrg
137510d565efSmrg cpp_opts->unsigned_char = !flag_signed_char;
137610d565efSmrg cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
137710d565efSmrg
137810d565efSmrg /* Wlong-long is disabled by default. It is enabled by:
137910d565efSmrg [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
138010d565efSmrg [-Wpedantic | -Wtraditional] -std=non-c99
138110d565efSmrg
138210d565efSmrg Either -Wlong-long or -Wno-long-long override any other settings.
138310d565efSmrg ??? These conditions should be handled in c.opt. */
138410d565efSmrg if (warn_long_long == -1)
138510d565efSmrg {
138610d565efSmrg warn_long_long = ((pedantic || warn_traditional)
138710d565efSmrg && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
138810d565efSmrg cpp_opts->cpp_warn_long_long = warn_long_long;
138910d565efSmrg }
139010d565efSmrg
139110d565efSmrg /* If we're generating preprocessor output, emit current directory
139210d565efSmrg if explicitly requested or if debugging information is enabled.
139310d565efSmrg ??? Maybe we should only do it for debugging formats that
139410d565efSmrg actually output the current directory? */
139510d565efSmrg if (flag_working_directory == -1)
139610d565efSmrg flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
139710d565efSmrg
139810d565efSmrg if (warn_implicit_fallthrough < 5)
139910d565efSmrg cpp_opts->cpp_warn_implicit_fallthrough = warn_implicit_fallthrough;
140010d565efSmrg else
140110d565efSmrg cpp_opts->cpp_warn_implicit_fallthrough = 0;
140210d565efSmrg
140310d565efSmrg if (cpp_opts->directives_only)
140410d565efSmrg {
140510d565efSmrg if (cpp_warn_unused_macros)
14060fc04c29Smrg error ("%<-fdirectives-only%> is incompatible "
14070fc04c29Smrg "with %<-Wunused-macros%>");
140810d565efSmrg if (cpp_opts->traditional)
14090fc04c29Smrg error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
141010d565efSmrg }
141110d565efSmrg }
141210d565efSmrg
141310d565efSmrg /* Add include path with a prefix at the front of its name. */
141410d565efSmrg static void
add_prefixed_path(const char * suffix,incpath_kind chain)1415c7a68eb7Smrg add_prefixed_path (const char *suffix, incpath_kind chain)
141610d565efSmrg {
141710d565efSmrg char *path;
141810d565efSmrg const char *prefix;
141910d565efSmrg size_t prefix_len, suffix_len;
142010d565efSmrg
142110d565efSmrg suffix_len = strlen (suffix);
142210d565efSmrg prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
142310d565efSmrg prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
142410d565efSmrg
142510d565efSmrg path = (char *) xmalloc (prefix_len + suffix_len + 1);
142610d565efSmrg memcpy (path, prefix, prefix_len);
142710d565efSmrg memcpy (path + prefix_len, suffix, suffix_len);
142810d565efSmrg path[prefix_len + suffix_len] = '\0';
142910d565efSmrg
143010d565efSmrg add_path (path, chain, 0, false);
143110d565efSmrg }
143210d565efSmrg
143310d565efSmrg /* Handle -D, -U, -A, -imacros, and the first -include. */
143410d565efSmrg static void
c_finish_options(void)143510d565efSmrg c_finish_options (void)
143610d565efSmrg {
143710d565efSmrg if (!cpp_opts->preprocessed)
143810d565efSmrg {
14390fc04c29Smrg const line_map_ordinary *bltin_map
14400fc04c29Smrg = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
14410fc04c29Smrg _("<built-in>"), 0));
14420fc04c29Smrg cb_file_change (parse_in, bltin_map);
144310d565efSmrg
144410d565efSmrg /* Make sure all of the builtins about to be declared have
14450fc04c29Smrg BUILTINS_LOCATION has their location_t. */
14460fc04c29Smrg cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
144710d565efSmrg
144810d565efSmrg cpp_init_builtins (parse_in, flag_hosted);
144910d565efSmrg c_cpp_builtins (parse_in);
145010d565efSmrg
145110d565efSmrg /* We're about to send user input to cpplib, so make it warn for
145210d565efSmrg things that we previously (when we sent it internal definitions)
145310d565efSmrg told it to not warn.
145410d565efSmrg
145510d565efSmrg C99 permits implementation-defined characters in identifiers.
145610d565efSmrg The documented meaning of -std= is to turn off extensions that
145710d565efSmrg conflict with the specified standard, and since a strictly
145810d565efSmrg conforming program cannot contain a '$', we do not condition
145910d565efSmrg their acceptance on the -std= setting. */
146010d565efSmrg cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
146110d565efSmrg
14620fc04c29Smrg const line_map_ordinary *cmd_map
14630fc04c29Smrg = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
14640fc04c29Smrg _("<command-line>"), 0));
14650fc04c29Smrg cb_file_change (parse_in, cmd_map);
146610d565efSmrg
14670fc04c29Smrg /* All command line defines must have the same location. */
14680fc04c29Smrg cpp_force_token_locations (parse_in, cmd_map->start_location);
14690fc04c29Smrg for (size_t i = 0; i < deferred_count; i++)
147010d565efSmrg {
147110d565efSmrg struct deferred_opt *opt = &deferred_opts[i];
147210d565efSmrg
147310d565efSmrg if (opt->code == OPT_D)
147410d565efSmrg cpp_define (parse_in, opt->arg);
147510d565efSmrg else if (opt->code == OPT_U)
147610d565efSmrg cpp_undef (parse_in, opt->arg);
147710d565efSmrg else if (opt->code == OPT_A)
147810d565efSmrg {
147910d565efSmrg if (opt->arg[0] == '-')
148010d565efSmrg cpp_unassert (parse_in, opt->arg + 1);
148110d565efSmrg else
148210d565efSmrg cpp_assert (parse_in, opt->arg);
148310d565efSmrg }
148410d565efSmrg }
148510d565efSmrg
14860fc04c29Smrg cpp_stop_forcing_token_locations (parse_in);
14870fc04c29Smrg }
14880fc04c29Smrg else if (cpp_opts->directives_only)
14890fc04c29Smrg cpp_init_special_builtins (parse_in);
14900fc04c29Smrg
149110d565efSmrg /* Start the main input file, if the debug writer wants it. */
149210d565efSmrg if (debug_hooks->start_end_main_source_file
149310d565efSmrg && !flag_preprocess_only)
149410d565efSmrg (*debug_hooks->start_source_file) (0, this_input_filename);
149510d565efSmrg
14960fc04c29Smrg if (!cpp_opts->preprocessed)
149710d565efSmrg /* Handle -imacros after -D and -U. */
14980fc04c29Smrg for (size_t i = 0; i < deferred_count; i++)
149910d565efSmrg {
150010d565efSmrg struct deferred_opt *opt = &deferred_opts[i];
150110d565efSmrg
150210d565efSmrg if (opt->code == OPT_imacros
150310d565efSmrg && cpp_push_include (parse_in, opt->arg))
150410d565efSmrg {
150510d565efSmrg /* Disable push_command_line_include callback for now. */
150610d565efSmrg include_cursor = deferred_count + 1;
150710d565efSmrg cpp_scan_nooutput (parse_in);
150810d565efSmrg }
150910d565efSmrg }
151010d565efSmrg
151110d565efSmrg include_cursor = 0;
151210d565efSmrg push_command_line_include ();
151310d565efSmrg }
151410d565efSmrg
151510d565efSmrg /* Give CPP the next file given by -include, if any. */
151610d565efSmrg static void
push_command_line_include(void)151710d565efSmrg push_command_line_include (void)
151810d565efSmrg {
151910d565efSmrg /* This can happen if disabled by -imacros for example.
152010d565efSmrg Punt so that we don't set "<command-line>" as the filename for
152110d565efSmrg the header. */
152210d565efSmrg if (include_cursor > deferred_count)
152310d565efSmrg return;
152410d565efSmrg
152510d565efSmrg if (!done_preinclude)
152610d565efSmrg {
152710d565efSmrg done_preinclude = true;
152810d565efSmrg if (flag_hosted && std_inc && !cpp_opts->preprocessed)
152910d565efSmrg {
153010d565efSmrg const char *preinc = targetcm.c_preinclude ();
153110d565efSmrg if (preinc && cpp_push_default_include (parse_in, preinc))
153210d565efSmrg return;
153310d565efSmrg }
153410d565efSmrg }
153510d565efSmrg
153610d565efSmrg pch_cpp_save_state ();
153710d565efSmrg
153810d565efSmrg while (include_cursor < deferred_count)
153910d565efSmrg {
154010d565efSmrg struct deferred_opt *opt = &deferred_opts[include_cursor++];
154110d565efSmrg
154210d565efSmrg if (!cpp_opts->preprocessed && opt->code == OPT_include
154310d565efSmrg && cpp_push_include (parse_in, opt->arg))
154410d565efSmrg return;
154510d565efSmrg }
154610d565efSmrg
154710d565efSmrg if (include_cursor == deferred_count)
154810d565efSmrg {
154910d565efSmrg include_cursor++;
155010d565efSmrg /* -Wunused-macros should only warn about macros defined hereafter. */
155110d565efSmrg cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
15520fc04c29Smrg /* Restore the line map back to the main file. */
155310d565efSmrg if (!cpp_opts->preprocessed)
155410d565efSmrg cpp_change_file (parse_in, LC_RENAME, this_input_filename);
155510d565efSmrg
155610d565efSmrg /* Set this here so the client can change the option if it wishes,
155710d565efSmrg and after stacking the main file so we don't trace the main file. */
155810d565efSmrg line_table->trace_includes = cpp_opts->print_include_names;
155910d565efSmrg }
156010d565efSmrg }
156110d565efSmrg
156210d565efSmrg /* File change callback. Has to handle -include files. */
156310d565efSmrg static void
cb_file_change(cpp_reader * ARG_UNUSED (pfile),const line_map_ordinary * new_map)156410d565efSmrg cb_file_change (cpp_reader * ARG_UNUSED (pfile),
156510d565efSmrg const line_map_ordinary *new_map)
156610d565efSmrg {
156710d565efSmrg if (flag_preprocess_only)
156810d565efSmrg pp_file_change (new_map);
156910d565efSmrg else
157010d565efSmrg fe_file_change (new_map);
157110d565efSmrg
157210d565efSmrg if (new_map
157310d565efSmrg && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
157410d565efSmrg {
157510d565efSmrg /* Signal to plugins that a file is included. This could happen
157610d565efSmrg several times with the same file path, e.g. because of
157710d565efSmrg several '#include' or '#line' directives... */
157810d565efSmrg invoke_plugin_callbacks
157910d565efSmrg (PLUGIN_INCLUDE_FILE,
158010d565efSmrg const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
158110d565efSmrg }
158210d565efSmrg
158310d565efSmrg if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
158410d565efSmrg {
158510d565efSmrg pch_cpp_save_state ();
158610d565efSmrg push_command_line_include ();
158710d565efSmrg }
158810d565efSmrg }
158910d565efSmrg
159010d565efSmrg void
cb_dir_change(cpp_reader * ARG_UNUSED (pfile),const char * dir)159110d565efSmrg cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
159210d565efSmrg {
159310d565efSmrg if (!set_src_pwd (dir))
159410d565efSmrg warning (0, "too late for # directive to set debug directory");
159510d565efSmrg }
159610d565efSmrg
159710d565efSmrg /* Set the C 89 standard (with 1994 amendments if C94, without GNU
159810d565efSmrg extensions if ISO). There is no concept of gnu94. */
159910d565efSmrg static void
set_std_c89(int c94,int iso)160010d565efSmrg set_std_c89 (int c94, int iso)
160110d565efSmrg {
160210d565efSmrg cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
160310d565efSmrg flag_iso = iso;
160410d565efSmrg flag_no_asm = iso;
160510d565efSmrg flag_no_gnu_keywords = iso;
160610d565efSmrg flag_no_nonansi_builtin = iso;
160710d565efSmrg flag_isoc94 = c94;
160810d565efSmrg flag_isoc99 = 0;
160910d565efSmrg flag_isoc11 = 0;
16100fc04c29Smrg flag_isoc2x = 0;
161110d565efSmrg lang_hooks.name = "GNU C89";
161210d565efSmrg }
161310d565efSmrg
161410d565efSmrg /* Set the C 99 standard (without GNU extensions if ISO). */
161510d565efSmrg static void
set_std_c99(int iso)161610d565efSmrg set_std_c99 (int iso)
161710d565efSmrg {
161810d565efSmrg cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
161910d565efSmrg flag_no_asm = iso;
162010d565efSmrg flag_no_nonansi_builtin = iso;
162110d565efSmrg flag_iso = iso;
16220fc04c29Smrg flag_isoc2x = 0;
162310d565efSmrg flag_isoc11 = 0;
162410d565efSmrg flag_isoc99 = 1;
162510d565efSmrg flag_isoc94 = 1;
162610d565efSmrg lang_hooks.name = "GNU C99";
162710d565efSmrg }
162810d565efSmrg
162910d565efSmrg /* Set the C 11 standard (without GNU extensions if ISO). */
163010d565efSmrg static void
set_std_c11(int iso)163110d565efSmrg set_std_c11 (int iso)
163210d565efSmrg {
163310d565efSmrg cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
163410d565efSmrg flag_no_asm = iso;
163510d565efSmrg flag_no_nonansi_builtin = iso;
163610d565efSmrg flag_iso = iso;
16370fc04c29Smrg flag_isoc2x = 0;
163810d565efSmrg flag_isoc11 = 1;
163910d565efSmrg flag_isoc99 = 1;
164010d565efSmrg flag_isoc94 = 1;
164110d565efSmrg lang_hooks.name = "GNU C11";
164210d565efSmrg }
164310d565efSmrg
1644c7a68eb7Smrg /* Set the C 17 standard (without GNU extensions if ISO). */
1645c7a68eb7Smrg static void
set_std_c17(int iso)1646c7a68eb7Smrg set_std_c17 (int iso)
1647c7a68eb7Smrg {
1648c7a68eb7Smrg cpp_set_lang (parse_in, iso ? CLK_STDC17: CLK_GNUC17);
1649c7a68eb7Smrg flag_no_asm = iso;
1650c7a68eb7Smrg flag_no_nonansi_builtin = iso;
1651c7a68eb7Smrg flag_iso = iso;
16520fc04c29Smrg flag_isoc2x = 0;
1653c7a68eb7Smrg flag_isoc11 = 1;
1654c7a68eb7Smrg flag_isoc99 = 1;
1655c7a68eb7Smrg flag_isoc94 = 1;
1656c7a68eb7Smrg lang_hooks.name = "GNU C17";
1657c7a68eb7Smrg }
1658c7a68eb7Smrg
16590fc04c29Smrg /* Set the C 2X standard (without GNU extensions if ISO). */
16600fc04c29Smrg static void
set_std_c2x(int iso)16610fc04c29Smrg set_std_c2x (int iso)
16620fc04c29Smrg {
16630fc04c29Smrg cpp_set_lang (parse_in, iso ? CLK_STDC2X: CLK_GNUC2X);
16640fc04c29Smrg flag_no_asm = iso;
16650fc04c29Smrg flag_no_nonansi_builtin = iso;
16660fc04c29Smrg flag_iso = iso;
16670fc04c29Smrg flag_isoc2x = 1;
16680fc04c29Smrg flag_isoc11 = 1;
16690fc04c29Smrg flag_isoc99 = 1;
16700fc04c29Smrg flag_isoc94 = 1;
16710fc04c29Smrg lang_hooks.name = "GNU C2X";
16720fc04c29Smrg }
16730fc04c29Smrg
1674c7a68eb7Smrg
167510d565efSmrg /* Set the C++ 98 standard (without GNU extensions if ISO). */
167610d565efSmrg static void
set_std_cxx98(int iso)167710d565efSmrg set_std_cxx98 (int iso)
167810d565efSmrg {
167910d565efSmrg cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
168010d565efSmrg flag_no_gnu_keywords = iso;
168110d565efSmrg flag_no_nonansi_builtin = iso;
168210d565efSmrg flag_iso = iso;
168310d565efSmrg flag_isoc94 = 0;
168410d565efSmrg flag_isoc99 = 0;
168510d565efSmrg cxx_dialect = cxx98;
168610d565efSmrg lang_hooks.name = "GNU C++98";
168710d565efSmrg }
168810d565efSmrg
168910d565efSmrg /* Set the C++ 2011 standard (without GNU extensions if ISO). */
169010d565efSmrg static void
set_std_cxx11(int iso)169110d565efSmrg set_std_cxx11 (int iso)
169210d565efSmrg {
169310d565efSmrg cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
169410d565efSmrg flag_no_gnu_keywords = iso;
169510d565efSmrg flag_no_nonansi_builtin = iso;
169610d565efSmrg flag_iso = iso;
169710d565efSmrg /* C++11 includes the C99 standard library. */
169810d565efSmrg flag_isoc94 = 1;
169910d565efSmrg flag_isoc99 = 1;
170010d565efSmrg cxx_dialect = cxx11;
170110d565efSmrg lang_hooks.name = "GNU C++11";
170210d565efSmrg }
170310d565efSmrg
1704c7a68eb7Smrg /* Set the C++ 2014 standard (without GNU extensions if ISO). */
170510d565efSmrg static void
set_std_cxx14(int iso)170610d565efSmrg set_std_cxx14 (int iso)
170710d565efSmrg {
170810d565efSmrg cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14);
170910d565efSmrg flag_no_gnu_keywords = iso;
171010d565efSmrg flag_no_nonansi_builtin = iso;
171110d565efSmrg flag_iso = iso;
1712c7a68eb7Smrg /* C++14 includes the C99 standard library. */
171310d565efSmrg flag_isoc94 = 1;
171410d565efSmrg flag_isoc99 = 1;
171510d565efSmrg cxx_dialect = cxx14;
171610d565efSmrg lang_hooks.name = "GNU C++14";
171710d565efSmrg }
171810d565efSmrg
1719c7a68eb7Smrg /* Set the C++ 2017 standard (without GNU extensions if ISO). */
172010d565efSmrg static void
set_std_cxx17(int iso)1721c7a68eb7Smrg set_std_cxx17 (int iso)
172210d565efSmrg {
1723c7a68eb7Smrg cpp_set_lang (parse_in, iso ? CLK_CXX17: CLK_GNUCXX17);
172410d565efSmrg flag_no_gnu_keywords = iso;
172510d565efSmrg flag_no_nonansi_builtin = iso;
172610d565efSmrg flag_iso = iso;
1727c7a68eb7Smrg /* C++17 includes the C11 standard library. */
172810d565efSmrg flag_isoc94 = 1;
172910d565efSmrg flag_isoc99 = 1;
173010d565efSmrg flag_isoc11 = 1;
1731c7a68eb7Smrg cxx_dialect = cxx17;
1732c7a68eb7Smrg lang_hooks.name = "GNU C++17";
1733c7a68eb7Smrg }
1734c7a68eb7Smrg
1735c7a68eb7Smrg /* Set the C++ 202a draft standard (without GNU extensions if ISO). */
1736c7a68eb7Smrg static void
set_std_cxx2a(int iso)1737c7a68eb7Smrg set_std_cxx2a (int iso)
1738c7a68eb7Smrg {
1739c7a68eb7Smrg cpp_set_lang (parse_in, iso ? CLK_CXX2A: CLK_GNUCXX2A);
1740c7a68eb7Smrg flag_no_gnu_keywords = iso;
1741c7a68eb7Smrg flag_no_nonansi_builtin = iso;
1742c7a68eb7Smrg flag_iso = iso;
1743c7a68eb7Smrg /* C++17 includes the C11 standard library. */
1744c7a68eb7Smrg flag_isoc94 = 1;
1745c7a68eb7Smrg flag_isoc99 = 1;
1746c7a68eb7Smrg flag_isoc11 = 1;
1747*ec02198aSmrg /* C++2a includes concepts. */
1748c7a68eb7Smrg cxx_dialect = cxx2a;
1749c7a68eb7Smrg lang_hooks.name = "GNU C++17"; /* Pretend C++17 until standardization. */
175010d565efSmrg }
175110d565efSmrg
175210d565efSmrg /* Args to -d specify what to dump. Silently ignore
175310d565efSmrg unrecognized options; they may be aimed at toplev.c. */
175410d565efSmrg static void
handle_OPT_d(const char * arg)175510d565efSmrg handle_OPT_d (const char *arg)
175610d565efSmrg {
175710d565efSmrg char c;
175810d565efSmrg
175910d565efSmrg while ((c = *arg++) != '\0')
176010d565efSmrg switch (c)
176110d565efSmrg {
176210d565efSmrg case 'M': /* Dump macros only. */
176310d565efSmrg case 'N': /* Dump names. */
176410d565efSmrg case 'D': /* Dump definitions. */
176510d565efSmrg case 'U': /* Dump used macros. */
176610d565efSmrg flag_dump_macros = c;
176710d565efSmrg break;
176810d565efSmrg
176910d565efSmrg case 'I':
177010d565efSmrg flag_dump_includes = 1;
177110d565efSmrg break;
177210d565efSmrg }
177310d565efSmrg }
1774