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 /* The prefix given by -iprefix, if any. */
81 static const char *iprefix
;
83 /* The multilib directory given by -imultilib, if any. */
84 static const char *imultilib
;
86 /* The system root, if any. Overridden by -isysroot. */
87 static const char *sysroot
= TARGET_SYSTEM_ROOT
;
89 /* Zero disables all standard directories for headers. */
90 static bool std_inc
= true;
92 /* Zero disables the C++-specific standard directories for headers. */
93 static bool std_cxx_inc
= true;
95 /* If the quote chain has been split by -I-. */
96 static bool quote_chain_split
;
98 /* Number of deferred options. */
99 static size_t deferred_count
;
101 /* Number of deferred options scanned for -include. */
102 static size_t include_cursor
;
104 /* Whether any standard preincluded header has been preincluded. */
105 static bool done_preinclude
;
107 static void handle_OPT_d (const char *);
108 static void set_std_cxx98 (int);
109 static void set_std_cxx11 (int);
110 static void set_std_cxx14 (int);
111 static void set_std_cxx17 (int);
112 static void set_std_cxx20 (int);
113 static void set_std_cxx23 (int);
114 static void set_std_cxx26 (int);
115 static void set_std_c89 (int, int);
116 static void set_std_c99 (int);
117 static void set_std_c11 (int);
118 static void set_std_c17 (int);
119 static void set_std_c2x (int);
120 static void check_deps_environment_vars (void);
121 static void handle_deferred_opts (void);
122 static void sanitize_cpp_opts (void);
123 static void add_prefixed_path (const char *, incpath_kind
);
124 static void push_command_line_include (void);
125 static void cb_file_change (cpp_reader
*, const line_map_ordinary
*);
126 static void cb_dir_change (cpp_reader
*, const char *);
127 static void c_finish_options (void);
129 #ifndef STDC_0_IN_SYSTEM_HEADERS
130 #define STDC_0_IN_SYSTEM_HEADERS 0
133 /* Holds switches parsed by c_common_handle_option (), but whose
134 handling is deferred to c_common_post_options (). */
135 static void defer_opt (enum opt_code
, const char *);
136 static struct deferred_opt
143 extern const unsigned int
144 c_family_lang_mask
= (CL_C
| CL_CXX
| CL_ObjC
| CL_ObjCXX
);
146 /* Defer option CODE with argument ARG. */
148 defer_opt (enum opt_code code
, const char *arg
)
150 deferred_opts
[deferred_count
].code
= code
;
151 deferred_opts
[deferred_count
].arg
= arg
;
155 /* Return language mask for option parsing. */
157 c_common_option_lang_mask (void)
159 static const unsigned int lang_flags
[] = {CL_C
, CL_ObjC
, CL_CXX
, CL_ObjCXX
};
161 return lang_flags
[c_language
];
164 /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
166 c_diagnostic_finalizer (diagnostic_context
*context
,
167 diagnostic_info
*diagnostic
,
170 char *saved_prefix
= pp_take_prefix (context
->printer
);
171 pp_set_prefix (context
->printer
, NULL
);
172 pp_newline (context
->printer
);
173 diagnostic_show_locus (context
, diagnostic
->richloc
, diagnostic
->kind
);
174 /* By default print macro expansion contexts in the diagnostic
175 finalizer -- for tokens resulting from macro expansion. */
176 virt_loc_aware_diagnostic_finalizer (context
, diagnostic
);
177 pp_set_prefix (context
->printer
, saved_prefix
);
178 pp_flush (context
->printer
);
181 /* Common default settings for diagnostics. */
183 c_common_diagnostics_set_defaults (diagnostic_context
*context
)
185 diagnostic_finalizer (context
) = c_diagnostic_finalizer
;
186 context
->opt_permissive
= OPT_fpermissive
;
189 /* Input charset configuration for diagnostics. */
191 c_common_input_charset_cb (const char * /*filename*/)
193 const char *cs
= cpp_opts
->input_charset
;
194 return cpp_input_conversion_is_trivial (cs
) ? nullptr : cs
;
197 /* Whether options from all C-family languages should be accepted
199 static bool accept_all_c_family_options
= false;
201 /* Return whether to complain about a wrong-language option. */
203 c_common_complain_wrong_lang_p (const struct cl_option
*option
)
205 if (accept_all_c_family_options
206 && (option
->flags
& c_family_lang_mask
))
212 /* Initialize options structure OPTS. */
214 c_common_init_options_struct (struct gcc_options
*opts
)
216 opts
->x_flag_exceptions
= c_dialect_cxx ();
217 opts
->x_warn_pointer_arith
= c_dialect_cxx ();
218 opts
->x_warn_write_strings
= c_dialect_cxx ();
219 opts
->x_flag_warn_unused_result
= true;
221 /* By default, C99-like requirements for complex multiply and divide. */
222 opts
->x_flag_complex_method
= 2;
223 opts
->x_flag_default_complex_method
= opts
->x_flag_complex_method
;
226 /* Common initialization before calling option handlers. */
228 c_common_init_options (unsigned int decoded_options_count
,
229 struct cl_decoded_option
*decoded_options
)
232 struct cpp_callbacks
*cb
;
235 = new (ggc_alloc
<string_concat_db
> ()) string_concat_db ();
237 parse_in
= cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX
: CLK_GNUC89
,
238 ident_hash
, line_table
);
239 cb
= cpp_get_callbacks (parse_in
);
240 cb
->diagnostic
= c_cpp_diagnostic
;
242 cpp_opts
= cpp_get_options (parse_in
);
243 cpp_opts
->dollars_in_ident
= DOLLARS_IN_IDENTIFIERS
;
244 cpp_opts
->objc
= c_dialect_objc ();
245 cpp_opts
->deps
.modules
= true;
247 /* Reset to avoid warnings on internal definitions. We set it just
248 before passing on command-line options to cpplib. */
249 cpp_opts
->warn_dollars
= 0;
251 deferred_opts
= XNEWVEC (struct deferred_opt
, decoded_options_count
);
253 if (c_language
== clk_c
)
255 /* The default for C is gnu17. */
256 set_std_c17 (false /* ISO */);
258 /* If preprocessing assembly language, accept any of the C-family
259 front end options since the driver may pass them through. */
260 for (i
= 1; i
< decoded_options_count
; i
++)
261 if (decoded_options
[i
].opt_index
== OPT_lang_asm
)
263 accept_all_c_family_options
= true;
268 /* Set C++ standard to C++17 if not specified on the command line. */
269 if (c_dialect_cxx ())
270 set_std_cxx17 (/*ISO*/false);
272 global_dc
->colorize_source_p
= true;
275 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
276 form of an -f or -W option was given. Returns false if the switch was
277 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
279 c_common_handle_option (size_t scode
, const char *arg
, HOST_WIDE_INT value
,
280 int kind
, location_t loc
,
281 const struct cl_option_handlers
*handlers
)
283 const struct cl_option
*option
= &cl_options
[scode
];
284 enum opt_code code
= (enum opt_code
) scode
;
287 /* Prevent resetting the language standard to a C dialect when the driver
288 has already determined that we're looking at assembler input. */
289 bool preprocessing_asm_p
= (cpp_get_options (parse_in
)->lang
== CLK_ASM
);
294 if (cl_options
[code
].flags
& c_family_lang_mask
)
296 if ((option
->flags
& CL_TARGET
)
297 && ! targetcm
.handle_c_option (scode
, arg
, value
))
304 case OPT__output_pch
:
309 defer_opt (code
, arg
);
313 cpp_opts
->discard_comments
= 0;
317 cpp_opts
->discard_comments
= 0;
318 cpp_opts
->discard_comments_in_macro_exp
= 0;
322 defer_opt (code
, arg
);
326 cpp_opts
->print_include_names
= 1;
330 TARGET_OPTF (xstrdup (arg
));
334 if (strcmp (arg
, "-"))
335 add_path (xstrdup (arg
), INC_BRACKET
, 0, true);
338 if (quote_chain_split
)
339 error ("%<-I-%> specified twice");
340 quote_chain_split
= true;
341 split_quote_chain ();
342 inform (input_location
, "obsolete option %<-I-%> used, "
343 "please use %<-iquote%> instead");
349 /* When doing dependencies with -M or -MM, suppress normal
350 preprocessed output, but still do -dM etc. as software
351 depends on this. Preprocessed output does occur if -MD, -MMD
352 or environment var dependency generation is used. */
353 cpp_opts
->deps
.style
= (code
== OPT_M
? DEPS_SYSTEM
: DEPS_USER
);
359 cpp_opts
->deps
.style
= (code
== OPT_MD
? DEPS_SYSTEM
: DEPS_USER
);
360 cpp_opts
->deps
.need_preprocessor_output
= true;
371 cpp_opts
->deps
.missing_files
= true;
376 cpp_opts
->deps
.phony_targets
= true;
380 /* Do not set deps_seen, so the user can unconditionally turn
382 cpp_opts
->deps
.modules
= true;
385 case OPT_Mno_modules
:
386 /* Do not set deps_seen, so the user can unconditionally turn
388 cpp_opts
->deps
.modules
= false;
394 defer_opt (code
, arg
);
398 flag_no_line_commands
= 1;
402 defer_opt (code
, arg
);
406 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
408 cpp_opts
->warn_num_sign_change
= value
;
411 case OPT_Wunknown_pragmas
:
412 /* Set to greater than 1, so that even unknown pragmas in
413 system headers will be warned about. */
414 /* ??? There is no way to handle this automatically for now. */
415 warn_unknown_pragmas
= value
* 2;
419 if (!c_dialect_cxx ())
420 set_std_c89 (false, true);
422 set_std_cxx98 (true);
433 warning (0, "%<-Wabi=1%> is not supported, using =2");
436 warn_abi_version
= value
;
439 case OPT_fcanonical_system_headers
:
440 cpp_opts
->canonical_system_headers
= value
;
443 case OPT_fcond_mismatch
:
444 if (!c_dialect_cxx ())
446 flag_cond_mismatch
= value
;
449 warning (0, "switch %qs is no longer supported", option
->opt_text
);
456 disable_builtin_function (arg
);
459 case OPT_fdirectives_only
:
460 cpp_opts
->directives_only
= value
;
463 case OPT_fdollars_in_identifiers
:
464 cpp_opts
->dollars_in_ident
= value
;
467 case OPT_fmacro_prefix_map_
:
468 add_macro_prefix_map (arg
);
471 case OPT_ffreestanding
:
476 flag_no_builtin
= !value
;
479 case OPT_fconstant_string_class_
:
480 constant_string_class_name
= arg
;
483 case OPT_fextended_identifiers
:
484 cpp_opts
->extended_identifiers
= value
;
487 case OPT_fmax_include_depth_
:
488 cpp_opts
->max_include_depth
= value
;
491 case OPT_foperator_names
:
492 cpp_opts
->operator_names
= value
;
496 cpp_opts
->restore_pch_deps
= value
;
499 case OPT_fpch_preprocess
:
500 flag_pch_preprocess
= value
;
503 case OPT_fpermissive
:
504 flag_permissive
= value
;
505 global_dc
->permissive
= value
;
508 case OPT_fpreprocessed
:
509 cpp_opts
->preprocessed
= value
;
516 case OPT_ftrack_macro_expansion
:
521 case OPT_ftrack_macro_expansion_
:
522 if (arg
&& *arg
!= '\0')
523 cpp_opts
->track_macro_expansion
= value
;
525 cpp_opts
->track_macro_expansion
= 2;
528 case OPT_fexec_charset_
:
529 cpp_opts
->narrow_charset
= arg
;
532 case OPT_fwide_exec_charset_
:
533 cpp_opts
->wide_charset
= arg
;
536 case OPT_finput_charset_
:
537 cpp_opts
->input_charset
= arg
;
538 cpp_opts
->cpp_input_charset_explicit
= 1;
541 case OPT_ftemplate_depth_
:
542 max_tinst_depth
= value
;
545 case OPT_fvisibility_inlines_hidden
:
546 visibility_options
.inlines_hidden
= value
;
549 case OPT_femit_struct_debug_baseonly
:
550 set_struct_debug_option (&global_options
, loc
, "base");
553 case OPT_femit_struct_debug_reduced
:
554 set_struct_debug_option (&global_options
, loc
,
555 "dir:ord:sys,dir:gen:any,ind:base");
558 case OPT_femit_struct_debug_detailed_
:
559 set_struct_debug_option (&global_options
, loc
, arg
);
562 case OPT_fext_numeric_literals
:
563 cpp_opts
->ext_numeric_literals
= value
;
567 add_path (xstrdup (arg
), INC_AFTER
, 0, true);
572 defer_opt (code
, arg
);
584 add_path (xstrdup (arg
), INC_QUOTE
, 0, true);
592 add_path (xstrdup (arg
), INC_SYSTEM
, 0, true);
595 case OPT_iwithprefix
:
596 add_prefixed_path (arg
, INC_SYSTEM
);
599 case OPT_iwithprefixbefore
:
600 add_prefixed_path (arg
, INC_BRACKET
);
604 cpp_set_lang (parse_in
, CLK_ASM
);
605 cpp_opts
->dollars_in_ident
= false;
620 error ("output filename specified twice");
623 case OPT_print_objc_runtime_info
:
624 print_struct_values
= 1;
632 case OPT_std_gnu__98
:
633 if (!preprocessing_asm_p
)
634 set_std_cxx98 (code
== OPT_std_c__98
/* ISO */);
638 case OPT_std_gnu__11
:
639 if (!preprocessing_asm_p
)
640 set_std_cxx11 (code
== OPT_std_c__11
/* ISO */);
644 case OPT_std_gnu__14
:
645 if (!preprocessing_asm_p
)
646 set_std_cxx14 (code
== OPT_std_c__14
/* ISO */);
650 case OPT_std_gnu__17
:
651 if (!preprocessing_asm_p
)
652 set_std_cxx17 (code
== OPT_std_c__17
/* ISO */);
656 case OPT_std_gnu__20
:
657 if (!preprocessing_asm_p
)
658 set_std_cxx20 (code
== OPT_std_c__20
/* ISO */);
662 case OPT_std_gnu__23
:
663 if (!preprocessing_asm_p
)
664 set_std_cxx23 (code
== OPT_std_c__23
/* ISO */);
668 case OPT_std_gnu__26
:
669 if (!preprocessing_asm_p
)
670 set_std_cxx26 (code
== OPT_std_c__26
/* ISO */);
674 case OPT_std_iso9899_199409
:
675 if (!preprocessing_asm_p
)
676 set_std_c89 (code
== OPT_std_iso9899_199409
/* c94 */, true /* ISO */);
680 if (!preprocessing_asm_p
)
681 set_std_c89 (false /* c94 */, false /* ISO */);
685 if (!preprocessing_asm_p
)
686 set_std_c99 (true /* ISO */);
690 if (!preprocessing_asm_p
)
691 set_std_c99 (false /* ISO */);
695 if (!preprocessing_asm_p
)
696 set_std_c11 (true /* ISO */);
700 if (!preprocessing_asm_p
)
701 set_std_c11 (false /* ISO */);
705 if (!preprocessing_asm_p
)
706 set_std_c17 (true /* ISO */);
710 if (!preprocessing_asm_p
)
711 set_std_c17 (false /* ISO */);
715 if (!preprocessing_asm_p
)
716 set_std_c2x (true /* ISO */);
720 if (!preprocessing_asm_p
)
721 set_std_c2x (false /* ISO */);
725 cpp_opts
->trigraphs
= 1;
728 case OPT_traditional_cpp
:
729 cpp_opts
->traditional
= 1;
740 C_handle_option_auto (&global_options
, &global_options_set
,
742 c_family_lang_mask
, kind
,
743 loc
, handlers
, global_dc
);
747 ObjC_handle_option_auto (&global_options
, &global_options_set
,
749 c_family_lang_mask
, kind
,
750 loc
, handlers
, global_dc
);
754 CXX_handle_option_auto (&global_options
, &global_options_set
,
756 c_family_lang_mask
, kind
,
757 loc
, handlers
, global_dc
);
761 ObjCXX_handle_option_auto (&global_options
, &global_options_set
,
763 c_family_lang_mask
, kind
,
764 loc
, handlers
, global_dc
);
771 cpp_handle_option_auto (&global_options
, scode
, cpp_opts
);
775 /* Default implementation of TARGET_HANDLE_C_OPTION. */
778 default_handle_c_option (size_t code ATTRIBUTE_UNUSED
,
779 const char *arg ATTRIBUTE_UNUSED
,
780 int value ATTRIBUTE_UNUSED
)
785 /* Post-switch processing. */
787 c_common_post_options (const char **pfilename
)
789 /* Canonicalize the input and output filenames. */
790 if (in_fnames
== NULL
)
792 in_fnames
= XNEWVEC (const char *, 1);
795 else if (strcmp (in_fnames
[0], "-") == 0)
798 error ("cannot use %<-%> as input filename for a precompiled header");
803 if (out_fname
== NULL
|| !strcmp (out_fname
, "-"))
806 if (cpp_opts
->deps
.style
== DEPS_NONE
)
807 check_deps_environment_vars ();
809 handle_deferred_opts ();
811 sanitize_cpp_opts ();
813 register_include_chains (parse_in
, sysroot
, iprefix
, imultilib
,
814 std_inc
, std_cxx_inc
&& c_dialect_cxx (), verbose
);
816 #ifdef C_COMMON_OVERRIDE_OPTIONS
817 /* Some machines may reject certain combinations of C
818 language-specific options. */
819 C_COMMON_OVERRIDE_OPTIONS
;
822 if (flag_excess_precision
== EXCESS_PRECISION_DEFAULT
)
823 flag_excess_precision
= (flag_iso
? EXCESS_PRECISION_STANDARD
824 : EXCESS_PRECISION_FAST
);
826 /* ISO C restricts floating-point expression contraction to within
827 source-language expressions (-ffp-contract=on, currently an alias
828 for -ffp-contract=off). */
831 && (OPTION_SET_P (flag_fp_contract_mode
)
832 == (enum fp_contract_mode
) 0)
833 && flag_unsafe_math_optimizations
== 0)
834 flag_fp_contract_mode
= FP_CONTRACT_OFF
;
836 /* If we are compiling C, and we are outside of a standards mode,
837 we can permit the new values from ISO/IEC TS 18661-3 for
838 FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
839 the set specified in ISO C99/C11. */
842 && (OPTION_SET_P (flag_permitted_flt_eval_methods
)
843 == PERMITTED_FLT_EVAL_METHODS_DEFAULT
))
844 flag_permitted_flt_eval_methods
= PERMITTED_FLT_EVAL_METHODS_TS_18661
;
846 flag_permitted_flt_eval_methods
= PERMITTED_FLT_EVAL_METHODS_C11
;
848 /* C2X Annex F does not permit certain built-in functions to raise
851 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
852 flag_fp_int_builtin_inexact
, 0);
854 /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
855 inline semantics are not supported in GNU89 or C89 mode. */
856 if (flag_gnu89_inline
== -1)
857 flag_gnu89_inline
= !flag_isoc99
;
858 else if (!flag_gnu89_inline
&& !flag_isoc99
)
859 error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
861 /* Default to ObjC sjlj exception handling if NeXT runtime < v2. */
862 if (flag_objc_sjlj_exceptions
< 0)
863 flag_objc_sjlj_exceptions
= (flag_next_runtime
&& flag_objc_abi
< 2);
864 if (flag_objc_exceptions
&& !flag_objc_sjlj_exceptions
)
867 /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
868 pattern recognition. */
870 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
871 flag_tree_loop_distribute_patterns
, 0);
873 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
874 It is never enabled in C++, as the minimum limit is not normative
876 if (c_dialect_cxx ())
877 warn_overlength_strings
= 0;
879 /* Wmain is enabled by default in C++ but not in C. */
880 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
881 even if -Wall or -Wpedantic was given (warn_main will be 2 if set
882 by -Wall, 1 if set by -Wmain). */
884 warn_main
= (c_dialect_cxx () && flag_hosted
) ? 1 : 0;
885 else if (warn_main
== 2)
886 warn_main
= flag_hosted
? 1 : 0;
888 /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
889 yet been set, it is disabled by default. In C++, it is enabled
891 if (warn_enum_compare
== -1)
892 warn_enum_compare
= c_dialect_cxx () ? 1 : 0;
894 /* -Wpacked-bitfield-compat is on by default for the C languages. The
895 warning is issued in stor-layout.cc which is not part of the front-end so
896 we need to selectively turn it on here. */
897 if (warn_packed_bitfield_compat
== -1)
898 warn_packed_bitfield_compat
= 1;
900 /* Special format checking options don't work without -Wformat; warn if
904 warning (OPT_Wformat_y2k
,
905 "%<-Wformat-y2k%> ignored without %<-Wformat%>");
906 warning (OPT_Wformat_extra_args
,
907 "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
908 warning (OPT_Wformat_zero_length
,
909 "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
910 warning (OPT_Wformat_nonliteral
,
911 "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
912 warning (OPT_Wformat_contains_nul
,
913 "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
914 warning (OPT_Wformat_security
,
915 "%<-Wformat-security%> ignored without %<-Wformat%>");
918 /* -Wimplicit-function-declaration is enabled by default for C99. */
919 if (warn_implicit_function_declaration
== -1)
920 warn_implicit_function_declaration
= flag_isoc99
;
922 /* -Wimplicit-int is enabled by default for C99. */
923 if (warn_implicit_int
== -1)
924 warn_implicit_int
= flag_isoc99
;
926 /* -Wold-style-definition is enabled by default for C2X. */
927 if (warn_old_style_definition
== -1)
928 warn_old_style_definition
= flag_isoc2x
;
930 /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
931 if (warn_shift_overflow
== -1)
932 warn_shift_overflow
= cxx_dialect
>= cxx11
|| flag_isoc99
;
934 /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
936 if (warn_shift_negative_value
== -1)
937 warn_shift_negative_value
= (extra_warnings
938 && (cxx_dialect
>= cxx11
|| flag_isoc99
)
939 && cxx_dialect
< cxx20
);
941 /* -Wregister is enabled by default in C++17. */
942 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, warn_register
,
943 cxx_dialect
>= cxx17
);
945 /* -Wcomma-subscript is enabled by default in C++20. */
946 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
947 warn_comma_subscript
,
949 || (cxx_dialect
== cxx20
&& warn_deprecated
));
951 /* -Wvolatile is enabled by default in C++20. */
952 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, warn_volatile
,
953 cxx_dialect
>= cxx20
&& warn_deprecated
);
955 /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */
956 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
957 warn_deprecated_enum_enum_conv
,
958 cxx_dialect
>= cxx20
&& warn_deprecated
);
960 /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */
961 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
962 warn_deprecated_enum_float_conv
,
963 cxx_dialect
>= cxx20
&& warn_deprecated
);
965 /* Declone C++ 'structors if -Os. */
966 if (flag_declone_ctor_dtor
== -1)
967 flag_declone_ctor_dtor
= optimize_size
;
969 if (flag_abi_compat_version
== 1)
971 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
972 flag_abi_compat_version
= 2;
975 /* Change flag_abi_version to be the actual current ABI level, for the
976 benefit of c_cpp_builtins, and to make comparison simpler. */
977 const int latest_abi_version
= 18;
978 /* Generate compatibility aliases for ABI v13 (8.2) by default. */
979 const int abi_compat_default
= 13;
981 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
982 clamp (flag_abi_version
);
983 clamp (warn_abi_version
);
984 clamp (flag_abi_compat_version
);
987 /* Default -Wabi= or -fabi-compat-version= from each other. */
988 if (warn_abi_version
== -1 && flag_abi_compat_version
!= -1)
989 warn_abi_version
= flag_abi_compat_version
;
990 else if (flag_abi_compat_version
== -1 && warn_abi_version
!= -1)
991 flag_abi_compat_version
= warn_abi_version
;
992 else if (warn_abi_version
== -1 && flag_abi_compat_version
== -1)
994 warn_abi_version
= latest_abi_version
;
995 if (flag_abi_version
== latest_abi_version
)
997 auto_diagnostic_group d
;
998 if (warning (OPT_Wabi
, "%<-Wabi%> won%'t warn about anything"))
1000 inform (input_location
, "%<-Wabi%> warns about differences "
1001 "from the most up-to-date ABI, which is also used "
1003 inform (input_location
, "use e.g. %<-Wabi=11%> to warn about "
1004 "changes from GCC 7");
1006 flag_abi_compat_version
= abi_compat_default
;
1009 flag_abi_compat_version
= latest_abi_version
;
1012 /* By default, enable the new inheriting constructor semantics along with ABI
1013 11. New and old should coexist fine, but it is a change in what
1014 artificial symbols are generated. */
1015 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
1016 flag_new_inheriting_ctors
,
1017 abi_version_at_least (11));
1019 /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
1020 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, flag_new_ttp
,
1021 cxx_dialect
>= cxx17
);
1023 /* C++11 guarantees forward progress. */
1024 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
, flag_finite_loops
,
1025 optimize
>= 2 && cxx_dialect
>= cxx11
);
1027 /* It's OK to discard calls to pure/const functions that might throw. */
1028 SET_OPTION_IF_UNSET (&global_options
, &global_options_set
,
1029 flag_delete_dead_exceptions
, true);
1031 if (cxx_dialect
>= cxx11
)
1033 /* If we're allowing C++0x constructs, don't warn about C++98
1034 identifiers which are keywords in C++0x. */
1035 warn_cxx11_compat
= 0;
1036 cpp_opts
->cpp_warn_cxx11_compat
= 0;
1038 if (warn_narrowing
== -1)
1041 /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
1042 for -std=c++{11,14,17,20,23,26} default to
1043 -fno-ext-numeric-literals. */
1044 if (flag_iso
&& !OPTION_SET_P (flag_ext_numeric_literals
))
1045 cpp_opts
->ext_numeric_literals
= 0;
1047 else if (warn_narrowing
== -1)
1050 if (cxx_dialect
>= cxx20
)
1052 /* Don't warn about C++20 compatibility changes in C++20 or later. */
1053 warn_cxx20_compat
= 0;
1054 cpp_opts
->cpp_warn_cxx20_compat
= 0;
1057 /* C++17 has stricter evaluation order requirements; let's use some of them
1058 for earlier C++ as well, so chaining works as expected. */
1059 if (c_dialect_cxx ()
1060 && flag_strong_eval_order
== -1)
1061 flag_strong_eval_order
= (cxx_dialect
>= cxx17
? 2 : 1);
1063 if (flag_implicit_constexpr
&& cxx_dialect
< cxx14
)
1064 flag_implicit_constexpr
= false;
1066 /* Global sized deallocation is new in C++14. */
1067 if (flag_sized_deallocation
== -1)
1068 flag_sized_deallocation
= (cxx_dialect
>= cxx14
);
1070 /* Pedwarn about invalid constexpr functions before C++23. */
1071 if (warn_invalid_constexpr
== -1)
1072 warn_invalid_constexpr
= (cxx_dialect
< cxx23
);
1074 /* char8_t support is implicitly enabled in C++20 and C2X. */
1075 if (flag_char8_t
== -1)
1076 flag_char8_t
= (cxx_dialect
>= cxx20
) || flag_isoc2x
;
1077 cpp_opts
->unsigned_utf8char
= flag_char8_t
? 1 : cpp_opts
->unsigned_char
;
1079 if (flag_extern_tls_init
)
1081 if (!TARGET_SUPPORTS_ALIASES
|| !SUPPORTS_WEAK
)
1083 /* Lazy TLS initialization for a variable in another TU requires
1084 alias and weak reference support. */
1085 if (flag_extern_tls_init
> 0)
1086 sorry ("external TLS initialization functions not supported "
1089 flag_extern_tls_init
= 0;
1092 flag_extern_tls_init
= 1;
1095 /* Enable by default only for C++ and C++ with ObjC extensions. */
1096 if (warn_return_type
== -1 && c_dialect_cxx ())
1097 warn_return_type
= 1;
1099 /* C++20 is the final version of concepts. We still use -fconcepts
1100 to know when concepts are enabled. Note that -fconcepts-ts can
1101 be used to include additional features, although modified to
1102 work with the standard. */
1103 if (cxx_dialect
>= cxx20
|| flag_concepts_ts
)
1106 if (num_in_fnames
> 1)
1107 error ("too many filenames given; type %<%s %s%> for usage",
1108 progname
, "--help");
1110 if (flag_preprocess_only
)
1112 /* Open the output now. We must do so even if flag_no_output is
1113 on, because there may be other output than from the actual
1114 preprocessing (e.g. from -dM). */
1115 if (out_fname
[0] == '\0')
1116 out_stream
= stdout
;
1118 out_stream
= fopen (out_fname
, "w");
1120 if (out_stream
== NULL
)
1121 fatal_error (input_location
, "opening output file %s: %m", out_fname
);
1123 init_pp_output (out_stream
);
1129 /* When writing a PCH file, avoid reading some other PCH file,
1130 because the default address space slot then can't be used
1131 for the output PCH file. */
1134 c_common_no_more_pch ();
1135 /* Only -g0 and -gdwarf* are supported with PCH, for other
1136 debug formats we warn here and refuse to load any PCH files. */
1137 if (write_symbols
!= NO_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
1138 warning (OPT_Wdeprecated
,
1139 "the %qs debug info cannot be used with "
1140 "pre-compiled headers",
1141 debug_set_names (write_symbols
& ~DWARF2_DEBUG
));
1143 else if (write_symbols
!= NO_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
1144 c_common_no_more_pch ();
1146 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1147 input_location
= UNKNOWN_LOCATION
;
1150 struct cpp_callbacks
*cb
= cpp_get_callbacks (parse_in
);
1151 cb
->file_change
= cb_file_change
;
1152 cb
->dir_change
= cb_dir_change
;
1153 if (lang_hooks
.preprocess_options
)
1154 lang_hooks
.preprocess_options (parse_in
);
1155 cpp_post_options (parse_in
);
1156 init_global_opts_from_cpp (&global_options
, cpp_get_options (parse_in
));
1157 /* For C++23 and explicit -finput-charset=UTF-8, turn on -Winvalid-utf8
1158 by default and make it a pedwarn unless -Wno-invalid-utf8. */
1159 if (cxx_dialect
>= cxx23
1160 && cpp_opts
->cpp_input_charset_explicit
1161 && strcmp (cpp_opts
->input_charset
, "UTF-8") == 0
1162 && (cpp_opts
->cpp_warn_invalid_utf8
1163 || !global_options_set
.x_warn_invalid_utf8
))
1165 global_options
.x_warn_invalid_utf8
= 1;
1166 cpp_opts
->cpp_warn_invalid_utf8
= cpp_opts
->cpp_pedantic
? 2 : 1;
1169 /* Let diagnostics infrastructure know how to convert input files the same
1170 way libcpp will do it, namely using the configured input charset and
1171 skipping a UTF-8 BOM if present. */
1172 diagnostic_initialize_input_context (global_dc
,
1173 c_common_input_charset_cb
, true);
1174 input_location
= UNKNOWN_LOCATION
;
1176 *pfilename
= this_input_filename
1177 = cpp_read_main_file (parse_in
, in_fnames
[0],
1178 /* We'll inject preamble pieces if this is
1179 not preprocessed. */
1180 !cpp_opts
->preprocessed
);
1182 /* Don't do any compilation or preprocessing if there is no input file. */
1183 if (this_input_filename
== NULL
)
1189 if (flag_working_directory
1190 && flag_preprocess_only
&& !flag_no_line_commands
)
1191 pp_dir_change (parse_in
, get_src_pwd ());
1193 /* Disable LTO output when outputting a precompiled header. */
1194 if (pch_file
&& flag_lto
)
1197 flag_generate_lto
= 0;
1200 return flag_preprocess_only
;
1203 /* Front end initialization common to C, ObjC and C++. */
1205 c_common_init (void)
1207 /* Set up preprocessor arithmetic. Must be done after call to
1208 c_common_nodes_and_builtins for type nodes to be good. */
1209 cpp_opts
->precision
= TYPE_PRECISION (intmax_type_node
);
1210 cpp_opts
->char_precision
= TYPE_PRECISION (char_type_node
);
1211 cpp_opts
->int_precision
= TYPE_PRECISION (integer_type_node
);
1212 cpp_opts
->wchar_precision
= TYPE_PRECISION (wchar_type_node
);
1213 cpp_opts
->unsigned_wchar
= TYPE_UNSIGNED (wchar_type_node
);
1214 cpp_opts
->bytes_big_endian
= BYTES_BIG_ENDIAN
;
1216 /* This can't happen until after wchar_precision and bytes_big_endian
1218 cpp_init_iconv (parse_in
);
1223 fputs ("Compiler executable checksum: ", stderr
);
1224 for (i
= 0; i
< 16; i
++)
1225 fprintf (stderr
, "%02x", executable_checksum
[i
]);
1226 putc ('\n', stderr
);
1229 /* Has to wait until now so that cpplib has its hash table. */
1232 if (flag_preprocess_only
)
1234 c_finish_options ();
1235 c_init_preprocess ();
1236 preprocess_file (parse_in
);
1243 /* Initialize the integrated preprocessor after debug output has been
1244 initialized; loop over each input file. */
1246 c_common_parse_file (void)
1248 auto dumps
= g
->get_dumps ();
1249 for (unsigned int i
= 0;;)
1251 c_finish_options ();
1252 /* Open the dump file to use for the original dump output
1253 here, to be used during parsing for the current file. */
1254 dumps
->dump_start (TDI_original
, &dump_flags
);
1259 /* And end the main input file, if the debug writer wants it */
1260 if (debug_hooks
->start_end_main_source_file
)
1261 (*debug_hooks
->end_source_file
) (0);
1262 if (++i
>= num_in_fnames
)
1264 cpp_undef_all (parse_in
);
1265 cpp_clear_file_cache (parse_in
);
1267 = cpp_read_main_file (parse_in
, in_fnames
[i
]);
1268 /* If an input file is missing, abandon further compilation.
1269 cpplib has issued a diagnostic. */
1270 if (!this_input_filename
)
1272 dumps
->dump_finish (TDI_original
);
1275 c_parse_final_cleanups ();
1276 dumps
->dump_finish (TDI_original
);
1279 /* Common finish hook for the C, ObjC and C++ front ends. */
1281 c_common_finish (void)
1283 FILE *deps_stream
= NULL
;
1285 /* Note that we write the dependencies even if there are errors. This is
1286 useful for handling outdated generated headers that now trigger errors
1287 (for example, with #error) which would be resolved by re-generating
1288 them. In a sense, this complements -MG. */
1289 if (cpp_opts
->deps
.style
!= DEPS_NONE
)
1291 /* If -M or -MM was seen without -MF, default output to the
1294 deps_stream
= out_stream
;
1295 else if (deps_file
[0] == '-' && deps_file
[1] == '\0')
1296 deps_stream
= stdout
;
1299 deps_stream
= fopen (deps_file
, deps_append
? "a": "w");
1301 fatal_error (input_location
, "opening dependency file %s: %m",
1306 /* When we call cpp_finish (), it may generate some diagnostics using
1307 locations it remembered from the preprocessing phase, e.g. for
1308 -Wunused-macros. So inform c_cpp_diagnostic () not to override those
1309 locations with input_location, which would be incorrect now. */
1310 override_libcpp_locations
= false;
1312 /* For performance, avoid tearing down cpplib's internal structures
1313 with cpp_destroy (). */
1314 cpp_finish (parse_in
, deps_stream
);
1316 if (deps_stream
&& deps_stream
!= out_stream
&& deps_stream
!= stdout
1317 && (ferror (deps_stream
) || fclose (deps_stream
)))
1318 fatal_error (input_location
, "closing dependency file %s: %m", deps_file
);
1320 if (out_stream
&& (ferror (out_stream
) || fclose (out_stream
)))
1321 fatal_error (input_location
, "when writing output to %s: %m", out_fname
);
1324 /* Either of two environment variables can specify output of
1325 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1326 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1327 and DEPS_TARGET is the target to mention in the deps. They also
1328 result in dependency information being appended to the output file
1329 rather than overwriting it, and like Sun's compiler
1330 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1332 check_deps_environment_vars (void)
1336 spec
= getenv ("DEPENDENCIES_OUTPUT");
1338 cpp_opts
->deps
.style
= DEPS_USER
;
1341 spec
= getenv ("SUNPRO_DEPENDENCIES");
1344 cpp_opts
->deps
.style
= DEPS_SYSTEM
;
1345 cpp_opts
->deps
.ignore_main_file
= true;
1351 /* Find the space before the DEPS_TARGET, if there is one. */
1352 char *s
= strchr (spec
, ' ');
1355 /* Let the caller perform MAKE quoting. */
1356 defer_opt (OPT_MT
, s
+ 1);
1360 /* Command line -MF overrides environment variables and default. */
1369 /* Handle deferred command line switches. */
1371 handle_deferred_opts (void)
1373 /* Avoid allocating the deps buffer if we don't need it.
1374 (This flag may be true without there having been -MT or -MQ
1375 options, but we'll still need the deps buffer.) */
1379 if (mkdeps
*deps
= cpp_get_deps (parse_in
))
1380 for (unsigned i
= 0; i
< deferred_count
; i
++)
1382 struct deferred_opt
*opt
= &deferred_opts
[i
];
1384 if (opt
->code
== OPT_MT
|| opt
->code
== OPT_MQ
)
1385 deps_add_target (deps
, opt
->arg
, opt
->code
== OPT_MQ
);
1389 /* These settings are appropriate for GCC, but not necessarily so for
1390 cpplib as a library. */
1392 sanitize_cpp_opts (void)
1394 /* If we don't know what style of dependencies to output, complain
1395 if any other dependency switches have been given. */
1396 if (deps_seen
&& cpp_opts
->deps
.style
== DEPS_NONE
)
1397 error ("to generate dependencies you must specify either %<-M%> "
1400 /* -dM and dependencies suppress normal output; do it here so that
1401 the last -d[MDN] switch overrides earlier ones. */
1402 if (flag_dump_macros
== 'M')
1405 /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1406 to perform proper macro expansion. */
1407 if (cpp_opts
->directives_only
&& !cpp_opts
->preprocessed
&& !flag_dump_macros
)
1408 flag_dump_macros
= 'D';
1410 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1411 -dM since at least glibc relies on -M -dM to work. */
1412 /* Also, flag_no_output implies flag_no_line_commands, always. */
1415 if (flag_dump_macros
!= 'M')
1416 flag_dump_macros
= 0;
1417 flag_dump_includes
= 0;
1418 flag_no_line_commands
= 1;
1420 else if (cpp_opts
->deps
.missing_files
)
1421 error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
1423 cpp_opts
->unsigned_char
= !flag_signed_char
;
1424 cpp_opts
->stdc_0_in_system_headers
= STDC_0_IN_SYSTEM_HEADERS
;
1426 /* Wlong-long is disabled by default. It is enabled by:
1427 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1428 [-Wpedantic | -Wtraditional] -std=non-c99
1430 Either -Wlong-long or -Wno-long-long override any other settings.
1431 ??? These conditions should be handled in c.opt. */
1432 if (warn_long_long
== -1)
1434 warn_long_long
= ((pedantic
|| warn_traditional
)
1435 && (c_dialect_cxx () ? cxx_dialect
== cxx98
: !flag_isoc99
));
1436 cpp_opts
->cpp_warn_long_long
= warn_long_long
;
1439 /* If we're generating preprocessor output, emit current directory
1440 if explicitly requested or if debugging information is enabled.
1441 ??? Maybe we should only do it for debugging formats that
1442 actually output the current directory? */
1443 if (flag_working_directory
== -1)
1444 flag_working_directory
= (debug_info_level
!= DINFO_LEVEL_NONE
);
1446 if (warn_implicit_fallthrough
< 5)
1447 cpp_opts
->cpp_warn_implicit_fallthrough
= warn_implicit_fallthrough
;
1449 cpp_opts
->cpp_warn_implicit_fallthrough
= 0;
1451 if (cpp_opts
->directives_only
)
1453 if (cpp_warn_unused_macros
)
1454 error ("%<-fdirectives-only%> is incompatible "
1455 "with %<-Wunused-macros%>");
1456 if (cpp_opts
->traditional
)
1457 error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
1461 /* Add include path with a prefix at the front of its name. */
1463 add_prefixed_path (const char *suffix
, incpath_kind chain
)
1467 size_t prefix_len
, suffix_len
;
1469 suffix_len
= strlen (suffix
);
1470 prefix
= iprefix
? iprefix
: cpp_GCC_INCLUDE_DIR
;
1471 prefix_len
= iprefix
? strlen (iprefix
) : cpp_GCC_INCLUDE_DIR_len
;
1473 path
= (char *) xmalloc (prefix_len
+ suffix_len
+ 1);
1474 memcpy (path
, prefix
, prefix_len
);
1475 memcpy (path
+ prefix_len
, suffix
, suffix_len
);
1476 path
[prefix_len
+ suffix_len
] = '\0';
1478 add_path (path
, chain
, 0, false);
1481 /* Handle -D, -U, -A, -imacros, and the first -include. */
1483 c_finish_options (void)
1485 if (!cpp_opts
->preprocessed
)
1487 const line_map_ordinary
*bltin_map
1488 = linemap_check_ordinary (linemap_add (line_table
, LC_RENAME
, 0,
1489 special_fname_builtin (), 0));
1490 cb_file_change (parse_in
, bltin_map
);
1491 linemap_line_start (line_table
, 0, 1);
1493 /* Make sure all of the builtins about to be declared have
1494 BUILTINS_LOCATION has their location_t. */
1495 cpp_force_token_locations (parse_in
, BUILTINS_LOCATION
);
1497 cpp_init_builtins (parse_in
, flag_hosted
);
1498 c_cpp_builtins (parse_in
);
1500 /* We're about to send user input to cpplib, so make it warn for
1501 things that we previously (when we sent it internal definitions)
1502 told it to not warn.
1504 C99 permits implementation-defined characters in identifiers.
1505 The documented meaning of -std= is to turn off extensions that
1506 conflict with the specified standard, and since a strictly
1507 conforming program cannot contain a '$', we do not condition
1508 their acceptance on the -std= setting. */
1509 cpp_opts
->warn_dollars
= (cpp_opts
->cpp_pedantic
&& !cpp_opts
->c99
);
1511 const line_map_ordinary
*cmd_map
1512 = linemap_check_ordinary (linemap_add (line_table
, LC_RENAME
, 0,
1513 _("<command-line>"), 0));
1514 cb_file_change (parse_in
, cmd_map
);
1515 linemap_line_start (line_table
, 0, 1);
1517 /* All command line defines must have the same location. */
1518 cpp_force_token_locations (parse_in
, line_table
->highest_line
);
1519 for (size_t i
= 0; i
< deferred_count
; i
++)
1521 struct deferred_opt
*opt
= &deferred_opts
[i
];
1523 if (opt
->code
== OPT_D
)
1524 cpp_define (parse_in
, opt
->arg
);
1525 else if (opt
->code
== OPT_U
)
1526 cpp_undef (parse_in
, opt
->arg
);
1527 else if (opt
->code
== OPT_A
)
1529 if (opt
->arg
[0] == '-')
1530 cpp_unassert (parse_in
, opt
->arg
+ 1);
1532 cpp_assert (parse_in
, opt
->arg
);
1536 cpp_stop_forcing_token_locations (parse_in
);
1538 else if (cpp_opts
->directives_only
)
1539 cpp_init_special_builtins (parse_in
);
1541 /* Start the main input file, if the debug writer wants it. */
1542 if (debug_hooks
->start_end_main_source_file
1543 && !flag_preprocess_only
)
1544 (*debug_hooks
->start_source_file
) (0, this_input_filename
);
1546 if (!cpp_opts
->preprocessed
)
1547 /* Handle -imacros after -D and -U. */
1548 for (size_t i
= 0; i
< deferred_count
; i
++)
1550 struct deferred_opt
*opt
= &deferred_opts
[i
];
1552 if (opt
->code
== OPT_imacros
1553 && cpp_push_include (parse_in
, opt
->arg
))
1555 /* Disable push_command_line_include callback for now. */
1556 include_cursor
= deferred_count
+ 1;
1557 cpp_scan_nooutput (parse_in
);
1562 push_command_line_include ();
1565 /* Give CPP the next file given by -include, if any. */
1567 push_command_line_include (void)
1569 /* This can happen if disabled by -imacros for example.
1570 Punt so that we don't set "<command-line>" as the filename for
1572 if (include_cursor
> deferred_count
)
1575 if (!done_preinclude
)
1577 done_preinclude
= true;
1578 if (flag_hosted
&& std_inc
&& !cpp_opts
->preprocessed
)
1580 const char *preinc
= targetcm
.c_preinclude ();
1581 if (preinc
&& cpp_push_default_include (parse_in
, preinc
))
1586 pch_cpp_save_state ();
1588 while (include_cursor
< deferred_count
)
1590 struct deferred_opt
*opt
= &deferred_opts
[include_cursor
++];
1592 if (!cpp_opts
->preprocessed
&& opt
->code
== OPT_include
1593 && cpp_push_include (parse_in
, opt
->arg
))
1597 if (include_cursor
== deferred_count
)
1600 /* -Wunused-macros should only warn about macros defined hereafter. */
1601 cpp_opts
->warn_unused_macros
= cpp_warn_unused_macros
;
1602 /* Restore the line map back to the main file. */
1603 if (!cpp_opts
->preprocessed
)
1605 cpp_change_file (parse_in
, LC_RENAME
, this_input_filename
);
1606 if (lang_hooks
.preprocess_main_file
)
1607 /* We're starting the main file. Inform the FE of that. */
1608 lang_hooks
.preprocess_main_file
1609 (parse_in
, line_table
, LINEMAPS_LAST_ORDINARY_MAP (line_table
));
1612 /* Set this here so the client can change the option if it wishes,
1613 and after stacking the main file so we don't trace the main file. */
1614 line_table
->trace_includes
= cpp_opts
->print_include_names
;
1618 /* File change callback. Has to handle -include files. */
1620 cb_file_change (cpp_reader
*reader
, const line_map_ordinary
*new_map
)
1622 if (flag_preprocess_only
)
1623 pp_file_change (new_map
);
1625 fe_file_change (new_map
);
1627 if (new_map
&& cpp_opts
->preprocessed
1628 && lang_hooks
.preprocess_main_file
&& MAIN_FILE_P (new_map
)
1629 && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map
))
1630 /* We're starting the main file. Inform the FE of that. */
1631 lang_hooks
.preprocess_main_file (reader
, line_table
, new_map
);
1634 && (new_map
->reason
== LC_ENTER
|| new_map
->reason
== LC_RENAME
))
1636 /* Signal to plugins that a file is included. This could happen
1637 several times with the same file path, e.g. because of
1638 several '#include' or '#line' directives... */
1639 invoke_plugin_callbacks
1640 (PLUGIN_INCLUDE_FILE
,
1641 const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map
)));
1644 if (new_map
== 0 || (new_map
->reason
== LC_LEAVE
&& MAIN_FILE_P (new_map
)))
1646 pch_cpp_save_state ();
1647 push_command_line_include ();
1652 cb_dir_change (cpp_reader
* ARG_UNUSED (pfile
), const char *dir
)
1654 if (!set_src_pwd (dir
))
1655 warning (0, "too late for # directive to set debug directory");
1658 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1659 extensions if ISO). There is no concept of gnu94. */
1661 set_std_c89 (int c94
, int iso
)
1663 cpp_set_lang (parse_in
, c94
? CLK_STDC94
: iso
? CLK_STDC89
: CLK_GNUC89
);
1666 flag_no_gnu_keywords
= iso
;
1667 flag_no_nonansi_builtin
= iso
;
1672 lang_hooks
.name
= "GNU C89";
1675 /* Set the C 99 standard (without GNU extensions if ISO). */
1677 set_std_c99 (int iso
)
1679 cpp_set_lang (parse_in
, iso
? CLK_STDC99
: CLK_GNUC99
);
1681 flag_no_nonansi_builtin
= iso
;
1687 lang_hooks
.name
= "GNU C99";
1690 /* Set the C 11 standard (without GNU extensions if ISO). */
1692 set_std_c11 (int iso
)
1694 cpp_set_lang (parse_in
, iso
? CLK_STDC11
: CLK_GNUC11
);
1696 flag_no_nonansi_builtin
= iso
;
1702 lang_hooks
.name
= "GNU C11";
1705 /* Set the C 17 standard (without GNU extensions if ISO). */
1707 set_std_c17 (int iso
)
1709 cpp_set_lang (parse_in
, iso
? CLK_STDC17
: CLK_GNUC17
);
1711 flag_no_nonansi_builtin
= iso
;
1717 lang_hooks
.name
= "GNU C17";
1720 /* Set the C 2X standard (without GNU extensions if ISO). */
1722 set_std_c2x (int iso
)
1724 cpp_set_lang (parse_in
, iso
? CLK_STDC2X
: CLK_GNUC2X
);
1726 flag_no_nonansi_builtin
= iso
;
1732 lang_hooks
.name
= "GNU C2X";
1736 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1738 set_std_cxx98 (int iso
)
1740 cpp_set_lang (parse_in
, iso
? CLK_CXX98
: CLK_GNUCXX
);
1741 flag_no_gnu_keywords
= iso
;
1742 flag_no_nonansi_builtin
= iso
;
1746 cxx_dialect
= cxx98
;
1747 lang_hooks
.name
= "GNU C++98";
1750 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1752 set_std_cxx11 (int iso
)
1754 cpp_set_lang (parse_in
, iso
? CLK_CXX11
: CLK_GNUCXX11
);
1755 flag_no_gnu_keywords
= iso
;
1756 flag_no_nonansi_builtin
= iso
;
1758 /* C++11 includes the C99 standard library. */
1761 cxx_dialect
= cxx11
;
1762 lang_hooks
.name
= "GNU C++11";
1765 /* Set the C++ 2014 standard (without GNU extensions if ISO). */
1767 set_std_cxx14 (int iso
)
1769 cpp_set_lang (parse_in
, iso
? CLK_CXX14
: CLK_GNUCXX14
);
1770 flag_no_gnu_keywords
= iso
;
1771 flag_no_nonansi_builtin
= iso
;
1773 /* C++14 includes the C99 standard library. */
1776 cxx_dialect
= cxx14
;
1777 lang_hooks
.name
= "GNU C++14";
1780 /* Set the C++ 2017 standard (without GNU extensions if ISO). */
1782 set_std_cxx17 (int iso
)
1784 cpp_set_lang (parse_in
, iso
? CLK_CXX17
: CLK_GNUCXX17
);
1785 flag_no_gnu_keywords
= iso
;
1786 flag_no_nonansi_builtin
= iso
;
1788 /* C++17 includes the C11 standard library. */
1792 cxx_dialect
= cxx17
;
1793 lang_hooks
.name
= "GNU C++17";
1796 /* Set the C++ 2020 standard (without GNU extensions if ISO). */
1798 set_std_cxx20 (int iso
)
1800 cpp_set_lang (parse_in
, iso
? CLK_CXX20
: CLK_GNUCXX20
);
1801 flag_no_gnu_keywords
= iso
;
1802 flag_no_nonansi_builtin
= iso
;
1804 /* C++20 includes the C11 standard library. */
1808 /* C++20 includes coroutines. */
1809 flag_coroutines
= true;
1810 cxx_dialect
= cxx20
;
1811 lang_hooks
.name
= "GNU C++20";
1814 /* Set the C++ 2023 standard (without GNU extensions if ISO). */
1816 set_std_cxx23 (int iso
)
1818 cpp_set_lang (parse_in
, iso
? CLK_CXX23
: CLK_GNUCXX23
);
1819 flag_no_gnu_keywords
= iso
;
1820 flag_no_nonansi_builtin
= iso
;
1822 /* C++23 includes the C11 standard library. */
1826 /* C++23 includes coroutines. */
1827 flag_coroutines
= true;
1828 cxx_dialect
= cxx23
;
1829 lang_hooks
.name
= "GNU C++23";
1832 /* Set the C++ 2026 standard (without GNU extensions if ISO). */
1834 set_std_cxx26 (int iso
)
1836 cpp_set_lang (parse_in
, iso
? CLK_CXX26
: CLK_GNUCXX26
);
1837 flag_no_gnu_keywords
= iso
;
1838 flag_no_nonansi_builtin
= iso
;
1840 /* C++26 includes the C11 standard library. */
1844 /* C++26 includes coroutines. */
1845 flag_coroutines
= true;
1846 cxx_dialect
= cxx26
;
1847 lang_hooks
.name
= "GNU C++26";
1850 /* Args to -d specify what to dump. Silently ignore
1851 unrecognized options; they may be aimed at toplev.cc. */
1853 handle_OPT_d (const char *arg
)
1857 while ((c
= *arg
++) != '\0')
1860 case 'M': /* Dump macros only. */
1861 case 'N': /* Dump names. */
1862 case 'D': /* Dump definitions. */
1863 case 'U': /* Dump used macros. */
1864 flag_dump_macros
= c
;
1868 flag_dump_includes
= 1;