1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002-2023 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
28 #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
29 #include "diagnostic.h"
33 #include "langhooks.h"
34 #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
36 #include "cppdefault.h"
38 #include "debug.h" /* For debug_hooks. */
40 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
43 #include "file-prefix-map.h" /* add_*_prefix_map() */
46 #ifndef DOLLARS_IN_IDENTIFIERS
47 # define DOLLARS_IN_IDENTIFIERS true
50 #ifndef TARGET_SYSTEM_ROOT
51 # define TARGET_SYSTEM_ROOT NULL
55 #define TARGET_OPTF(ARG)
59 cpp_options
*cpp_opts
;
62 static const char *this_input_filename
;
64 /* Filename and stream for preprocessed output. */
65 static const char *out_fname
;
66 static FILE *out_stream
;
68 /* Append dependencies to deps_file. */
69 static bool deps_append
;
71 /* If dependency switches (-MF etc.) have been given. */
72 static bool deps_seen
;
77 /* Dependency output file. */
78 static const char *deps_file
;
80 /* Structured dependency output file. */
81 static const char *fdeps_file
;
83 /* The prefix given by -iprefix, if any. */
84 static const char *iprefix
;
86 /* The multilib directory given by -imultilib, if any. */
87 static const char *imultilib
;
89 /* The system root, if any. Overridden by -isysroot. */
90 static const char *sysroot
= TARGET_SYSTEM_ROOT
;
92 /* Zero disables all standard directories for headers. */
93 static bool std_inc
= true;
95 /* Zero disables the C++-specific standard directories for headers. */
96 static bool std_cxx_inc
= true;
98 /* If the quote chain has been split by -I-. */
99 static bool quote_chain_split
;
101 /* Number of deferred options. */
102 static size_t deferred_count
;
104 /* Number of deferred options scanned for -include. */
105 static size_t include_cursor
;
107 /* Whether any standard preincluded header has been preincluded. */
108 static bool done_preinclude
;
110 static void handle_OPT_d (const char *);
111 static void set_std_cxx98 (int);
112 static void set_std_cxx11 (int);
113 static void set_std_cxx14 (int);
114 static void set_std_cxx17 (int);
115 static void set_std_cxx20 (int);
116 static void set_std_cxx23 (int);
117 static void set_std_cxx26 (int);
118 static void set_std_c89 (int, int);
119 static void set_std_c99 (int);
120 static void set_std_c11 (int);
121 static void set_std_c17 (int);
122 static void set_std_c23 (int);
123 static void check_deps_environment_vars (void);
124 static void handle_deferred_opts (void);
125 static void sanitize_cpp_opts (void);
126 static void add_prefixed_path (const char *, incpath_kind
);
127 static void push_command_line_include (void);
128 static void cb_file_change (cpp_reader
*, const line_map_ordinary
*);
129 static void cb_dir_change (cpp_reader
*, const char *);
130 static void c_finish_options (void);
132 #ifndef STDC_0_IN_SYSTEM_HEADERS
133 #define STDC_0_IN_SYSTEM_HEADERS 0
136 /* Holds switches parsed by c_common_handle_option (), but whose
137 handling is deferred to c_common_post_options (). */
138 static void defer_opt (enum opt_code
, const char *);
139 static struct deferred_opt
146 extern const unsigned int
147 c_family_lang_mask
= (CL_C
| CL_CXX
| CL_ObjC
| CL_ObjCXX
);
149 /* Defer option CODE with argument ARG. */
151 defer_opt (enum opt_code code
, const char *arg
)
153 deferred_opts
[deferred_count
].code
= code
;
154 deferred_opts
[deferred_count
].arg
= arg
;
158 /* Return language mask for option parsing. */
160 c_common_option_lang_mask (void)
162 static const unsigned int lang_flags
[] = {CL_C
, CL_ObjC
, CL_CXX
, CL_ObjCXX
};
164 return lang_flags
[c_language
];
167 /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
169 c_diagnostic_finalizer (diagnostic_context
*context
,
170 diagnostic_info
*diagnostic
,
173 char *saved_prefix
= pp_take_prefix (context
->printer
);
174 pp_set_prefix (context
->printer
, NULL
);
175 pp_newline (context
->printer
);
176 diagnostic_show_locus (context
, diagnostic
->richloc
, diagnostic
->kind
);
177 /* By default print macro expansion contexts in the diagnostic
178 finalizer -- for tokens resulting from macro expansion. */
179 virt_loc_aware_diagnostic_finalizer (context
, diagnostic
);
180 pp_set_prefix (context
->printer
, saved_prefix
);
181 pp_flush (context
->printer
);
184 /* Common default settings for diagnostics. */
186 c_common_diagnostics_set_defaults (diagnostic_context
*context
)
188 diagnostic_finalizer (context
) = c_diagnostic_finalizer
;
189 context
->m_opt_permissive
= OPT_fpermissive
;
192 /* Input charset configuration for diagnostics. */
194 c_common_input_charset_cb (const char * /*filename*/)
196 const char *cs
= cpp_opts
->input_charset
;
197 return cpp_input_conversion_is_trivial (cs
) ? nullptr : cs
;
200 /* Whether options from all C-family languages should be accepted
202 static bool accept_all_c_family_options
= false;
204 /* Return whether to complain about a wrong-language option. */
206 c_common_complain_wrong_lang_p (const struct cl_option
*option
)
208 if (accept_all_c_family_options
209 && (option
->flags
& c_family_lang_mask
))
215 /* Initialize options structure OPTS. */
217 c_common_init_options_struct (struct gcc_options
*opts
)
219 opts
->x_flag_exceptions
= c_dialect_cxx ();
220 opts
->x_warn_pointer_arith
= c_dialect_cxx ();
221 opts
->x_warn_write_strings
= c_dialect_cxx ();
222 opts
->x_flag_warn_unused_result
= true;
224 /* By default, C99-like requirements for complex multiply and divide. */
225 opts
->x_flag_complex_method
= 2;
226 opts
->x_flag_default_complex_method
= opts
->x_flag_complex_method
;
229 /* Common initialization before calling option handlers. */
231 c_common_init_options (unsigned int decoded_options_count
,
232 struct cl_decoded_option
*decoded_options
)
235 struct cpp_callbacks
*cb
;
238 = new (ggc_alloc
<string_concat_db
> ()) string_concat_db ();
240 parse_in
= cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX
: CLK_GNUC89
,
241 ident_hash
, line_table
, ident_hash_extra
);
242 cb
= cpp_get_callbacks (parse_in
);
243 cb
->diagnostic
= c_cpp_diagnostic
;
245 cpp_opts
= cpp_get_options (parse_in
);
246 cpp_opts
->dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
247 cpp_opts
->objc
= c_dialect_objc ();
248 cpp_opts
->deps
.modules
= true;
250 /* Reset to avoid warnings on internal definitions. We set it just
251 before passing on command-line options to cpplib. */
252 cpp_opts
->warn_dollars
= 0;
254 deferred_opts
= XNEWVEC (struct deferred_opt
, decoded_options_count
);
256 if (c_language
== clk_c
)
258 /* The default for C is gnu17. */
259 set_std_c17 (false /* ISO */);
261 /* If preprocessing assembly language, accept any of the C-family
262 front end options since the driver may pass them through. */
263 for (i
= 1; i
< decoded_options_count
; i
++)
264 if (decoded_options
[i
].opt_index
== OPT_lang_asm
)
266 accept_all_c_family_options
= true;
271 /* Set C++ standard to C++17 if not specified on the command line. */
272 if (c_dialect_cxx ())
273 set_std_cxx17 (/*ISO*/false);
275 global_dc
->m_source_printing
.colorize_source_p
= true;
278 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
279 form of an -f or -W option was given. Returns false if the switch was
280 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
282 c_common_handle_option (size_t scode
, const char *arg
, HOST_WIDE_INT value
,
283 int kind
, location_t loc
,
284 const struct cl_option_handlers
*handlers
)
286 const struct cl_option
*option
= &cl_options
[scode
];
287 enum opt_code code
= (enum opt_code
) scode
;
290 /* Prevent resetting the language standard to a C dialect when the driver
291 has already determined that we're looking at assembler input. */
292 bool preprocessing_asm_p
= (cpp_get_options (parse_in
)->lang
== CLK_ASM
);
297 if (cl_options
[code
].flags
& c_family_lang_mask
)
299 if ((option
->flags
& CL_TARGET
)
300 && ! targetcm
.handle_c_option (scode
, arg
, value
))
307 case OPT__output_pch
:
312 defer_opt (code
, arg
);
316 cpp_opts
->discard_comments
= 0;
320 cpp_opts
->discard_comments
= 0;
321 cpp_opts
->discard_comments_in_macro_exp
= 0;
325 defer_opt (code
, arg
);
329 cpp_opts
->print_include_names
= 1;
333 TARGET_OPTF (xstrdup (arg
));
337 if (strcmp (arg
, "-"))
338 add_path (xstrdup (arg
), INC_BRACKET
, 0, true);
341 if (quote_chain_split
)
342 error ("%<-I-%> specified twice");
343 quote_chain_split
= true;
344 split_quote_chain ();
345 inform (input_location
, "obsolete option %<-I-%> used, "
346 "please use %<-iquote%> instead");
352 /* When doing dependencies with -M or -MM, suppress normal
353 preprocessed output, but still do -dM etc. as software
354 depends on this. Preprocessed output does occur if -MD, -MMD
355 or environment var dependency generation is used. */
356 cpp_opts
->deps
.style
= (code
== OPT_M
? DEPS_SYSTEM
: DEPS_USER
);
362 cpp_opts
->deps
.style
= (code
== OPT_MD
? DEPS_SYSTEM
: DEPS_USER
);
363 cpp_opts
->deps
.need_preprocessor_output
= true;
367 case OPT_fdeps_format_
:
368 /* https://wg21.link/p1689r5 */
369 if (!strcmp (arg
, "p1689r5"))
370 cpp_opts
->deps
.fdeps_format
= FDEPS_FMT_P1689R5
;
372 error ("%<-fdeps-format=%> unknown format %<%s%>", arg
);
375 case OPT_fdeps_file_
:
380 case OPT_fdeps_target_
:
382 defer_opt (code
, arg
);
392 cpp_opts
->deps
.missing_files
= true;
397 cpp_opts
->deps
.phony_targets
= true;
401 /* Do not set deps_seen, so the user can unconditionally turn
403 cpp_opts
->deps
.modules
= true;
406 case OPT_Mno_modules
:
407 /* Do not set deps_seen, so the user can unconditionally turn
409 cpp_opts
->deps
.modules
= false;
415 defer_opt (code
, arg
);
419 flag_no_line_commands
= 1;
423 defer_opt (code
, arg
);
427 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
429 cpp_opts
->warn_num_sign_change
= value
;
432 case OPT_Wunknown_pragmas
:
433 /* Set to greater than 1, so that even unknown pragmas in
434 system headers will be warned about. */
435 /* ??? There is no way to handle this automatically for now. */
436 warn_unknown_pragmas
= value
* 2;
440 if (!c_dialect_cxx ())
441 set_std_c89 (false, true);
443 set_std_cxx98 (true);
454 warning (0, "%<-Wabi=1%> is not supported, using =2");
457 warn_abi_version
= value
;
460 case OPT_fcanonical_system_headers
:
461 cpp_opts
->canonical_system_headers
= value
;
464 case OPT_fcond_mismatch
:
465 if (!c_dialect_cxx ())
467 flag_cond_mismatch
= value
;
470 warning (0, "switch %qs is no longer supported", option
->opt_text
);
477 disable_builtin_function (arg
);
480 case OPT_fdirectives_only
:
481 cpp_opts
->directives_only
= value
;
484 case OPT_fdollars_in_identifiers
:
485 cpp_opts
->dollars_in_ident
= value
;
488 case OPT_fmacro_prefix_map_
:
489 add_macro_prefix_map (arg
);
492 case OPT_ffreestanding
:
497 flag_no_builtin
= !value
;
500 case OPT_fconstant_string_class_
:
501 constant_string_class_name
= arg
;
504 case OPT_fextended_identifiers
:
505 cpp_opts
->extended_identifiers
= value
;
508 case OPT_fmax_include_depth_
:
509 cpp_opts
->max_include_depth
= value
;
512 case OPT_foperator_names
:
513 cpp_opts
->operator_names
= value
;
517 cpp_opts
->restore_pch_deps
= value
;
520 case OPT_fpch_preprocess
:
521 flag_pch_preprocess
= value
;
524 case OPT_fpermissive
:
525 flag_permissive
= value
;
526 global_dc
->m_permissive
= value
;
529 case OPT_fpreprocessed
:
530 cpp_opts
->preprocessed
= value
;
537 case OPT_ftrack_macro_expansion
:
542 case OPT_ftrack_macro_expansion_
:
543 if (arg
&& *arg
!= '\0')
544 cpp_opts
->track_macro_expansion
= value
;
546 cpp_opts
->track_macro_expansion
= 2;
549 case OPT_fexec_charset_
:
550 cpp_opts
->narrow_charset
= arg
;
553 case OPT_fwide_exec_charset_
:
554 cpp_opts
->wide_charset
= arg
;
557 case OPT_finput_charset_
:
558 cpp_opts
->input_charset
= arg
;
559 cpp_opts
->cpp_input_charset_explicit
= 1;
562 case OPT_ftemplate_depth_
:
563 max_tinst_depth
= value
;
566 case OPT_fvisibility_inlines_hidden
:
567 visibility_options
.inlines_hidden
= value
;
570 case OPT_femit_struct_debug_baseonly
:
571 set_struct_debug_option (&global_options
, loc
, "base");
574 case OPT_femit_struct_debug_reduced
:
575 set_struct_debug_option (&global_options
, loc
,
576 "dir:ord:sys,dir:gen:any,ind:base");
579 case OPT_femit_struct_debug_detailed_
:
580 set_struct_debug_option (&global_options
, loc
, arg
);
583 case OPT_fext_numeric_literals
:
584 cpp_opts
->ext_numeric_literals
= value
;
588 add_path (xstrdup (arg
), INC_AFTER
, 0, true);
593 defer_opt (code
, arg
);
605 add_path (xstrdup (arg
), INC_QUOTE
, 0, true);
613 add_path (xstrdup (arg
), INC_SYSTEM
, 0, true);
616 case OPT_iwithprefix
:
617 add_prefixed_path (arg
, INC_SYSTEM
);
620 case OPT_iwithprefixbefore
:
621 add_prefixed_path (arg
, INC_BRACKET
);
625 cpp_set_lang (parse_in
, CLK_ASM
);
626 cpp_opts
->dollars_in_ident
= false;
641 error ("output filename specified twice");
644 case OPT_print_objc_runtime_info
:
645 print_struct_values
= 1;
653 case OPT_std_gnu__98
:
654 if (!preprocessing_asm_p
)
655 set_std_cxx98 (code
== OPT_std_c__98
/* ISO */);
659 case OPT_std_gnu__11
:
660 if (!preprocessing_asm_p
)
661 set_std_cxx11 (code
== OPT_std_c__11
/* ISO */);
665 case OPT_std_gnu__14
:
666 if (!preprocessing_asm_p
)
667 set_std_cxx14 (code
== OPT_std_c__14
/* ISO */);
671 case OPT_std_gnu__17
:
672 if (!preprocessing_asm_p
)
673 set_std_cxx17 (code
== OPT_std_c__17
/* ISO */);
677 case OPT_std_gnu__20
:
678 if (!preprocessing_asm_p
)
679 set_std_cxx20 (code
== OPT_std_c__20
/* ISO */);
683 case OPT_std_gnu__23
:
684 if (!preprocessing_asm_p
)
685 set_std_cxx23 (code
== OPT_std_c__23
/* ISO */);
689 case OPT_std_gnu__26
:
690 if (!preprocessing_asm_p
)
691 set_std_cxx26 (code
== OPT_std_c__26
/* ISO */);
695 case OPT_std_iso9899_199409
:
696 if (!preprocessing_asm_p
)
697 set_std_c89 (code
== OPT_std_iso9899_199409
/* c94 */, true /* ISO */);
701 if (!preprocessing_asm_p
)
702 set_std_c89 (false /* c94 */, false /* ISO */);
706 if (!preprocessing_asm_p
)
707 set_std_c99 (true /* ISO */);
711 if (!preprocessing_asm_p
)
712 set_std_c99 (false /* ISO */);
716 if (!preprocessing_asm_p
)
717 set_std_c11 (true /* ISO */);
721 if (!preprocessing_asm_p
)
722 set_std_c11 (false /* ISO */);
726 if (!preprocessing_asm_p
)
727 set_std_c17 (true /* ISO */);
731 if (!preprocessing_asm_p
)
732 set_std_c17 (false /* ISO */);
736 if (!preprocessing_asm_p
)
737 set_std_c23 (true /* ISO */);
741 if (!preprocessing_asm_p
)
742 set_std_c23 (false /* ISO */);
746 cpp_opts
->trigraphs
= 1;
749 case OPT_traditional_cpp
:
750 cpp_opts
->traditional
= 1;
761 C_handle_option_auto (&global_options
, &global_options_set
,
763 c_family_lang_mask
, kind
,
764 loc
, handlers
, global_dc
);
768 ObjC_handle_option_auto (&global_options
, &global_options_set
,
770 c_family_lang_mask
, kind
,
771 loc
, handlers
, global_dc
);
775 CXX_handle_option_auto (&global_options
, &global_options_set
,
777 c_family_lang_mask
, kind
,
778 loc
, handlers
, global_dc
);
782 ObjCXX_handle_option_auto (&global_options
, &global_options_set
,
784 c_family_lang_mask
, kind
,
785 loc
, handlers
, global_dc
);
792 cpp_handle_option_auto (&global_options
, scode
, cpp_opts
);
796 /* Default implementation of TARGET_HANDLE_C_OPTION. */
799 default_handle_c_option (size_t code ATTRIBUTE_UNUSED
,
800 const char *arg ATTRIBUTE_UNUSED
,
801 int value ATTRIBUTE_UNUSED
)
806 /* Post-switch processing. */
808 c_common_post_options (const char **pfilename
)
810 /* Canonicalize the input and output filenames. */
811 if (in_fnames
== NULL
)
813 in_fnames
= XNEWVEC (const char *, 1);
816 else if (strcmp (in_fnames
[0], "-") == 0)
819 error ("cannot use %<-%> as input filename for a precompiled header");
824 if (out_fname
== NULL
|| !strcmp (out_fname
, "-"))
827 if (cpp_opts
->deps
.style
== DEPS_NONE
)
828 check_deps_environment_vars ();
830 handle_deferred_opts ();
832 sanitize_cpp_opts ();
834 register_include_chains (parse_in
, sysroot
, iprefix
, imultilib
,
835 std_inc
, std_cxx_inc
&& c_dialect_cxx (), verbose
);
837 #ifdef C_COMMON_OVERRIDE_OPTIONS
838 /* Some machines may reject certain combinations of C
839 language-specific options. */
840 C_COMMON_OVERRIDE_OPTIONS
;
843 if (flag_excess_precision
== EXCESS_PRECISION_DEFAULT
)
844 flag_excess_precision
= (flag_iso
? EXCESS_PRECISION_STANDARD
845 : EXCESS_PRECISION_FAST
);
847 /* ISO C restricts floating-point expression contraction to within
848 source-language expressions (-ffp-contract=on, currently an alias
849 for -ffp-contract=off). */
852 && (OPTION_SET_P (flag_fp_contract_mode
)
853 == (enum fp_contract_mode
) 0)
854 && flag_unsafe_math_optimizations
== 0)
855 flag_fp_contract_mode
= FP_CONTRACT_OFF
;
857 /* C language modes before C99 enable -fpermissive by default, but
858 only if -pedantic-errors is not specified. Also treat
859 -fno-permissive as a subset of -pedantic-errors that does not
860 reject certain GNU extensions also present the defaults for later
862 if (!c_dialect_cxx ()
864 && !global_dc
->m_pedantic_errors
865 && !OPTION_SET_P (flag_permissive
))
868 global_dc
->m_permissive
= 1;
871 /* If we are compiling C, and we are outside of a standards mode,
872 we can permit the new values from ISO/IEC TS 18661-3 for
873 FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
874 the set specified in ISO C99/C11. */
877 && (OPTION_SET_P (flag_permitted_flt_eval_methods
)
878 == PERMITTED_FLT_EVAL_METHODS_DEFAULT
))
879 flag_permitted_flt_eval_methods
= PERMITTED_FLT_EVAL_METHODS_TS_18661
;
881 flag_permitted_flt_eval_methods
= PERMITTED_FLT_EVAL_METHODS_C11
;
883 /* C23 Annex F does not permit certain built-in functions to raise
886 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
887 flag_fp_int_builtin_inexact
, 0);
889 /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
890 inline semantics are not supported in GNU89 or C89 mode. */
891 if (flag_gnu89_inline
== -1)
892 flag_gnu89_inline
= !flag_isoc99
;
893 else if (!flag_gnu89_inline
&& !flag_isoc99
)
894 error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
896 /* Default to ObjC sjlj exception handling if NeXT runtime < v2. */
897 if (flag_objc_sjlj_exceptions
< 0)
898 flag_objc_sjlj_exceptions
= (flag_next_runtime
&& flag_objc_abi
< 2);
899 if (flag_objc_exceptions
&& !flag_objc_sjlj_exceptions
)
902 /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
903 pattern recognition. */
905 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
906 flag_tree_loop_distribute_patterns
, 0);
908 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
909 It is never enabled in C++, as the minimum limit is not normative
911 if (c_dialect_cxx ())
912 warn_overlength_strings
= 0;
914 /* Wmain is enabled by default in C++ but not in C. */
915 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
916 even if -Wall or -Wpedantic was given (warn_main will be 2 if set
917 by -Wall, 1 if set by -Wmain). */
919 warn_main
= (c_dialect_cxx () && flag_hosted
) ? 1 : 0;
920 else if (warn_main
== 2)
921 warn_main
= flag_hosted
? 1 : 0;
923 /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
924 yet been set, it is disabled by default. In C++, it is enabled
926 if (warn_enum_compare
== -1)
927 warn_enum_compare
= c_dialect_cxx () ? 1 : 0;
929 /* -Wpacked-bitfield-compat is on by default for the C languages. The
930 warning is issued in stor-layout.cc which is not part of the front-end so
931 we need to selectively turn it on here. */
932 if (warn_packed_bitfield_compat
== -1)
933 warn_packed_bitfield_compat
= 1;
935 /* Special format checking options don't work without -Wformat; warn if
939 warning (OPT_Wformat_y2k
,
940 "%<-Wformat-y2k%> ignored without %<-Wformat%>");
941 warning (OPT_Wformat_extra_args
,
942 "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
943 warning (OPT_Wformat_zero_length
,
944 "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
945 warning (OPT_Wformat_nonliteral
,
946 "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
947 warning (OPT_Wformat_contains_nul
,
948 "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
949 warning (OPT_Wformat_security
,
950 "%<-Wformat-security%> ignored without %<-Wformat%>");
953 /* -Wimplicit-function-declaration is enabled by default for C99. */
954 if (warn_implicit_function_declaration
== -1)
955 warn_implicit_function_declaration
= flag_isoc99
;
957 /* -Wimplicit-int is enabled by default for C99. */
958 if (warn_implicit_int
== -1)
959 warn_implicit_int
= flag_isoc99
;
961 /* -Wold-style-definition is enabled by default for C23. */
962 if (warn_old_style_definition
== -1)
963 warn_old_style_definition
= flag_isoc23
;
965 /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
966 if (warn_shift_overflow
== -1)
967 warn_shift_overflow
= cxx_dialect
>= cxx11
|| flag_isoc99
;
969 /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
971 if (warn_shift_negative_value
== -1)
972 warn_shift_negative_value
= (extra_warnings
973 && (cxx_dialect
>= cxx11
|| flag_isoc99
)
974 && cxx_dialect
< cxx20
);
976 /* -Wregister is enabled by default in C++17. */
977 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, warn_register
,
978 cxx_dialect
>= cxx17
);
980 /* -Wcomma-subscript is enabled by default in C++20. */
981 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
982 warn_comma_subscript
,
984 || (cxx_dialect
== cxx20
&& warn_deprecated
));
986 /* -Wvolatile is enabled by default in C++20. */
987 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, warn_volatile
,
988 cxx_dialect
>= cxx20
&& warn_deprecated
);
990 /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */
991 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
992 warn_deprecated_enum_enum_conv
,
993 cxx_dialect
>= cxx20
&& warn_deprecated
);
995 /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */
996 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
997 warn_deprecated_enum_float_conv
,
998 cxx_dialect
>= cxx20
&& warn_deprecated
);
1000 /* Declone C++ 'structors if -Os. */
1001 if (flag_declone_ctor_dtor
== -1)
1002 flag_declone_ctor_dtor
= optimize_size
;
1004 if (flag_abi_compat_version
== 1)
1006 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
1007 flag_abi_compat_version
= 2;
1010 /* Change flag_abi_version to be the actual current ABI level, for the
1011 benefit of c_cpp_builtins, and to make comparison simpler. */
1012 const int latest_abi_version
= 19;
1013 /* Generate compatibility aliases for ABI v13 (8.2) by default. */
1014 const int abi_compat_default
= 13;
1016 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
1017 clamp (flag_abi_version
);
1018 clamp (warn_abi_version
);
1019 clamp (flag_abi_compat_version
);
1022 /* Default -Wabi= or -fabi-compat-version= from each other. */
1023 if (warn_abi_version
== -1 && flag_abi_compat_version
!= -1)
1024 warn_abi_version
= flag_abi_compat_version
;
1025 else if (flag_abi_compat_version
== -1 && warn_abi_version
!= -1)
1026 flag_abi_compat_version
= warn_abi_version
;
1027 else if (warn_abi_version
== -1 && flag_abi_compat_version
== -1)
1029 warn_abi_version
= latest_abi_version
;
1030 if (flag_abi_version
== latest_abi_version
)
1032 auto_diagnostic_group d
;
1033 if (warning (OPT_Wabi
, "%<-Wabi%> won%'t warn about anything"))
1035 inform (input_location
, "%<-Wabi%> warns about differences "
1036 "from the most up-to-date ABI, which is also used "
1038 inform (input_location
, "use e.g. %<-Wabi=11%> to warn about "
1039 "changes from GCC 7");
1041 flag_abi_compat_version
= abi_compat_default
;
1044 flag_abi_compat_version
= latest_abi_version
;
1047 /* By default, enable the new inheriting constructor semantics along with ABI
1048 11. New and old should coexist fine, but it is a change in what
1049 artificial symbols are generated. */
1050 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
1051 flag_new_inheriting_ctors
,
1052 abi_version_at_least (11));
1054 /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
1055 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, flag_new_ttp
,
1056 cxx_dialect
>= cxx17
);
1058 /* C++11 guarantees forward progress. */
1059 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, flag_finite_loops
,
1060 optimize
>= 2 && cxx_dialect
>= cxx11
);
1062 /* It's OK to discard calls to pure/const functions that might throw. */
1063 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
1064 flag_delete_dead_exceptions
, true);
1066 if (cxx_dialect
>= cxx11
)
1068 /* If we're allowing C++0x constructs, don't warn about C++98
1069 identifiers which are keywords in C++0x. */
1070 warn_cxx11_compat
= 0;
1071 cpp_opts
->cpp_warn_cxx11_compat
= 0;
1073 if (warn_narrowing
== -1)
1076 /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
1077 for -std=c++{11,14,17,20,23,26} default to
1078 -fno-ext-numeric-literals. */
1079 if (flag_iso
&& !OPTION_SET_P (flag_ext_numeric_literals
))
1080 cpp_opts
->ext_numeric_literals
= 0;
1082 else if (warn_narrowing
== -1)
1085 if (cxx_dialect
>= cxx20
)
1087 /* Don't warn about C++20 compatibility changes in C++20 or later. */
1088 warn_cxx20_compat
= 0;
1089 cpp_opts
->cpp_warn_cxx20_compat
= 0;
1092 /* C++17 has stricter evaluation order requirements; let's use some of them
1093 for earlier C++ as well, so chaining works as expected. */
1094 if (c_dialect_cxx ()
1095 && flag_strong_eval_order
== -1)
1096 flag_strong_eval_order
= (cxx_dialect
>= cxx17
? 2 : 1);
1098 if (flag_implicit_constexpr
&& cxx_dialect
< cxx14
)
1099 flag_implicit_constexpr
= false;
1101 /* Global sized deallocation is new in C++14. */
1102 if (flag_sized_deallocation
== -1)
1103 flag_sized_deallocation
= (cxx_dialect
>= cxx14
);
1105 /* Pedwarn about invalid constexpr functions before C++23. */
1106 if (warn_invalid_constexpr
== -1)
1107 warn_invalid_constexpr
= (cxx_dialect
< cxx23
);
1109 /* char8_t support is implicitly enabled in C++20 and C23. */
1110 if (flag_char8_t
== -1)
1111 flag_char8_t
= (cxx_dialect
>= cxx20
) || flag_isoc23
;
1112 cpp_opts
->unsigned_utf8char
= flag_char8_t
? 1 : cpp_opts
->unsigned_char
;
1114 if (flag_extern_tls_init
)
1116 if (!TARGET_SUPPORTS_ALIASES
|| !SUPPORTS_WEAK
)
1118 /* Lazy TLS initialization for a variable in another TU requires
1119 alias and weak reference support. */
1120 if (flag_extern_tls_init
> 0)
1121 sorry ("external TLS initialization functions not supported "
1124 flag_extern_tls_init
= 0;
1127 flag_extern_tls_init
= 1;
1130 /* Enable by default only for C++ and C++ with ObjC extensions. */
1131 if (warn_return_type
== -1 && c_dialect_cxx ())
1132 warn_return_type
= 1;
1134 /* C++20 is the final version of concepts. We still use -fconcepts
1135 to know when concepts are enabled. Note that -fconcepts-ts can
1136 be used to include additional features, although modified to
1137 work with the standard. */
1138 if (cxx_dialect
>= cxx20
|| flag_concepts_ts
)
1141 if (num_in_fnames
> 1)
1142 error ("too many filenames given; type %<%s %s%> for usage",
1143 progname
, "--help");
1145 if (flag_preprocess_only
)
1147 /* Open the output now. We must do so even if flag_no_output is
1148 on, because there may be other output than from the actual
1149 preprocessing (e.g. from -dM). */
1150 if (out_fname
[0] == '\0')
1151 out_stream
= stdout
;
1153 out_stream
= fopen (out_fname
, "w");
1155 if (out_stream
== NULL
)
1156 fatal_error (input_location
, "opening output file %s: %m", out_fname
);
1158 init_pp_output (out_stream
);
1164 /* When writing a PCH file, avoid reading some other PCH file,
1165 because the default address space slot then can't be used
1166 for the output PCH file. */
1169 c_common_no_more_pch ();
1170 /* Only -g0 and -gdwarf* are supported with PCH, for other
1171 debug formats we warn here and refuse to load any PCH files. */
1172 if (write_symbols
!= NO_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
1173 warning (OPT_Wdeprecated
,
1174 "the %qs debug info cannot be used with "
1175 "pre-compiled headers",
1176 debug_set_names (write_symbols
& ~DWARF2_DEBUG
));
1177 /* Let libcpp know that the main file is a header so it won't
1178 complain about things like #include_next and #pragma once. */
1179 cpp_opts
->main_search
= CMS_header
;
1181 else if (write_symbols
!= NO_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
1182 c_common_no_more_pch ();
1184 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1185 input_location
= UNKNOWN_LOCATION
;
1188 struct cpp_callbacks
*cb
= cpp_get_callbacks (parse_in
);
1189 cb
->file_change
= cb_file_change
;
1190 cb
->dir_change
= cb_dir_change
;
1191 if (lang_hooks
.preprocess_options
)
1192 lang_hooks
.preprocess_options (parse_in
);
1193 cpp_post_options (parse_in
);
1194 init_global_opts_from_cpp (&global_options
, cpp_get_options (parse_in
));
1195 /* For C++23 and explicit -finput-charset=UTF-8, turn on -Winvalid-utf8
1196 by default and make it a pedwarn unless -Wno-invalid-utf8. */
1197 if (cxx_dialect
>= cxx23
1198 && cpp_opts
->cpp_input_charset_explicit
1199 && strcmp (cpp_opts
->input_charset
, "UTF-8") == 0
1200 && (cpp_opts
->cpp_warn_invalid_utf8
1201 || !global_options_set
.x_warn_invalid_utf8
))
1203 global_options
.x_warn_invalid_utf8
= 1;
1204 cpp_opts
->cpp_warn_invalid_utf8
= cpp_opts
->cpp_pedantic
? 2 : 1;
1207 /* Let diagnostics infrastructure know how to convert input files the same
1208 way libcpp will do it, namely using the configured input charset and
1209 skipping a UTF-8 BOM if present. */
1210 diagnostic_initialize_input_context (global_dc
,
1211 c_common_input_charset_cb
, true);
1212 input_location
= UNKNOWN_LOCATION
;
1214 *pfilename
= this_input_filename
1215 = cpp_read_main_file (parse_in
, in_fnames
[0],
1216 /* We'll inject preamble pieces if this is
1217 not preprocessed. */
1218 !cpp_opts
->preprocessed
);
1220 /* Don't do any compilation or preprocessing if there is no input file. */
1221 if (this_input_filename
== NULL
)
1227 if (flag_working_directory
1228 && flag_preprocess_only
&& !flag_no_line_commands
)
1229 pp_dir_change (parse_in
, get_src_pwd ());
1231 /* Disable LTO output when outputting a precompiled header. */
1232 if (pch_file
&& flag_lto
)
1235 flag_generate_lto
= 0;
1238 return flag_preprocess_only
;
1241 /* Front end initialization common to C, ObjC and C++. */
1243 c_common_init (void)
1245 /* Set up preprocessor arithmetic. Must be done after call to
1246 c_common_nodes_and_builtins for type nodes to be good. */
1247 cpp_opts
->precision
= TYPE_PRECISION (intmax_type_node
);
1248 cpp_opts
->char_precision
= TYPE_PRECISION (char_type_node
);
1249 cpp_opts
->int_precision
= TYPE_PRECISION (integer_type_node
);
1250 cpp_opts
->wchar_precision
= TYPE_PRECISION (wchar_type_node
);
1251 cpp_opts
->unsigned_wchar
= TYPE_UNSIGNED (wchar_type_node
);
1252 cpp_opts
->bytes_big_endian
= BYTES_BIG_ENDIAN
;
1254 /* This can't happen until after wchar_precision and bytes_big_endian
1256 cpp_init_iconv (parse_in
);
1261 fputs ("Compiler executable checksum: ", stderr
);
1262 for (i
= 0; i
< 16; i
++)
1263 fprintf (stderr
, "%02x", executable_checksum
[i
]);
1264 putc ('\n', stderr
);
1267 /* Has to wait until now so that cpplib has its hash table. */
1270 if (flag_preprocess_only
)
1272 c_finish_options ();
1273 c_init_preprocess ();
1274 preprocess_file (parse_in
);
1281 /* Initialize the integrated preprocessor after debug output has been
1282 initialized; loop over each input file. */
1284 c_common_parse_file (void)
1286 auto dumps
= g
->get_dumps ();
1287 for (unsigned int i
= 0;;)
1289 c_finish_options ();
1290 /* Open the dump file to use for the original dump output
1291 here, to be used during parsing for the current file. */
1292 dumps
->dump_start (TDI_original
, &dump_flags
);
1297 /* And end the main input file, if the debug writer wants it */
1298 if (debug_hooks
->start_end_main_source_file
)
1299 (*debug_hooks
->end_source_file
) (0);
1300 if (++i
>= num_in_fnames
)
1302 cpp_undef_all (parse_in
);
1303 cpp_clear_file_cache (parse_in
);
1305 = cpp_read_main_file (parse_in
, in_fnames
[i
]);
1306 /* If an input file is missing, abandon further compilation.
1307 cpplib has issued a diagnostic. */
1308 if (!this_input_filename
)
1310 dumps
->dump_finish (TDI_original
);
1313 c_parse_final_cleanups ();
1314 dumps
->dump_finish (TDI_original
);
1317 /* Common finish hook for the C, ObjC and C++ front ends. */
1319 c_common_finish (void)
1321 FILE *deps_stream
= NULL
;
1322 FILE *fdeps_stream
= NULL
;
1324 /* Note that we write the dependencies even if there are errors. This is
1325 useful for handling outdated generated headers that now trigger errors
1326 (for example, with #error) which would be resolved by re-generating
1327 them. In a sense, this complements -MG. */
1328 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
1330 /* If -M or -MM was seen without -MF, default output to the
1333 deps_stream
= out_stream
;
1334 else if (deps_file
[0] == '-' && deps_file
[1] == '\0')
1335 deps_stream
= stdout
;
1338 deps_stream
= fopen (deps_file
, deps_append
? "a": "w");
1340 fatal_error (input_location
, "opening dependency file %s: %m",
1345 /* When we call cpp_finish (), it may generate some diagnostics using
1346 locations it remembered from the preprocessing phase, e.g. for
1347 -Wunused-macros. So inform c_cpp_diagnostic () not to override those
1348 locations with input_location, which would be incorrect now. */
1349 override_libcpp_locations
= false;
1351 if (cpp_opts
->deps
.fdeps_format
!= FDEPS_FMT_NONE
)
1354 fdeps_stream
= out_stream
;
1355 else if (fdeps_file
[0] == '-' && fdeps_file
[1] == '\0')
1356 fdeps_stream
= stdout
;
1359 fdeps_stream
= fopen (fdeps_file
, "w");
1361 fatal_error (input_location
, "opening dependency file %s: %m",
1364 if (fdeps_stream
== deps_stream
&& fdeps_stream
!= stdout
)
1365 fatal_error (input_location
, "%<-MF%> and %<-fdeps-file=%> cannot share an output file %s: %m",
1369 /* For performance, avoid tearing down cpplib's internal structures
1370 with cpp_destroy (). */
1371 cpp_finish (parse_in
, deps_stream
, fdeps_stream
);
1373 if (deps_stream
&& deps_stream
!= out_stream
&& deps_stream
!= stdout
1374 && (ferror (deps_stream
) || fclose (deps_stream
)))
1375 fatal_error (input_location
, "closing dependency file %s: %m", deps_file
);
1377 if (out_stream
&& (ferror (out_stream
) || fclose (out_stream
)))
1378 fatal_error (input_location
, "when writing output to %s: %m", out_fname
);
1381 /* Either of two environment variables can specify output of
1382 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1383 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1384 and DEPS_TARGET is the target to mention in the deps. They also
1385 result in dependency information being appended to the output file
1386 rather than overwriting it, and like Sun's compiler
1387 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1389 check_deps_environment_vars (void)
1393 spec
= getenv ("DEPENDENCIES_OUTPUT");
1395 cpp_opts
->deps
.style
= DEPS_USER
;
1398 spec
= getenv ("SUNPRO_DEPENDENCIES");
1401 cpp_opts
->deps
.style
= DEPS_SYSTEM
;
1402 cpp_opts
->deps
.ignore_main_file
= true;
1408 /* Find the space before the DEPS_TARGET, if there is one. */
1409 char *s
= strchr (spec
, ' ');
1412 /* Let the caller perform MAKE quoting. */
1413 defer_opt (OPT_MT
, s
+ 1);
1417 /* Command line -MF overrides environment variables and default. */
1426 /* Handle deferred command line switches. */
1428 handle_deferred_opts (void)
1430 /* Avoid allocating the deps buffer if we don't need it.
1431 (This flag may be true without there having been -MT or -MQ
1432 options, but we'll still need the deps buffer.) */
1436 if (mkdeps
*deps
= cpp_get_deps (parse_in
))
1437 for (unsigned i
= 0; i
< deferred_count
; i
++)
1439 struct deferred_opt
*opt
= &deferred_opts
[i
];
1441 if (opt
->code
== OPT_MT
|| opt
->code
== OPT_MQ
)
1442 deps_add_target (deps
, opt
->arg
, opt
->code
== OPT_MQ
);
1443 else if (opt
->code
== OPT_fdeps_target_
)
1444 fdeps_add_target (deps
, opt
->arg
, true);
1448 /* These settings are appropriate for GCC, but not necessarily so for
1449 cpplib as a library. */
1451 sanitize_cpp_opts (void)
1453 /* If we don't know what style of dependencies to output, complain
1454 if any other dependency switches have been given. */
1455 if (deps_seen
&& cpp_opts
->deps
.style
== DEPS_NONE
)
1456 error ("to generate dependencies you must specify either %<-M%> "
1459 /* -dM and dependencies suppress normal output; do it here so that
1460 the last -d[MDN] switch overrides earlier ones. */
1461 if (flag_dump_macros
== 'M')
1464 /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1465 to perform proper macro expansion. */
1466 if (cpp_opts
->directives_only
&& !cpp_opts
->preprocessed
&& !flag_dump_macros
)
1467 flag_dump_macros
= 'D';
1469 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1470 -dM since at least glibc relies on -M -dM to work. */
1471 /* Also, flag_no_output implies flag_no_line_commands, always. */
1474 if (flag_dump_macros
!= 'M')
1475 flag_dump_macros
= 0;
1476 flag_dump_includes
= 0;
1477 flag_no_line_commands
= 1;
1479 else if (cpp_opts
->deps
.missing_files
)
1480 error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
1482 cpp_opts
->unsigned_char
= !flag_signed_char
;
1483 cpp_opts
->stdc_0_in_system_headers
= STDC_0_IN_SYSTEM_HEADERS
;
1485 /* Wlong-long is disabled by default. It is enabled by:
1486 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1487 [-Wpedantic | -Wtraditional] -std=non-c99
1489 Either -Wlong-long or -Wno-long-long override any other settings.
1490 ??? These conditions should be handled in c.opt. */
1491 if (warn_long_long
== -1)
1493 warn_long_long
= ((pedantic
|| warn_traditional
)
1494 && (c_dialect_cxx () ? cxx_dialect
== cxx98
: !flag_isoc99
));
1495 cpp_opts
->cpp_warn_long_long
= warn_long_long
;
1498 /* If we're generating preprocessor output, emit current directory
1499 if explicitly requested or if debugging information is enabled.
1500 ??? Maybe we should only do it for debugging formats that
1501 actually output the current directory? */
1502 if (flag_working_directory
== -1)
1503 flag_working_directory
= (debug_info_level
!= DINFO_LEVEL_NONE
);
1505 if (warn_implicit_fallthrough
< 5)
1506 cpp_opts
->cpp_warn_implicit_fallthrough
= warn_implicit_fallthrough
;
1508 cpp_opts
->cpp_warn_implicit_fallthrough
= 0;
1510 if (cpp_opts
->directives_only
)
1512 if (cpp_warn_unused_macros
)
1513 error ("%<-fdirectives-only%> is incompatible "
1514 "with %<-Wunused-macros%>");
1515 if (cpp_opts
->traditional
)
1516 error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
1520 /* Add include path with a prefix at the front of its name. */
1522 add_prefixed_path (const char *suffix
, incpath_kind chain
)
1526 size_t prefix_len
, suffix_len
;
1528 suffix_len
= strlen (suffix
);
1529 prefix
= iprefix
? iprefix
: cpp_GCC_INCLUDE_DIR
;
1530 prefix_len
= iprefix
? strlen (iprefix
) : cpp_GCC_INCLUDE_DIR_len
;
1532 path
= (char *) xmalloc (prefix_len
+ suffix_len
+ 1);
1533 memcpy (path
, prefix
, prefix_len
);
1534 memcpy (path
+ prefix_len
, suffix
, suffix_len
);
1535 path
[prefix_len
+ suffix_len
] = '\0';
1537 add_path (path
, chain
, 0, false);
1540 /* Handle -D, -U, -A, -imacros, and the first -include. */
1542 c_finish_options (void)
1544 if (!cpp_opts
->preprocessed
)
1546 const line_map_ordinary
*bltin_map
1547 = linemap_check_ordinary (linemap_add (line_table
, LC_RENAME
, 0,
1548 special_fname_builtin (), 0));
1549 cb_file_change (parse_in
, bltin_map
);
1550 linemap_line_start (line_table
, 0, 1);
1552 /* Make sure all of the builtins about to be declared have
1553 BUILTINS_LOCATION has their location_t. */
1554 cpp_force_token_locations (parse_in
, BUILTINS_LOCATION
);
1556 cpp_init_builtins (parse_in
, flag_hosted
);
1557 c_cpp_builtins (parse_in
);
1559 /* We're about to send user input to cpplib, so make it warn for
1560 things that we previously (when we sent it internal definitions)
1561 told it to not warn.
1563 C99 permits implementation-defined characters in identifiers.
1564 The documented meaning of -std= is to turn off extensions that
1565 conflict with the specified standard, and since a strictly
1566 conforming program cannot contain a '$', we do not condition
1567 their acceptance on the -std= setting. */
1568 cpp_opts
->warn_dollars
= (cpp_opts
->cpp_pedantic
&& !cpp_opts
->c99
);
1570 const line_map_ordinary
*cmd_map
1571 = linemap_check_ordinary (linemap_add (line_table
, LC_RENAME
, 0,
1572 _("<command-line>"), 0));
1573 cb_file_change (parse_in
, cmd_map
);
1574 linemap_line_start (line_table
, 0, 1);
1576 /* All command line defines must have the same location. */
1577 cpp_force_token_locations (parse_in
, line_table
->highest_line
);
1578 for (size_t i
= 0; i
< deferred_count
; i
++)
1580 struct deferred_opt
*opt
= &deferred_opts
[i
];
1582 if (opt
->code
== OPT_D
)
1583 cpp_define (parse_in
, opt
->arg
);
1584 else if (opt
->code
== OPT_U
)
1585 cpp_undef (parse_in
, opt
->arg
);
1586 else if (opt
->code
== OPT_A
)
1588 if (opt
->arg
[0] == '-')
1589 cpp_unassert (parse_in
, opt
->arg
+ 1);
1591 cpp_assert (parse_in
, opt
->arg
);
1595 cpp_stop_forcing_token_locations (parse_in
);
1597 else if (cpp_opts
->directives_only
)
1598 cpp_init_special_builtins (parse_in
);
1600 /* Start the main input file, if the debug writer wants it. */
1601 if (debug_hooks
->start_end_main_source_file
1602 && !flag_preprocess_only
)
1603 (*debug_hooks
->start_source_file
) (0, this_input_filename
);
1605 if (!cpp_opts
->preprocessed
)
1606 /* Handle -imacros after -D and -U. */
1607 for (size_t i
= 0; i
< deferred_count
; i
++)
1609 struct deferred_opt
*opt
= &deferred_opts
[i
];
1611 if (opt
->code
== OPT_imacros
1612 && cpp_push_include (parse_in
, opt
->arg
))
1614 /* Disable push_command_line_include callback for now. */
1615 include_cursor
= deferred_count
+ 1;
1616 cpp_scan_nooutput (parse_in
);
1621 push_command_line_include ();
1624 /* Give CPP the next file given by -include, if any. */
1626 push_command_line_include (void)
1628 /* This can happen if disabled by -imacros for example.
1629 Punt so that we don't set "<command-line>" as the filename for
1631 if (include_cursor
> deferred_count
)
1634 if (!done_preinclude
)
1636 done_preinclude
= true;
1637 if (flag_hosted
&& std_inc
&& !cpp_opts
->preprocessed
)
1639 const char *preinc
= targetcm
.c_preinclude ();
1640 if (preinc
&& cpp_push_default_include (parse_in
, preinc
))
1645 pch_cpp_save_state ();
1647 while (include_cursor
< deferred_count
)
1649 struct deferred_opt
*opt
= &deferred_opts
[include_cursor
++];
1651 if (!cpp_opts
->preprocessed
&& opt
->code
== OPT_include
1652 && cpp_push_include (parse_in
, opt
->arg
))
1656 if (include_cursor
== deferred_count
)
1659 /* -Wunused-macros should only warn about macros defined hereafter. */
1660 cpp_opts
->warn_unused_macros
= cpp_warn_unused_macros
;
1661 /* Restore the line map back to the main file. */
1662 if (!cpp_opts
->preprocessed
)
1664 cpp_change_file (parse_in
, LC_RENAME
, this_input_filename
);
1665 if (lang_hooks
.preprocess_main_file
)
1666 /* We're starting the main file. Inform the FE of that. */
1667 lang_hooks
.preprocess_main_file
1668 (parse_in
, line_table
, LINEMAPS_LAST_ORDINARY_MAP (line_table
));
1671 /* Set this here so the client can change the option if it wishes,
1672 and after stacking the main file so we don't trace the main file. */
1673 line_table
->trace_includes
= cpp_opts
->print_include_names
;
1677 /* File change callback. Has to handle -include files. */
1679 cb_file_change (cpp_reader
*reader
, const line_map_ordinary
*new_map
)
1681 if (flag_preprocess_only
)
1682 pp_file_change (new_map
);
1684 fe_file_change (new_map
);
1686 if (new_map
&& cpp_opts
->preprocessed
1687 && lang_hooks
.preprocess_main_file
&& MAIN_FILE_P (new_map
)
1688 && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map
))
1689 /* We're starting the main file. Inform the FE of that. */
1690 lang_hooks
.preprocess_main_file (reader
, line_table
, new_map
);
1693 && (new_map
->reason
== LC_ENTER
|| new_map
->reason
== LC_RENAME
))
1695 /* Signal to plugins that a file is included. This could happen
1696 several times with the same file path, e.g. because of
1697 several '#include' or '#line' directives... */
1698 invoke_plugin_callbacks
1699 (PLUGIN_INCLUDE_FILE
,
1700 const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map
)));
1703 if (new_map
== 0 || (new_map
->reason
== LC_LEAVE
&& MAIN_FILE_P (new_map
)))
1705 pch_cpp_save_state ();
1706 push_command_line_include ();
1711 cb_dir_change (cpp_reader
* ARG_UNUSED (pfile
), const char *dir
)
1713 if (!set_src_pwd (dir
))
1714 warning (0, "too late for # directive to set debug directory");
1717 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1718 extensions if ISO). There is no concept of gnu94. */
1720 set_std_c89 (int c94
, int iso
)
1722 cpp_set_lang (parse_in
, c94
? CLK_STDC94
: iso
? CLK_STDC89
: CLK_GNUC89
);
1725 flag_no_gnu_keywords
= iso
;
1726 flag_no_nonansi_builtin
= iso
;
1731 lang_hooks
.name
= "GNU C89";
1734 /* Set the C 99 standard (without GNU extensions if ISO). */
1736 set_std_c99 (int iso
)
1738 cpp_set_lang (parse_in
, iso
? CLK_STDC99
: CLK_GNUC99
);
1740 flag_no_nonansi_builtin
= iso
;
1746 lang_hooks
.name
= "GNU C99";
1749 /* Set the C 11 standard (without GNU extensions if ISO). */
1751 set_std_c11 (int iso
)
1753 cpp_set_lang (parse_in
, iso
? CLK_STDC11
: CLK_GNUC11
);
1755 flag_no_nonansi_builtin
= iso
;
1761 lang_hooks
.name
= "GNU C11";
1764 /* Set the C 17 standard (without GNU extensions if ISO). */
1766 set_std_c17 (int iso
)
1768 cpp_set_lang (parse_in
, iso
? CLK_STDC17
: CLK_GNUC17
);
1770 flag_no_nonansi_builtin
= iso
;
1776 lang_hooks
.name
= "GNU C17";
1779 /* Set the C 2X standard (without GNU extensions if ISO). */
1781 set_std_c23 (int iso
)
1783 cpp_set_lang (parse_in
, iso
? CLK_STDC23
: CLK_GNUC23
);
1785 flag_no_nonansi_builtin
= iso
;
1791 lang_hooks
.name
= "GNU C23";
1795 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1797 set_std_cxx98 (int iso
)
1799 cpp_set_lang (parse_in
, iso
? CLK_CXX98
: CLK_GNUCXX
);
1800 flag_no_gnu_keywords
= iso
;
1801 flag_no_nonansi_builtin
= iso
;
1805 cxx_dialect
= cxx98
;
1806 lang_hooks
.name
= "GNU C++98";
1809 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1811 set_std_cxx11 (int iso
)
1813 cpp_set_lang (parse_in
, iso
? CLK_CXX11
: CLK_GNUCXX11
);
1814 flag_no_gnu_keywords
= iso
;
1815 flag_no_nonansi_builtin
= iso
;
1817 /* C++11 includes the C99 standard library. */
1820 cxx_dialect
= cxx11
;
1821 lang_hooks
.name
= "GNU C++11";
1824 /* Set the C++ 2014 standard (without GNU extensions if ISO). */
1826 set_std_cxx14 (int iso
)
1828 cpp_set_lang (parse_in
, iso
? CLK_CXX14
: CLK_GNUCXX14
);
1829 flag_no_gnu_keywords
= iso
;
1830 flag_no_nonansi_builtin
= iso
;
1832 /* C++14 includes the C99 standard library. */
1835 cxx_dialect
= cxx14
;
1836 lang_hooks
.name
= "GNU C++14";
1839 /* Set the C++ 2017 standard (without GNU extensions if ISO). */
1841 set_std_cxx17 (int iso
)
1843 cpp_set_lang (parse_in
, iso
? CLK_CXX17
: CLK_GNUCXX17
);
1844 flag_no_gnu_keywords
= iso
;
1845 flag_no_nonansi_builtin
= iso
;
1847 /* C++17 includes the C11 standard library. */
1851 cxx_dialect
= cxx17
;
1852 lang_hooks
.name
= "GNU C++17";
1855 /* Set the C++ 2020 standard (without GNU extensions if ISO). */
1857 set_std_cxx20 (int iso
)
1859 cpp_set_lang (parse_in
, iso
? CLK_CXX20
: CLK_GNUCXX20
);
1860 flag_no_gnu_keywords
= iso
;
1861 flag_no_nonansi_builtin
= iso
;
1863 /* C++20 includes the C11 standard library. */
1867 /* C++20 includes coroutines. */
1868 flag_coroutines
= true;
1869 cxx_dialect
= cxx20
;
1870 lang_hooks
.name
= "GNU C++20";
1873 /* Set the C++ 2023 standard (without GNU extensions if ISO). */
1875 set_std_cxx23 (int iso
)
1877 cpp_set_lang (parse_in
, iso
? CLK_CXX23
: CLK_GNUCXX23
);
1878 flag_no_gnu_keywords
= iso
;
1879 flag_no_nonansi_builtin
= iso
;
1881 /* C++23 includes the C11 standard library. */
1885 /* C++23 includes coroutines. */
1886 flag_coroutines
= true;
1887 cxx_dialect
= cxx23
;
1888 lang_hooks
.name
= "GNU C++23";
1891 /* Set the C++ 2026 standard (without GNU extensions if ISO). */
1893 set_std_cxx26 (int iso
)
1895 cpp_set_lang (parse_in
, iso
? CLK_CXX26
: CLK_GNUCXX26
);
1896 flag_no_gnu_keywords
= iso
;
1897 flag_no_nonansi_builtin
= iso
;
1899 /* C++26 includes the C11 standard library. */
1903 /* C++26 includes coroutines. */
1904 flag_coroutines
= true;
1905 cxx_dialect
= cxx26
;
1906 lang_hooks
.name
= "GNU C++26";
1909 /* Args to -d specify what to dump. Silently ignore
1910 unrecognized options; they may be aimed at toplev.cc. */
1912 handle_OPT_d (const char *arg
)
1916 while ((c
= *arg
++) != '\0')
1919 case 'M': /* Dump macros only. */
1920 case 'N': /* Dump names. */
1921 case 'D': /* Dump definitions. */
1922 case 'U': /* Dump used macros. */
1923 flag_dump_macros
= c
;
1927 flag_dump_includes
= 1;