Branch data Line data Source code
1 : : /* C/ObjC/C++ command line option handling.
2 : : Copyright (C) 2002-2025 Free Software Foundation, Inc.
3 : : Contributed by Neil Booth.
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "tm.h"
25 : : #include "target.h"
26 : : #include "c-target.h"
27 : : #include "c-common.h"
28 : : #include "memmodel.h"
29 : : #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
30 : : #include "diagnostic.h"
31 : : #include "c-pragma.h"
32 : : #include "flags.h"
33 : : #include "toplev.h"
34 : : #include "langhooks.h"
35 : : #include "diagnostics/macro-unwinding.h" /* for virt_loc_aware_diagnostic_finalizer */
36 : : #include "intl.h"
37 : : #include "cppdefault.h"
38 : : #include "incpath.h"
39 : : #include "debug.h" /* For debug_hooks. */
40 : : #include "opts.h"
41 : : #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
42 : : #include "mkdeps.h"
43 : : #include "dumpfile.h"
44 : : #include "file-prefix-map.h" /* add_*_prefix_map() */
45 : : #include "context.h"
46 : : #include "diagnostics/text-sink.h"
47 : :
48 : : #ifndef DOLLARS_IN_IDENTIFIERS
49 : : # define DOLLARS_IN_IDENTIFIERS true
50 : : #endif
51 : :
52 : : #ifndef TARGET_SYSTEM_ROOT
53 : : # define TARGET_SYSTEM_ROOT NULL
54 : : #endif
55 : :
56 : : #ifndef TARGET_OPTF
57 : : #define TARGET_OPTF(ARG)
58 : : #endif
59 : :
60 : : /* CPP's options. */
61 : : cpp_options *cpp_opts;
62 : :
63 : : /* Input filename. */
64 : : static const char *this_input_filename;
65 : :
66 : : /* Filename and stream for preprocessed output. */
67 : : static const char *out_fname;
68 : : static FILE *out_stream;
69 : :
70 : : /* Append dependencies to deps_file. */
71 : : static bool deps_append;
72 : :
73 : : /* If dependency switches (-MF etc.) have been given. */
74 : : static bool deps_seen;
75 : :
76 : : /* If -v seen. */
77 : : static bool verbose;
78 : :
79 : : /* Dependency output file. */
80 : : static const char *deps_file;
81 : :
82 : : /* Structured dependency output file. */
83 : : static const char *fdeps_file;
84 : :
85 : : /* The prefix given by -iprefix, if any. */
86 : : static const char *iprefix;
87 : :
88 : : /* The multilib directory given by -imultilib, if any. */
89 : : static const char *imultilib;
90 : :
91 : : /* The system root, if any. Overridden by -isysroot. */
92 : : static const char *sysroot = TARGET_SYSTEM_ROOT;
93 : :
94 : : /* Zero disables all standard directories for headers. */
95 : : static bool std_inc = true;
96 : :
97 : : /* Zero disables the C++-specific standard directories for headers. */
98 : : static bool std_cxx_inc = true;
99 : :
100 : : /* If the quote chain has been split by -I-. */
101 : : static bool quote_chain_split;
102 : :
103 : : /* Number of deferred options. */
104 : : static size_t deferred_count;
105 : :
106 : : /* Number of deferred options scanned for -include. */
107 : : static size_t include_cursor;
108 : :
109 : : /* Whether any standard preincluded header has been preincluded. */
110 : : static bool done_preinclude;
111 : :
112 : : static void handle_OPT_d (const char *);
113 : : static void set_std_cxx98 (int);
114 : : static void set_std_cxx11 (int);
115 : : static void set_std_cxx14 (int);
116 : : static void set_std_cxx17 (int);
117 : : static void set_std_cxx20 (int);
118 : : static void set_std_cxx23 (int);
119 : : static void set_std_cxx26 (int);
120 : : static void set_std_c89 (int, int);
121 : : static void set_std_c99 (int);
122 : : static void set_std_c11 (int);
123 : : static void set_std_c17 (int);
124 : : static void set_std_c23 (int);
125 : : static void set_std_c2y (int);
126 : : static void check_deps_environment_vars (void);
127 : : static void handle_deferred_opts (void);
128 : : static void sanitize_cpp_opts (void);
129 : : static void add_prefixed_path (const char *, incpath_kind);
130 : : static void push_command_line_include (void);
131 : : static void cb_file_change (cpp_reader *, const line_map_ordinary *);
132 : : static void cb_dir_change (cpp_reader *, const char *);
133 : : static void c_finish_options (void);
134 : :
135 : : #ifndef STDC_0_IN_SYSTEM_HEADERS
136 : : #define STDC_0_IN_SYSTEM_HEADERS 0
137 : : #endif
138 : :
139 : : /* Holds switches parsed by c_common_handle_option (), but whose
140 : : handling is deferred to c_common_post_options (). */
141 : : static void defer_opt (enum opt_code, const char *);
142 : : static struct deferred_opt
143 : : {
144 : : enum opt_code code;
145 : : const char *arg;
146 : : } *deferred_opts;
147 : :
148 : :
149 : : extern const unsigned int
150 : : c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
151 : :
152 : : /* Defer option CODE with argument ARG. */
153 : : static void
154 : 181527 : defer_opt (enum opt_code code, const char *arg)
155 : : {
156 : 181527 : deferred_opts[deferred_count].code = code;
157 : 181527 : deferred_opts[deferred_count].arg = arg;
158 : 181527 : deferred_count++;
159 : 181527 : }
160 : :
161 : : /* Return language mask for option parsing. */
162 : : unsigned int
163 : 5941201 : c_common_option_lang_mask (void)
164 : : {
165 : 5941201 : static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
166 : :
167 : 5941201 : return lang_flags[c_language];
168 : : }
169 : :
170 : : /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
171 : : static void
172 : 311592 : c_diagnostic_text_finalizer (diagnostics::text_sink &text_output,
173 : : const diagnostics::diagnostic_info *diagnostic,
174 : : enum diagnostics::kind)
175 : : {
176 : 311592 : pretty_printer *const pp = text_output.get_printer ();
177 : 311592 : char *saved_prefix = pp_take_prefix (pp);
178 : 311592 : pp_set_prefix (pp, text_output.build_indent_prefix (false));
179 : 311592 : pp_newline (pp);
180 : 311592 : diagnostic_show_locus (&text_output.get_context (),
181 : 311592 : text_output.get_source_printing_options (),
182 : 311592 : diagnostic->m_richloc, diagnostic->m_kind, pp);
183 : : /* By default print macro expansion contexts in the diagnostic
184 : : finalizer -- for tokens resulting from macro expansion. */
185 : 311592 : diagnostics::virt_loc_aware_text_finalizer (text_output, diagnostic);
186 : 311592 : pp_set_prefix (pp, saved_prefix);
187 : 311592 : pp_flush (pp);
188 : 311592 : }
189 : :
190 : : /* Common default settings for diagnostics. */
191 : : void
192 : 207045 : c_common_diagnostics_set_defaults (diagnostics::context *context)
193 : : {
194 : 207045 : diagnostics::text_finalizer (context) = c_diagnostic_text_finalizer;
195 : 207045 : context->set_permissive_option (OPT_fpermissive);
196 : 207045 : }
197 : :
198 : : /* Input charset configuration for diagnostics. */
199 : : static const char *
200 : 60949 : c_common_input_charset_cb (const char * /*filename*/)
201 : : {
202 : 60949 : const char *cs = cpp_opts->input_charset;
203 : 60949 : return cpp_input_conversion_is_trivial (cs) ? nullptr : cs;
204 : : }
205 : :
206 : : /* Whether options from all C-family languages should be accepted
207 : : quietly. */
208 : : static bool accept_all_c_family_options = false;
209 : :
210 : : /* Return whether to complain about a wrong-language option. */
211 : : bool
212 : 292 : c_common_complain_wrong_lang_p (const struct cl_option *option)
213 : : {
214 : 292 : if (accept_all_c_family_options
215 : 6 : && (option->flags & c_family_lang_mask))
216 : 6 : return false;
217 : :
218 : : return true;
219 : : }
220 : :
221 : : /* Initialize options structure OPTS. */
222 : : void
223 : 47214397 : c_common_init_options_struct (struct gcc_options *opts)
224 : : {
225 : 47214397 : opts->x_flag_exceptions = c_dialect_cxx ();
226 : 47214397 : opts->x_warn_pointer_arith = c_dialect_cxx ();
227 : 47214397 : opts->x_warn_write_strings = c_dialect_cxx ();
228 : 47214397 : opts->x_flag_warn_unused_result = true;
229 : :
230 : : /* By default, C99-like requirements for complex multiply and divide. */
231 : 47214397 : opts->x_flag_complex_method = 2;
232 : 47214397 : opts->x_flag_default_complex_method = opts->x_flag_complex_method;
233 : 47214397 : }
234 : :
235 : : /* Common initialization before calling option handlers. */
236 : : void
237 : 207045 : c_common_init_options (unsigned int decoded_options_count,
238 : : struct cl_decoded_option *decoded_options)
239 : : {
240 : 207045 : unsigned int i;
241 : 207045 : struct cpp_callbacks *cb;
242 : :
243 : 207045 : g_string_concat_db
244 : 207045 : = new (ggc_alloc <string_concat_db> ()) string_concat_db ();
245 : :
246 : 317105 : parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX : CLK_GNUC89,
247 : : ident_hash, line_table, ident_hash_extra);
248 : 207045 : cb = cpp_get_callbacks (parse_in);
249 : 207045 : cb->diagnostic = c_cpp_diagnostic;
250 : :
251 : 207045 : cpp_opts = cpp_get_options (parse_in);
252 : 207045 : cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
253 : 207045 : cpp_opts->objc = c_dialect_objc ();
254 : 207045 : cpp_opts->deps.modules = true;
255 : :
256 : : /* Reset to avoid warnings on internal definitions. We set it just
257 : : before passing on command-line options to cpplib. */
258 : 207045 : cpp_opts->warn_dollars = 0;
259 : :
260 : 207045 : deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
261 : :
262 : 207045 : if (c_language == clk_c)
263 : : {
264 : : /* The default for C is gnu23. */
265 : 110060 : set_std_c23 (false /* ISO */);
266 : :
267 : : /* If preprocessing assembly language, accept any of the C-family
268 : : front end options since the driver may pass them through. */
269 : 2809836 : for (i = 1; i < decoded_options_count; i++)
270 : 2590697 : if (decoded_options[i].opt_index == OPT_lang_asm)
271 : : {
272 : 981 : accept_all_c_family_options = true;
273 : 981 : break;
274 : : }
275 : : }
276 : :
277 : : /* Set C++ standard to C++17 if not specified on the command line. */
278 : 207045 : if (c_dialect_cxx ())
279 : 96985 : set_std_cxx17 (/*ISO*/false);
280 : :
281 : 207045 : global_dc->get_source_printing_options ().colorize_source_p = true;
282 : 207045 : }
283 : :
284 : : /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
285 : : form of an -f or -W option was given. Returns false if the switch was
286 : : invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
287 : : bool
288 : 3305839 : c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
289 : : int kind, location_t loc,
290 : : const struct cl_option_handlers *handlers)
291 : : {
292 : 3305839 : const struct cl_option *option = &cl_options[scode];
293 : 3305839 : enum opt_code code = (enum opt_code) scode;
294 : 3305839 : bool result = true;
295 : :
296 : : /* Prevent resetting the language standard to a C dialect when the driver
297 : : has already determined that we're looking at assembler input. */
298 : 3305839 : bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
299 : :
300 : 3305839 : switch (code)
301 : : {
302 : 1425427 : default:
303 : 1425427 : if (cl_options[code].flags & c_family_lang_mask)
304 : : {
305 : 1425427 : if ((option->flags & CL_TARGET)
306 : 1425427 : && ! targetcm.handle_c_option (scode, arg, value))
307 : : result = false;
308 : : break;
309 : : }
310 : : result = false;
311 : : break;
312 : :
313 : 435 : case OPT__output_pch:
314 : 435 : pch_file = arg;
315 : 435 : break;
316 : :
317 : 10 : case OPT_A:
318 : 10 : defer_opt (code, arg);
319 : 10 : break;
320 : :
321 : 13 : case OPT_C:
322 : 13 : cpp_opts->discard_comments = 0;
323 : 13 : break;
324 : :
325 : 11 : case OPT_CC:
326 : 11 : cpp_opts->discard_comments = 0;
327 : 11 : cpp_opts->discard_comments_in_macro_exp = 0;
328 : 11 : break;
329 : :
330 : 165429 : case OPT_D:
331 : 165429 : defer_opt (code, arg);
332 : 165429 : break;
333 : :
334 : 24 : case OPT_H:
335 : 24 : cpp_opts->print_include_names = 1;
336 : 24 : break;
337 : :
338 : : case OPT_F:
339 : : TARGET_OPTF (xstrdup (arg));
340 : : break;
341 : :
342 : 548839 : case OPT_I:
343 : 548839 : if (strcmp (arg, "-"))
344 : 548839 : add_path (xstrdup (arg), INC_BRACKET, 0, true);
345 : : else
346 : : {
347 : 0 : if (quote_chain_split)
348 : 0 : error ("%<-I-%> specified twice");
349 : 0 : quote_chain_split = true;
350 : 0 : split_quote_chain ();
351 : 0 : inform (input_location, "obsolete option %<-I-%> used, "
352 : : "please use %<-iquote%> instead");
353 : : }
354 : : break;
355 : :
356 : 25 : case OPT_M:
357 : 25 : case OPT_MM:
358 : : /* When doing dependencies with -M or -MM, suppress normal
359 : : preprocessed output, but still do -dM etc. as software
360 : : depends on this. Preprocessed output does occur if -MD, -MMD
361 : : or environment var dependency generation is used. */
362 : 25 : cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM : DEPS_USER);
363 : 25 : flag_no_output = 1;
364 : 25 : break;
365 : :
366 : 5832 : case OPT_MD:
367 : 5832 : case OPT_MMD:
368 : 5832 : cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM : DEPS_USER);
369 : 5832 : cpp_opts->deps.need_preprocessor_output = true;
370 : 5832 : deps_file = arg;
371 : 5832 : break;
372 : :
373 : 51 : case OPT_fdeps_format_:
374 : : /* https://wg21.link/p1689r5 */
375 : 51 : if (!strcmp (arg, "p1689r5"))
376 : 48 : cpp_opts->deps.fdeps_format = FDEPS_FMT_P1689R5;
377 : : else
378 : 3 : error ("%<-fdeps-format=%> unknown format %qs", arg);
379 : : break;
380 : :
381 : 63 : case OPT_fdeps_file_:
382 : 63 : deps_seen = true;
383 : 63 : fdeps_file = arg;
384 : 63 : break;
385 : :
386 : 63 : case OPT_fdeps_target_:
387 : 63 : deps_seen = true;
388 : 63 : defer_opt (code, arg);
389 : 63 : break;
390 : :
391 : 5776 : case OPT_MF:
392 : 5776 : deps_seen = true;
393 : 5776 : deps_file = arg;
394 : 5776 : break;
395 : :
396 : 3 : case OPT_MG:
397 : 3 : deps_seen = true;
398 : 3 : cpp_opts->deps.missing_files = true;
399 : 3 : break;
400 : :
401 : 5761 : case OPT_MP:
402 : 5761 : deps_seen = true;
403 : 5761 : cpp_opts->deps.phony_targets = true;
404 : 5761 : break;
405 : :
406 : 0 : case OPT_Mmodules:
407 : : /* Do not set deps_seen, so the user can unconditionally turn
408 : : this on or off. */
409 : 0 : cpp_opts->deps.modules = true;
410 : 0 : break;
411 : :
412 : 3 : case OPT_Mno_modules:
413 : : /* Do not set deps_seen, so the user can unconditionally turn
414 : : this on or off. */
415 : 3 : cpp_opts->deps.modules = false;
416 : 3 : break;
417 : :
418 : 5828 : case OPT_MQ:
419 : 5828 : case OPT_MT:
420 : 5828 : deps_seen = true;
421 : 5828 : defer_opt (code, arg);
422 : 5828 : break;
423 : :
424 : 43 : case OPT_P:
425 : 43 : flag_no_line_commands = 1;
426 : 43 : break;
427 : :
428 : 61 : case OPT_U:
429 : 61 : defer_opt (code, arg);
430 : 61 : break;
431 : :
432 : 10867 : case OPT_Wall:
433 : : /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
434 : :
435 : 10867 : cpp_opts->warn_num_sign_change = value;
436 : 10867 : break;
437 : :
438 : 10949 : case OPT_Wunknown_pragmas:
439 : : /* Set to greater than 1, so that even unknown pragmas in
440 : : system headers will be warned about. */
441 : : /* ??? There is no way to handle this automatically for now. */
442 : 10949 : warn_unknown_pragmas = value * 2;
443 : 10949 : break;
444 : :
445 : 3943 : case OPT_ansi:
446 : 3943 : if (!c_dialect_cxx ())
447 : 3797 : set_std_c89 (false, true);
448 : : else
449 : 146 : set_std_cxx98 (true);
450 : : break;
451 : :
452 : 1649 : case OPT_d:
453 : 1649 : handle_OPT_d (arg);
454 : 1649 : break;
455 : :
456 : 13865 : case OPT_Wabi_:
457 : 13865 : warn_abi = true;
458 : 13865 : if (value == 1)
459 : : {
460 : 0 : warning (0, "%<-Wabi=1%> is not supported, using =2");
461 : 0 : value = 2;
462 : : }
463 : 13865 : warn_abi_version = value;
464 : 13865 : break;
465 : :
466 : 18 : case OPT_fcanonical_system_headers:
467 : 18 : cpp_opts->canonical_system_headers = value;
468 : 18 : break;
469 : :
470 : 12 : case OPT_fcond_mismatch:
471 : 12 : if (!c_dialect_cxx ())
472 : : {
473 : 12 : flag_cond_mismatch = value;
474 : 12 : break;
475 : : }
476 : 0 : warning (0, "switch %qs is no longer supported", option->opt_text);
477 : 0 : break;
478 : :
479 : 308 : case OPT_fbuiltin_:
480 : 308 : if (value)
481 : : result = false;
482 : : else
483 : 308 : disable_builtin_function (arg);
484 : : break;
485 : :
486 : 1090 : case OPT_fdirectives_only:
487 : 1090 : cpp_opts->directives_only = value;
488 : 1090 : break;
489 : :
490 : 7 : case OPT_fdollars_in_identifiers:
491 : 7 : cpp_opts->dollars_in_ident = value;
492 : 7 : break;
493 : :
494 : 8 : case OPT_fmacro_prefix_map_:
495 : 8 : add_macro_prefix_map (arg);
496 : 8 : break;
497 : :
498 : 1031 : case OPT_ffreestanding:
499 : 1031 : value = !value;
500 : : /* Fall through. */
501 : 1039 : case OPT_fhosted:
502 : 1039 : flag_hosted = value;
503 : 1039 : flag_no_builtin = !value;
504 : 1039 : break;
505 : :
506 : 0 : case OPT_fconstant_string_class_:
507 : 0 : constant_string_class_name = arg;
508 : 0 : break;
509 : :
510 : 0 : case OPT_fextended_identifiers:
511 : 0 : cpp_opts->extended_identifiers = value;
512 : 0 : break;
513 : :
514 : 4 : case OPT_fmax_include_depth_:
515 : 4 : cpp_opts->max_include_depth = value;
516 : 4 : break;
517 : :
518 : 4 : case OPT_foperator_names:
519 : 4 : cpp_opts->operator_names = value;
520 : 4 : break;
521 : :
522 : 0 : case OPT_fpch_deps:
523 : 0 : cpp_opts->restore_pch_deps = value;
524 : 0 : break;
525 : :
526 : 475 : case OPT_fpch_preprocess:
527 : 475 : flag_pch_preprocess = value;
528 : 475 : break;
529 : :
530 : 1151 : case OPT_fpermissive:
531 : 1151 : flag_permissive = value;
532 : 1151 : global_dc->m_permissive = value;
533 : 1151 : break;
534 : :
535 : 525 : case OPT_fpreprocessed:
536 : 525 : cpp_opts->preprocessed = value;
537 : 525 : break;
538 : :
539 : 2 : case OPT_fdebug_cpp:
540 : 2 : cpp_opts->debug = value;
541 : 2 : break;
542 : :
543 : 1 : case OPT_ftrack_macro_expansion:
544 : 1 : if (value)
545 : 0 : value = 2;
546 : : /* Fall Through. */
547 : :
548 : 483 : case OPT_ftrack_macro_expansion_:
549 : 483 : if (arg && *arg != '\0')
550 : 482 : cpp_opts->track_macro_expansion = value;
551 : : else
552 : 1 : cpp_opts->track_macro_expansion = 2;
553 : : break;
554 : :
555 : 85 : case OPT_fexec_charset_:
556 : 85 : cpp_opts->narrow_charset = arg;
557 : 85 : break;
558 : :
559 : 2 : case OPT_fwide_exec_charset_:
560 : 2 : cpp_opts->wide_charset = arg;
561 : 2 : break;
562 : :
563 : 93 : case OPT_finput_charset_:
564 : 93 : cpp_opts->input_charset = arg;
565 : 93 : cpp_opts->cpp_input_charset_explicit = 1;
566 : 93 : break;
567 : :
568 : 28 : case OPT_ftemplate_depth_:
569 : 28 : max_tinst_depth = value;
570 : 28 : break;
571 : :
572 : 21 : case OPT_fvisibility_inlines_hidden:
573 : 21 : visibility_options.inlines_hidden = value;
574 : 21 : break;
575 : :
576 : 22 : case OPT_femit_struct_debug_baseonly:
577 : 22 : set_struct_debug_option (&global_options, loc, "base");
578 : 22 : break;
579 : :
580 : 8 : case OPT_femit_struct_debug_reduced:
581 : 8 : set_struct_debug_option (&global_options, loc,
582 : : "dir:ord:sys,dir:gen:any,ind:base");
583 : 8 : break;
584 : :
585 : 12 : case OPT_femit_struct_debug_detailed_:
586 : 12 : set_struct_debug_option (&global_options, loc, arg);
587 : 12 : break;
588 : :
589 : 17 : case OPT_fext_numeric_literals:
590 : 17 : cpp_opts->ext_numeric_literals = value;
591 : 17 : break;
592 : :
593 : 4 : case OPT_idirafter:
594 : 4 : add_path (xstrdup (arg), INC_AFTER, 0, true);
595 : 4 : break;
596 : :
597 : 10136 : case OPT_imacros:
598 : 10136 : case OPT_include:
599 : 10136 : defer_opt (code, arg);
600 : 10136 : break;
601 : :
602 : 5310 : case OPT_imultilib:
603 : 5310 : imultilib = arg;
604 : 5310 : break;
605 : :
606 : 203712 : case OPT_iprefix:
607 : 203712 : iprefix = arg;
608 : 203712 : break;
609 : :
610 : 2862 : case OPT_iquote:
611 : 2862 : add_path (xstrdup (arg), INC_QUOTE, 0, true);
612 : 2862 : break;
613 : :
614 : 0 : case OPT_isysroot:
615 : 0 : sysroot = arg;
616 : 0 : break;
617 : :
618 : 460303 : case OPT_isystem:
619 : 460303 : add_path (xstrdup (arg), INC_SYSTEM, 0, true);
620 : 460303 : break;
621 : :
622 : 0 : case OPT_iwithprefix:
623 : 0 : add_prefixed_path (arg, INC_SYSTEM);
624 : 0 : break;
625 : :
626 : 0 : case OPT_iwithprefixbefore:
627 : 0 : add_prefixed_path (arg, INC_BRACKET);
628 : 0 : break;
629 : :
630 : 81 : case OPT__embed_dir_:
631 : 81 : add_path (xstrdup (arg), INC_EMBED, 0, true);
632 : 81 : break;
633 : :
634 : 981 : case OPT_lang_asm:
635 : 981 : cpp_set_lang (parse_in, CLK_ASM);
636 : 981 : cpp_opts->dollars_in_ident = false;
637 : 981 : break;
638 : :
639 : 60 : case OPT_nostdinc:
640 : 60 : std_inc = false;
641 : 60 : break;
642 : :
643 : 110144 : case OPT_nostdinc__:
644 : 110144 : std_cxx_inc = false;
645 : 110144 : break;
646 : :
647 : 206328 : case OPT_o:
648 : 206328 : if (!out_fname)
649 : 206328 : out_fname = arg;
650 : : else
651 : 0 : error ("output filename specified twice");
652 : : break;
653 : :
654 : 0 : case OPT_print_objc_runtime_info:
655 : 0 : print_struct_values = 1;
656 : 0 : break;
657 : :
658 : 2 : case OPT_remap:
659 : 2 : cpp_opts->remap = 1;
660 : 2 : break;
661 : :
662 : 13976 : case OPT_std_c__98:
663 : 13976 : case OPT_std_gnu__98:
664 : 13976 : if (!preprocessing_asm_p)
665 : 13976 : set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
666 : : break;
667 : :
668 : 5599 : case OPT_std_c__11:
669 : 5599 : case OPT_std_gnu__11:
670 : 5599 : if (!preprocessing_asm_p)
671 : 5599 : set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
672 : : break;
673 : :
674 : 1278 : case OPT_std_c__14:
675 : 1278 : case OPT_std_gnu__14:
676 : 1278 : if (!preprocessing_asm_p)
677 : 1278 : set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
678 : : break;
679 : :
680 : 30522 : case OPT_std_c__17:
681 : 30522 : case OPT_std_gnu__17:
682 : 30522 : if (!preprocessing_asm_p)
683 : 30522 : set_std_cxx17 (code == OPT_std_c__17 /* ISO */);
684 : : break;
685 : :
686 : 5009 : case OPT_std_c__20:
687 : 5009 : case OPT_std_gnu__20:
688 : 5009 : if (!preprocessing_asm_p)
689 : 5009 : set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
690 : : break;
691 : :
692 : 1926 : case OPT_std_c__23:
693 : 1926 : case OPT_std_gnu__23:
694 : 1926 : if (!preprocessing_asm_p)
695 : 1926 : set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
696 : : break;
697 : :
698 : 23597 : case OPT_std_c__26:
699 : 23597 : case OPT_std_gnu__26:
700 : 23597 : if (!preprocessing_asm_p)
701 : 23597 : set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
702 : : break;
703 : :
704 : 190 : case OPT_std_c90:
705 : 190 : case OPT_std_iso9899_199409:
706 : 190 : if (!preprocessing_asm_p)
707 : 190 : set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
708 : : break;
709 : :
710 : 2952 : case OPT_std_gnu90:
711 : 2952 : if (!preprocessing_asm_p)
712 : 2952 : set_std_c89 (false /* c94 */, false /* ISO */);
713 : : break;
714 : :
715 : 574 : case OPT_std_c99:
716 : 574 : if (!preprocessing_asm_p)
717 : 573 : set_std_c99 (true /* ISO */);
718 : : break;
719 : :
720 : 609 : case OPT_std_gnu99:
721 : 609 : if (!preprocessing_asm_p)
722 : 609 : set_std_c99 (false /* ISO */);
723 : : break;
724 : :
725 : 509 : case OPT_std_c11:
726 : 509 : if (!preprocessing_asm_p)
727 : 509 : set_std_c11 (true /* ISO */);
728 : : break;
729 : :
730 : 3690 : case OPT_std_gnu11:
731 : 3690 : if (!preprocessing_asm_p)
732 : 3690 : set_std_c11 (false /* ISO */);
733 : : break;
734 : :
735 : 42 : case OPT_std_c17:
736 : 42 : if (!preprocessing_asm_p)
737 : 42 : set_std_c17 (true /* ISO */);
738 : : break;
739 : :
740 : 785 : case OPT_std_gnu17:
741 : 785 : if (!preprocessing_asm_p)
742 : 785 : set_std_c17 (false /* ISO */);
743 : : break;
744 : :
745 : 843 : case OPT_std_c23:
746 : 843 : if (!preprocessing_asm_p)
747 : 843 : set_std_c23 (true /* ISO */);
748 : : break;
749 : :
750 : 199 : case OPT_std_gnu23:
751 : 199 : if (!preprocessing_asm_p)
752 : 199 : set_std_c23 (false /* ISO */);
753 : : break;
754 : :
755 : 165 : case OPT_std_c2y:
756 : 165 : if (!preprocessing_asm_p)
757 : 165 : set_std_c2y (true /* ISO */);
758 : : break;
759 : :
760 : 8 : case OPT_std_gnu2y:
761 : 8 : if (!preprocessing_asm_p)
762 : 8 : set_std_c2y (false /* ISO */);
763 : : break;
764 : :
765 : 20 : case OPT_trigraphs:
766 : 20 : cpp_opts->trigraphs = 1;
767 : 20 : break;
768 : :
769 : 2927 : case OPT_traditional_cpp:
770 : 2927 : cpp_opts->traditional = 1;
771 : 2927 : break;
772 : :
773 : 0 : case OPT_fsearch_include_path:
774 : 0 : cpp_opts->main_search = CMS_user;
775 : 0 : break;
776 : :
777 : 0 : case OPT_fsearch_include_path_:
778 : 0 : if (!strcmp (arg, "user"))
779 : 0 : cpp_opts->main_search = CMS_user;
780 : 0 : else if (!strcmp (arg, "system"))
781 : 0 : cpp_opts->main_search = CMS_system;
782 : : else
783 : 0 : error ("invalid argument %qs to %<-fsearch-include-path%>", arg);
784 : : break;
785 : :
786 : 112 : case OPT_v:
787 : 112 : verbose = true;
788 : 112 : break;
789 : : }
790 : :
791 : 3305839 : switch (c_language)
792 : : {
793 : 1414780 : case clk_c:
794 : 1414780 : C_handle_option_auto (&global_options, &global_options_set,
795 : : scode, arg, value,
796 : : c_family_lang_mask, kind,
797 : : loc, handlers, global_dc);
798 : 1414780 : break;
799 : :
800 : 0 : case clk_objc:
801 : 0 : ObjC_handle_option_auto (&global_options, &global_options_set,
802 : : scode, arg, value,
803 : : c_family_lang_mask, kind,
804 : : loc, handlers, global_dc);
805 : 0 : break;
806 : :
807 : 1891059 : case clk_cxx:
808 : 1891059 : CXX_handle_option_auto (&global_options, &global_options_set,
809 : : scode, arg, value,
810 : : c_family_lang_mask, kind,
811 : : loc, handlers, global_dc);
812 : 1891059 : break;
813 : :
814 : 0 : case clk_objcxx:
815 : 0 : ObjCXX_handle_option_auto (&global_options, &global_options_set,
816 : : scode, arg, value,
817 : : c_family_lang_mask, kind,
818 : : loc, handlers, global_dc);
819 : 0 : break;
820 : :
821 : 0 : default:
822 : 0 : gcc_unreachable ();
823 : : }
824 : :
825 : 3305839 : cpp_handle_option_auto (&global_options, scode, cpp_opts);
826 : 3305839 : return result;
827 : : }
828 : :
829 : : /* Default implementation of TARGET_HANDLE_C_OPTION. */
830 : :
831 : : bool
832 : 0 : default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
833 : : const char *arg ATTRIBUTE_UNUSED,
834 : : int value ATTRIBUTE_UNUSED)
835 : : {
836 : 0 : return false;
837 : : }
838 : :
839 : : /* Post-switch processing. */
840 : : bool
841 : 206965 : c_common_post_options (const char **pfilename)
842 : : {
843 : : /* Canonicalize the input and output filenames. */
844 : 206965 : if (in_fnames == NULL)
845 : : {
846 : 0 : in_fnames = XNEWVEC (const char *, 1);
847 : 0 : in_fnames[0] = "";
848 : : }
849 : 206965 : else if (strcmp (in_fnames[0], "-") == 0)
850 : : {
851 : 407 : if (pch_file)
852 : 0 : error ("cannot use %<-%> as input filename for a precompiled header");
853 : :
854 : 407 : in_fnames[0] = "";
855 : : }
856 : :
857 : 206965 : if (out_fname == NULL || !strcmp (out_fname, "-"))
858 : 717 : out_fname = "";
859 : :
860 : 206965 : if (cpp_opts->deps.style == DEPS_NONE)
861 : 201108 : check_deps_environment_vars ();
862 : :
863 : 206965 : handle_deferred_opts ();
864 : :
865 : 206965 : sanitize_cpp_opts ();
866 : :
867 : 206965 : register_include_chains (parse_in, sysroot, iprefix, imultilib,
868 : 206965 : std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
869 : :
870 : : #ifdef C_COMMON_OVERRIDE_OPTIONS
871 : : /* Some machines may reject certain combinations of C
872 : : language-specific options. */
873 : : C_COMMON_OVERRIDE_OPTIONS;
874 : : #endif
875 : :
876 : 206965 : if (flag_excess_precision == EXCESS_PRECISION_DEFAULT)
877 : 354056 : flag_excess_precision = (flag_iso ? EXCESS_PRECISION_STANDARD
878 : : : EXCESS_PRECISION_FAST);
879 : :
880 : : /* ISO C restricts floating-point expression contraction to within
881 : : source-language expressions (-ffp-contract=on, currently an alias
882 : : for -ffp-contract=off). */
883 : 206965 : if (flag_iso
884 : 56712 : && !c_dialect_cxx ()
885 : 6110 : && (OPTION_SET_P (flag_fp_contract_mode)
886 : : == (enum fp_contract_mode) 0)
887 : 6110 : && flag_unsafe_math_optimizations == 0)
888 : 6105 : flag_fp_contract_mode = FP_CONTRACT_OFF;
889 : :
890 : : /* C language modes before C99 enable -fpermissive by default, but
891 : : only if -pedantic-errors is not specified. Also treat
892 : : -fno-permissive as a subset of -pedantic-errors that does not
893 : : reject certain GNU extensions also present the defaults for later
894 : : language modes. */
895 : 206965 : if (!c_dialect_cxx ()
896 : 109981 : && !flag_isoc99
897 : 6930 : && !global_dc->m_pedantic_errors
898 : 5936 : && !OPTION_SET_P (flag_permissive))
899 : : {
900 : 5935 : flag_permissive = 1;
901 : 5935 : global_dc->m_permissive = 1;
902 : : }
903 : :
904 : : /* If we are compiling C, and we are outside of a standards mode,
905 : : we can permit the new values from ISO/IEC TS 18661-3 for
906 : : FLT_EVAL_METHOD. Otherwise, we must restrict the possible values to
907 : : the set specified in ISO C99/C11. */
908 : 206965 : if (!flag_iso
909 : 150253 : && !c_dialect_cxx ()
910 : 103871 : && (OPTION_SET_P (flag_permitted_flt_eval_methods)
911 : : == PERMITTED_FLT_EVAL_METHODS_DEFAULT))
912 : 103870 : flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_TS_18661;
913 : : else
914 : 103095 : flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
915 : :
916 : : /* C23 Annex F does not permit certain built-in functions to raise
917 : : "inexact". */
918 : 206965 : if (flag_isoc23)
919 : 96843 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
920 : : flag_fp_int_builtin_inexact, 0);
921 : :
922 : : /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
923 : : inline semantics are not supported in GNU89 or C89 mode. */
924 : 206965 : if (flag_gnu89_inline == -1)
925 : 206527 : flag_gnu89_inline = !flag_isoc99;
926 : 438 : else if (!flag_gnu89_inline && !flag_isoc99)
927 : 1 : error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
928 : :
929 : : /* Default to ObjC sjlj exception handling if NeXT runtime < v2. */
930 : 206965 : if (flag_objc_sjlj_exceptions < 0)
931 : 413930 : flag_objc_sjlj_exceptions = (flag_next_runtime && flag_objc_abi < 2);
932 : 206965 : if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
933 : 0 : flag_exceptions = 1;
934 : :
935 : : /* If -ffreestanding, -fno-hosted or -fno-builtin then disable
936 : : pattern recognition. */
937 : 206965 : if (flag_no_builtin)
938 : 767 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
939 : : flag_tree_loop_distribute_patterns, 0);
940 : :
941 : : /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
942 : : It is never enabled in C++, as the minimum limit is not normative
943 : : in that standard. */
944 : 206965 : if (c_dialect_cxx ())
945 : 96984 : warn_overlength_strings = 0;
946 : :
947 : : /* Wmain is enabled by default in C++ but not in C. */
948 : : /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
949 : : even if -Wall or -Wpedantic was given (warn_main will be 2 if set
950 : : by -Wall, 1 if set by -Wmain). */
951 : 206965 : if (warn_main == -1)
952 : 250376 : warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
953 : 55419 : else if (warn_main == 2)
954 : 55098 : warn_main = flag_hosted ? 1 : 0;
955 : :
956 : : /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not
957 : : yet been set, it is disabled by default. In C++, it is enabled
958 : : by default. */
959 : 206965 : if (warn_enum_compare == -1)
960 : 197498 : warn_enum_compare = c_dialect_cxx () ? 1 : 0;
961 : :
962 : : /* For C++26 default to -Wkeyword-macro if -Wpedantic. */
963 : 206965 : if (cxx_dialect >= cxx26 && pedantic)
964 : : {
965 : 14035 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
966 : : warn_keyword_macro, 1);
967 : 14035 : if (warn_keyword_macro)
968 : 14034 : cpp_opts->cpp_warn_keyword_macro = warn_keyword_macro;
969 : : }
970 : :
971 : : /* -Wpacked-bitfield-compat is on by default for the C languages. The
972 : : warning is issued in stor-layout.cc which is not part of the front-end so
973 : : we need to selectively turn it on here. */
974 : 206965 : if (warn_packed_bitfield_compat == -1)
975 : 206957 : warn_packed_bitfield_compat = 1;
976 : :
977 : : /* Special format checking options don't work without -Wformat; warn if
978 : : they are used. */
979 : 206965 : if (!warn_format)
980 : : {
981 : 195750 : warning (OPT_Wformat_y2k,
982 : : "%<-Wformat-y2k%> ignored without %<-Wformat%>");
983 : 195750 : warning (OPT_Wformat_extra_args,
984 : : "%<-Wformat-extra-args%> ignored without %<-Wformat%>");
985 : 195750 : warning (OPT_Wformat_zero_length,
986 : : "%<-Wformat-zero-length%> ignored without %<-Wformat%>");
987 : 195750 : warning (OPT_Wformat_nonliteral,
988 : : "%<-Wformat-nonliteral%> ignored without %<-Wformat%>");
989 : 195750 : warning (OPT_Wformat_contains_nul,
990 : : "%<-Wformat-contains-nul%> ignored without %<-Wformat%>");
991 : 195750 : warning (OPT_Wformat_security,
992 : : "%<-Wformat-security%> ignored without %<-Wformat%>");
993 : : }
994 : :
995 : : /* -Wimplicit-function-declaration is enabled by default for C99. */
996 : 206965 : if (warn_implicit_function_declaration == -1)
997 : 198642 : warn_implicit_function_declaration = flag_isoc99;
998 : :
999 : : /* -Wimplicit-int is enabled by default for C99. */
1000 : 206965 : if (warn_implicit_int == -1)
1001 : 198700 : warn_implicit_int = flag_isoc99;
1002 : :
1003 : : /* -Wold-style-definition is enabled by default for C23. */
1004 : 206965 : if (warn_old_style_definition == -1)
1005 : 202675 : warn_old_style_definition = flag_isoc23;
1006 : :
1007 : : /* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
1008 : 206965 : if (warn_shift_overflow == -1)
1009 : 392846 : warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
1010 : :
1011 : : /* -Wmissing-parameter-name is enabled by -pedantic before C23,
1012 : : and for -Wc11-c23-compat. */
1013 : 206965 : if (warn_missing_parameter_name == -1)
1014 : 206962 : warn_missing_parameter_name
1015 : 46867 : = ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
1016 : 253874 : || warn_c11_c23_compat > 0);
1017 : :
1018 : : /* Likewise for -Wfree-labels. */
1019 : 206965 : if (warn_free_labels == -1)
1020 : 46867 : warn_free_labels = ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
1021 : 253874 : || warn_c11_c23_compat > 0);
1022 : :
1023 : 206965 : if (warn_deprecated_non_prototype == -1)
1024 : 206960 : warn_deprecated_non_prototype = warn_c11_c23_compat > 0;
1025 : :
1026 : : /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
1027 : : modes. */
1028 : 206965 : if (warn_shift_negative_value == -1)
1029 : 413890 : warn_shift_negative_value = (extra_warnings
1030 : 7761 : && (cxx_dialect >= cxx11 || flag_isoc99)
1031 : 414019 : && cxx_dialect < cxx20);
1032 : :
1033 : : /* -Wregister is enabled by default in C++17. */
1034 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_register,
1035 : : cxx_dialect >= cxx17);
1036 : :
1037 : : /* Explicit -Wdeprecated turns on warnings from later standards. */
1038 : 1619280 : auto deprecated_in = [&](enum cxx_dialect d)
1039 : : {
1040 : 1412315 : if (OPTION_SET_P (warn_deprecated)) return !!warn_deprecated;
1041 : 1410721 : return (warn_deprecated && cxx_dialect >= d);
1042 : : };
1043 : :
1044 : : /* -Wcomma-subscript is enabled by default in C++20. */
1045 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1046 : : warn_comma_subscript,
1047 : : cxx_dialect >= cxx23
1048 : : || deprecated_in (cxx20));
1049 : :
1050 : : /* -Wvolatile is enabled by default in C++20. */
1051 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, warn_volatile,
1052 : : deprecated_in (cxx20));
1053 : :
1054 : : /* -Wdeprecated-enum-enum-conversion is enabled by default in C++20. */
1055 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1056 : : warn_deprecated_enum_enum_conv,
1057 : : deprecated_in (cxx20));
1058 : :
1059 : : /* -Wdeprecated-enum-float-conversion is enabled by default in C++20. */
1060 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1061 : : warn_deprecated_enum_float_conv,
1062 : : deprecated_in (cxx20));
1063 : :
1064 : : /* -Wdeprecated-literal-operator is enabled by default in C++23. */
1065 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1066 : : warn_deprecated_literal_operator,
1067 : : deprecated_in (cxx23));
1068 : :
1069 : : /* -Warray-compare is enabled by default in C++20. */
1070 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1071 : : warn_array_compare,
1072 : : warn_array_compare || deprecated_in (cxx20));
1073 : :
1074 : : /* -Wdeprecated-variadic-comma-omission is enabled by default in C++26. */
1075 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1076 : : warn_deprecated_variadic_comma_omission,
1077 : : deprecated_in (cxx26));
1078 : :
1079 : : /* -Wtemplate-id-cdtor is enabled by default in C++20. */
1080 : 239515 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1081 : : warn_template_id_cdtor,
1082 : : cxx_dialect >= cxx20 || warn_cxx20_compat);
1083 : :
1084 : : /* Declone C++ 'structors if -Os. */
1085 : 206965 : if (flag_declone_ctor_dtor == -1)
1086 : 206928 : flag_declone_ctor_dtor = optimize_size;
1087 : :
1088 : 206965 : if (flag_abi_compat_version == 1)
1089 : : {
1090 : 0 : warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
1091 : 0 : flag_abi_compat_version = 2;
1092 : : }
1093 : :
1094 : : /* Change flag_abi_version to be the actual current ABI level, for the
1095 : : benefit of c_cpp_builtins, and to make comparison simpler. */
1096 : 206965 : const int latest_abi_version = 21;
1097 : : /* Possibly different for non-default ABI fixes within a release. */
1098 : 206965 : const int default_abi_version = latest_abi_version;
1099 : : /* Generate compatibility aliases for ABI v18 (GCC 13) by default. */
1100 : 206965 : const int abi_compat_default = 18;
1101 : :
1102 : 206965 : if (flag_abi_version > latest_abi_version)
1103 : 0 : warning (0, "%<-fabi-version=%d%> is not supported, using =%d",
1104 : : flag_abi_version, latest_abi_version);
1105 : :
1106 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1107 : : flag_abi_version, default_abi_version);
1108 : :
1109 : : #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
1110 : 206965 : clamp (flag_abi_version);
1111 : : /* Don't clamp warn_abi_version, let it be 0 or out of bounds. */
1112 : 206965 : clamp (flag_abi_compat_version);
1113 : : #undef clamp
1114 : :
1115 : : /* Default -Wabi= or -fabi-compat-version= from each other. */
1116 : 206965 : if (warn_abi_version == -1 && flag_abi_compat_version != -1)
1117 : 192 : warn_abi_version = flag_abi_compat_version;
1118 : 206773 : else if (flag_abi_compat_version == -1 && warn_abi_version != -1)
1119 : 13818 : flag_abi_compat_version = warn_abi_version;
1120 : 192955 : else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
1121 : : {
1122 : 192910 : warn_abi_version = 0;
1123 : 192910 : if (flag_abi_version == default_abi_version)
1124 : 192675 : flag_abi_compat_version = abi_compat_default;
1125 : : else
1126 : 235 : flag_abi_compat_version = latest_abi_version;
1127 : : }
1128 : :
1129 : : /* Allow warnings vs ABI versions beyond what we currently support. */
1130 : 206965 : if (warn_abi_version == 0)
1131 : 192925 : warn_abi_version = 1000;
1132 : :
1133 : : /* By default, enable the new inheriting constructor semantics along with ABI
1134 : : 11. New and old should coexist fine, but it is a change in what
1135 : : artificial symbols are generated. */
1136 : 413674 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1137 : : flag_new_inheriting_ctors,
1138 : : abi_version_at_least (11));
1139 : :
1140 : : /* For GCC 7, only enable DR150 resolution by default if -std=c++17. */
1141 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_new_ttp,
1142 : : cxx_dialect >= cxx17);
1143 : :
1144 : : /* C++11 guarantees forward progress. */
1145 : 387289 : SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
1146 : : optimize >= 2 && cxx_dialect >= cxx11);
1147 : :
1148 : : /* It's OK to discard calls to pure/const functions that might throw. */
1149 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1150 : : flag_delete_dead_exceptions, true);
1151 : :
1152 : 206965 : if (cxx_dialect >= cxx11)
1153 : : {
1154 : : /* If we're allowing C++0x constructs, don't warn about C++98
1155 : : identifiers which are keywords in C++0x. */
1156 : 82932 : warn_cxx11_compat = 0;
1157 : 82932 : cpp_opts->cpp_warn_cxx11_compat = 0;
1158 : :
1159 : 82932 : if (warn_narrowing == -1)
1160 : 80764 : warn_narrowing = 1;
1161 : :
1162 : : /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
1163 : : for -std=c++{11,14,17,20,23,26} default to
1164 : : -fno-ext-numeric-literals. */
1165 : 82932 : if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
1166 : 41818 : cpp_opts->ext_numeric_literals = 0;
1167 : : }
1168 : 124033 : else if (warn_narrowing == -1)
1169 : 123545 : warn_narrowing = 0;
1170 : :
1171 : 206965 : if (cxx_dialect >= cxx20)
1172 : : {
1173 : : /* Don't warn about C++20 compatibility changes in C++20 or later. */
1174 : 30482 : warn_cxx20_compat = 0;
1175 : 30482 : cpp_opts->cpp_warn_cxx20_compat = 0;
1176 : : }
1177 : 206965 : if (cxx_dialect >= cxx26)
1178 : : /* Don't warn about C++26 compatibility changes in C++26 or later. */
1179 : 23551 : warn_cxx26_compat = 0;
1180 : :
1181 : : /* C++17 has stricter evaluation order requirements; let's use some of them
1182 : : for earlier C++ as well, so chaining works as expected. */
1183 : 206965 : if (c_dialect_cxx ()
1184 : 96984 : && flag_strong_eval_order == -1)
1185 : 117864 : flag_strong_eval_order = (cxx_dialect >= cxx17 ? 2 : 1);
1186 : :
1187 : 206965 : if (flag_implicit_constexpr && cxx_dialect < cxx14)
1188 : 0 : flag_implicit_constexpr = false;
1189 : :
1190 : : /* Global sized deallocation is new in C++14. */
1191 : 206965 : if (flag_sized_deallocation == -1)
1192 : 206961 : flag_sized_deallocation = (cxx_dialect >= cxx14);
1193 : :
1194 : : /* Pedwarn about invalid constexpr functions before C++23. */
1195 : 206965 : if (warn_invalid_constexpr == -1)
1196 : 206949 : warn_invalid_constexpr = (cxx_dialect < cxx23);
1197 : :
1198 : : /* char8_t support is implicitly enabled in C++20 and C23. */
1199 : 206965 : if (flag_char8_t == -1)
1200 : 334164 : flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc23;
1201 : 206965 : cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char;
1202 : :
1203 : 206965 : cpp_opts->cpp_tabstop = global_dc->get_column_options ().m_tabstop;
1204 : :
1205 : 206965 : if (flag_extern_tls_init)
1206 : : {
1207 : 206963 : if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
1208 : : {
1209 : : /* Lazy TLS initialization for a variable in another TU requires
1210 : : alias and weak reference support. */
1211 : : if (flag_extern_tls_init > 0)
1212 : : sorry ("external TLS initialization functions not supported "
1213 : : "on this target");
1214 : :
1215 : : flag_extern_tls_init = 0;
1216 : : }
1217 : : else
1218 : 206963 : flag_extern_tls_init = 1;
1219 : : }
1220 : :
1221 : : /* Enable by default only for C++ and C++ with ObjC extensions. */
1222 : 206965 : if (warn_return_type == -1 && c_dialect_cxx ())
1223 : 93483 : warn_return_type = 1;
1224 : :
1225 : : /* C++20 is the final version of concepts. We still use -fconcepts
1226 : : to know when concepts are enabled. */
1227 : 206965 : if (cxx_dialect >= cxx20)
1228 : 30482 : flag_concepts = 1;
1229 : :
1230 : : /* Coroutines are also a C++20 feature. */
1231 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1232 : : flag_coroutines, cxx_dialect >= cxx20);
1233 : :
1234 : : /* Enable lifetime extension of range based for temporaries for C++23. */
1235 : 206965 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1236 : : flag_range_for_ext_temps, cxx_dialect >= cxx23);
1237 : :
1238 : : /* EnabledBy unfortunately can't specify value to use if set and
1239 : : LangEnabledBy can't specify multiple options with &&. For -Wunused
1240 : : or -Wunused -Wextra we want these to default to 3 unless user specified
1241 : : some other level explicitly. */
1242 : 206965 : if (warn_unused_but_set_parameter == 1)
1243 : 7605 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1244 : : warn_unused_but_set_parameter, 3);
1245 : 206965 : if (warn_unused_but_set_variable == 1)
1246 : 10407 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
1247 : : warn_unused_but_set_variable, 3);
1248 : :
1249 : : /* -fimmediate-escalation has no effect when immediate functions are not
1250 : : supported. */
1251 : 206965 : if (flag_immediate_escalation && cxx_dialect < cxx20)
1252 : 176483 : flag_immediate_escalation = 0;
1253 : :
1254 : 206965 : if (num_in_fnames > 1)
1255 : 0 : error ("too many filenames given; type %<%s %s%> for usage",
1256 : : progname, "--help");
1257 : :
1258 : 206965 : if (flag_preprocess_only)
1259 : : {
1260 : : /* Open the output now. We must do so even if flag_no_output is
1261 : : on, because there may be other output than from the actual
1262 : : preprocessing (e.g. from -dM). */
1263 : 6836 : if (out_fname[0] == '\0')
1264 : 717 : out_stream = stdout;
1265 : : else
1266 : 6119 : out_stream = fopen (out_fname, "w");
1267 : :
1268 : 6836 : if (out_stream == NULL)
1269 : 0 : fatal_error (input_location, "opening output file %s: %m", out_fname);
1270 : :
1271 : 6836 : init_pp_output (out_stream);
1272 : : }
1273 : : else
1274 : : {
1275 : 200129 : init_c_lex ();
1276 : :
1277 : : /* When writing a PCH file, avoid reading some other PCH file,
1278 : : because the default address space slot then can't be used
1279 : : for the output PCH file. */
1280 : 200129 : if (pch_file)
1281 : : {
1282 : 435 : c_common_no_more_pch ();
1283 : : /* Only -g0 and -gdwarf* are supported with PCH, for other
1284 : : debug formats we warn here and refuse to load any PCH files. */
1285 : 435 : if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1286 : 0 : warning (OPT_Wdeprecated,
1287 : : "the %qs debug info cannot be used with "
1288 : : "pre-compiled headers",
1289 : : debug_set_names (write_symbols & ~DWARF2_DEBUG));
1290 : : /* Let libcpp know that the main file is a header so it won't
1291 : : complain about things like #include_next and #pragma once. */
1292 : 435 : cpp_opts->main_search = CMS_header;
1293 : : }
1294 : 199694 : else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
1295 : 356 : c_common_no_more_pch ();
1296 : :
1297 : : /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1298 : 200129 : input_location = UNKNOWN_LOCATION;
1299 : : }
1300 : :
1301 : 206965 : struct cpp_callbacks *cb = cpp_get_callbacks (parse_in);
1302 : 206965 : cb->file_change = cb_file_change;
1303 : 206965 : cb->dir_change = cb_dir_change;
1304 : 206965 : if (lang_hooks.preprocess_options)
1305 : 96984 : lang_hooks.preprocess_options (parse_in);
1306 : 206965 : cpp_post_options (parse_in);
1307 : 206965 : init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
1308 : : /* For C++23 and explicit -finput-charset=UTF-8, turn on -Winvalid-utf8
1309 : : by default and make it a pedwarn unless -Wno-invalid-utf8. */
1310 : 206965 : if (cxx_dialect >= cxx23
1311 : 25475 : && cpp_opts->cpp_input_charset_explicit
1312 : 23 : && strcmp (cpp_opts->input_charset, "UTF-8") == 0
1313 : 21 : && (cpp_opts->cpp_warn_invalid_utf8
1314 : 16 : || !global_options_set.x_warn_invalid_utf8))
1315 : : {
1316 : 18 : global_options.x_warn_invalid_utf8 = 1;
1317 : 28 : cpp_opts->cpp_warn_invalid_utf8 = cpp_opts->cpp_pedantic ? 2 : 1;
1318 : : }
1319 : :
1320 : : /* Let diagnostics infrastructure know how to convert input files the same
1321 : : way libcpp will do it, namely using the configured input charset and
1322 : : skipping a UTF-8 BOM if present. */
1323 : 206965 : diagnostic_initialize_input_context (global_dc,
1324 : : c_common_input_charset_cb, true);
1325 : 206965 : input_location = UNKNOWN_LOCATION;
1326 : :
1327 : 413930 : *pfilename = this_input_filename
1328 : 413930 : = cpp_read_main_file (parse_in, in_fnames[0],
1329 : : /* We'll inject preamble pieces if this is
1330 : : not preprocessed. */
1331 : 206965 : !cpp_opts->preprocessed);
1332 : :
1333 : : /* Don't do any compilation or preprocessing if there is no input file. */
1334 : 206965 : if (this_input_filename == NULL)
1335 : : {
1336 : 0 : errorcount++;
1337 : 0 : return false;
1338 : : }
1339 : :
1340 : 206965 : if (flag_working_directory
1341 : 42822 : && flag_preprocess_only && !flag_no_line_commands)
1342 : 2352 : pp_dir_change (parse_in, get_src_pwd ());
1343 : :
1344 : : /* Disable LTO output when outputting a precompiled header. */
1345 : 206965 : if (pch_file && flag_lto)
1346 : : {
1347 : 0 : flag_lto = 0;
1348 : 0 : flag_generate_lto = 0;
1349 : : }
1350 : :
1351 : 206965 : return flag_preprocess_only;
1352 : : }
1353 : :
1354 : : /* Front end initialization common to C, ObjC and C++. */
1355 : : bool
1356 : 206755 : c_common_init (void)
1357 : : {
1358 : : /* Set up preprocessor arithmetic. Must be done after call to
1359 : : c_common_nodes_and_builtins for type nodes to be good. */
1360 : 206755 : cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1361 : 206755 : cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1362 : 206755 : cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1363 : 206755 : cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1364 : 206755 : cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1365 : 206755 : cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1366 : :
1367 : : /* This can't happen until after wchar_precision and bytes_big_endian
1368 : : are known. */
1369 : 206755 : cpp_init_iconv (parse_in);
1370 : :
1371 : 206755 : if (version_flag)
1372 : : {
1373 : 109 : int i;
1374 : 109 : fputs ("Compiler executable checksum: ", stderr);
1375 : 1962 : for (i = 0; i < 16; i++)
1376 : 1744 : fprintf (stderr, "%02x", executable_checksum[i]);
1377 : 109 : putc ('\n', stderr);
1378 : : }
1379 : :
1380 : : /* Has to wait until now so that cpplib has its hash table. */
1381 : 206755 : init_pragma ();
1382 : :
1383 : 206755 : if (flag_preprocess_only)
1384 : : {
1385 : 6831 : c_init_preprocess ();
1386 : 6831 : c_finish_options ();
1387 : 6831 : preprocess_file (parse_in);
1388 : 6831 : return false;
1389 : : }
1390 : :
1391 : : return true;
1392 : : }
1393 : :
1394 : : /* Initialize the integrated preprocessor after debug output has been
1395 : : initialized; loop over each input file. */
1396 : : void
1397 : 199924 : c_common_parse_file (void)
1398 : : {
1399 : 199924 : auto dumps = g->get_dumps ();
1400 : 199924 : for (unsigned int i = 0;;)
1401 : : {
1402 : 199924 : c_finish_options ();
1403 : : /* Open the dump file to use for the original dump output
1404 : : here, to be used during parsing for the current file. */
1405 : 199924 : dumps->dump_start (TDI_original, &dump_flags);
1406 : 199924 : pch_init ();
1407 : 199924 : push_file_scope ();
1408 : 199924 : c_parse_file ();
1409 : 199634 : pop_file_scope ();
1410 : : /* And end the main input file, if the debug writer wants it */
1411 : 199634 : if (debug_hooks->start_end_main_source_file)
1412 : 40285 : (*debug_hooks->end_source_file) (0);
1413 : 199634 : if (++i >= num_in_fnames)
1414 : : break;
1415 : 0 : cpp_undef_all (parse_in);
1416 : 0 : cpp_clear_file_cache (parse_in);
1417 : 0 : this_input_filename
1418 : 0 : = cpp_read_main_file (parse_in, in_fnames[i]);
1419 : : /* If an input file is missing, abandon further compilation.
1420 : : cpplib has issued a diagnostic. */
1421 : 0 : if (!this_input_filename)
1422 : : break;
1423 : 0 : dumps->dump_finish (TDI_original);
1424 : : }
1425 : :
1426 : 199634 : c_parse_final_cleanups ();
1427 : 199622 : dumps->dump_finish (TDI_original);
1428 : 199622 : }
1429 : :
1430 : : /* Common finish hook for the C, ObjC and C++ front ends. */
1431 : : void
1432 : 206259 : c_common_finish (void)
1433 : : {
1434 : 206259 : FILE *deps_stream = NULL;
1435 : 206259 : FILE *fdeps_stream = NULL;
1436 : :
1437 : : /* Note that we write the dependencies even if there are errors. This is
1438 : : useful for handling outdated generated headers that now trigger errors
1439 : : (for example, with #error) which would be resolved by re-generating
1440 : : them. In a sense, this complements -MG. */
1441 : 206259 : if (cpp_opts->deps.style != DEPS_NONE)
1442 : : {
1443 : : /* If -M or -MM was seen without -MF, default output to the
1444 : : output stream. */
1445 : 5852 : if (!deps_file)
1446 : 22 : deps_stream = out_stream;
1447 : 5830 : else if (deps_file[0] == '-' && deps_file[1] == '\0')
1448 : 0 : deps_stream = stdout;
1449 : : else
1450 : : {
1451 : 11660 : deps_stream = fopen (deps_file, deps_append ? "a" : "w");
1452 : 5830 : if (!deps_stream)
1453 : 0 : fatal_error (input_location, "opening dependency file %s: %m",
1454 : : deps_file);
1455 : : }
1456 : : }
1457 : :
1458 : : /* When we call cpp_finish (), it may generate some diagnostics using
1459 : : locations it remembered from the preprocessing phase, e.g. for
1460 : : -Wunused-macros. So inform c_cpp_diagnostic () not to override those
1461 : : locations with input_location, which would be incorrect now. */
1462 : 206259 : override_libcpp_locations = false;
1463 : :
1464 : 206259 : if (cpp_opts->deps.fdeps_format != FDEPS_FMT_NONE)
1465 : : {
1466 : 36 : if (!fdeps_file)
1467 : 0 : fdeps_stream = out_stream;
1468 : 36 : else if (fdeps_file[0] == '-' && fdeps_file[1] == '\0')
1469 : 0 : fdeps_stream = stdout;
1470 : : else
1471 : : {
1472 : 36 : fdeps_stream = fopen (fdeps_file, "w");
1473 : 36 : if (!fdeps_stream)
1474 : 0 : fatal_error (input_location, "opening dependency file %s: %m",
1475 : : fdeps_file);
1476 : : }
1477 : 36 : if (fdeps_stream == deps_stream && fdeps_stream != stdout)
1478 : 0 : fatal_error (input_location, "%<-MF%> and %<-fdeps-file=%> cannot share an output file %s: %m",
1479 : : fdeps_file);
1480 : : }
1481 : :
1482 : : /* For performance, avoid tearing down cpplib's internal structures
1483 : : with cpp_destroy (). */
1484 : 206259 : cpp_finish (parse_in, deps_stream, fdeps_stream);
1485 : :
1486 : 5852 : if (deps_stream && deps_stream != out_stream && deps_stream != stdout
1487 : 212089 : && (ferror (deps_stream) || fclose (deps_stream)))
1488 : 0 : fatal_error (input_location, "closing dependency file %s: %m", deps_file);
1489 : :
1490 : 206259 : if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1491 : 0 : fatal_error (input_location, "when writing output to %s: %m", out_fname);
1492 : 206259 : }
1493 : :
1494 : : /* Either of two environment variables can specify output of
1495 : : dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1496 : : DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1497 : : and DEPS_TARGET is the target to mention in the deps. They also
1498 : : result in dependency information being appended to the output file
1499 : : rather than overwriting it, and like Sun's compiler
1500 : : SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1501 : : static void
1502 : 201108 : check_deps_environment_vars (void)
1503 : : {
1504 : 201108 : char *spec;
1505 : :
1506 : 201108 : spec = getenv ("DEPENDENCIES_OUTPUT");
1507 : 201108 : if (spec)
1508 : 0 : cpp_opts->deps.style = DEPS_USER;
1509 : : else
1510 : : {
1511 : 201108 : spec = getenv ("SUNPRO_DEPENDENCIES");
1512 : 201108 : if (spec)
1513 : : {
1514 : 0 : cpp_opts->deps.style = DEPS_SYSTEM;
1515 : 0 : cpp_opts->deps.ignore_main_file = true;
1516 : : }
1517 : : }
1518 : :
1519 : 0 : if (spec)
1520 : : {
1521 : : /* Find the space before the DEPS_TARGET, if there is one. */
1522 : 0 : char *s = strchr (spec, ' ');
1523 : 0 : if (s)
1524 : : {
1525 : : /* Let the caller perform MAKE quoting. */
1526 : 0 : defer_opt (OPT_MT, s + 1);
1527 : 0 : *s = '\0';
1528 : : }
1529 : :
1530 : : /* Command line -MF overrides environment variables and default. */
1531 : 0 : if (!deps_file)
1532 : 0 : deps_file = spec;
1533 : :
1534 : 0 : deps_append = 1;
1535 : 0 : deps_seen = true;
1536 : : }
1537 : 201108 : }
1538 : :
1539 : : /* Handle deferred command line switches. */
1540 : : static void
1541 : 206965 : handle_deferred_opts (void)
1542 : : {
1543 : : /* Avoid allocating the deps buffer if we don't need it.
1544 : : (This flag may be true without there having been -MT or -MQ
1545 : : options, but we'll still need the deps buffer.) */
1546 : 206965 : if (!deps_seen)
1547 : : return;
1548 : :
1549 : 5859 : if (mkdeps *deps = cpp_get_deps (parse_in))
1550 : 34804 : for (unsigned i = 0; i < deferred_count; i++)
1551 : : {
1552 : 28969 : struct deferred_opt *opt = &deferred_opts[i];
1553 : :
1554 : 28969 : if (opt->code == OPT_MT || opt->code == OPT_MQ)
1555 : 5828 : deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1556 : 23141 : else if (opt->code == OPT_fdeps_target_)
1557 : 42 : fdeps_add_target (deps, opt->arg, true);
1558 : : }
1559 : : }
1560 : :
1561 : : /* These settings are appropriate for GCC, but not necessarily so for
1562 : : cpplib as a library. */
1563 : : static void
1564 : 206965 : sanitize_cpp_opts (void)
1565 : : {
1566 : : /* If we don't know what style of dependencies to output, complain
1567 : : if any other dependency switches have been given. */
1568 : 206965 : if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1569 : 24 : error ("to generate dependencies you must specify either %<-M%> "
1570 : : "or %<-MM%>");
1571 : :
1572 : : /* -dM and dependencies suppress normal output; do it here so that
1573 : : the last -d[MDN] switch overrides earlier ones. */
1574 : 206965 : if (flag_dump_macros == 'M')
1575 : 80 : flag_no_output = 1;
1576 : :
1577 : : /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1578 : : to perform proper macro expansion. */
1579 : 206965 : if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1580 : 68 : flag_dump_macros = 'D';
1581 : :
1582 : : /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1583 : : -dM since at least glibc relies on -M -dM to work. */
1584 : : /* Also, flag_no_output implies flag_no_line_commands, always. */
1585 : 206965 : if (flag_no_output)
1586 : : {
1587 : 104 : if (flag_dump_macros != 'M')
1588 : 24 : flag_dump_macros = 0;
1589 : 104 : flag_dump_includes = 0;
1590 : 104 : flag_no_line_commands = 1;
1591 : : }
1592 : 206861 : else if (cpp_opts->deps.missing_files)
1593 : 1 : error ("%<-MG%> may only be used with %<-M%> or %<-MM%>");
1594 : :
1595 : 206965 : cpp_opts->unsigned_char = !flag_signed_char;
1596 : 206965 : cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1597 : :
1598 : : /* Wlong-long is disabled by default. It is enabled by:
1599 : : [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1600 : : [-Wpedantic | -Wtraditional] -std=non-c99
1601 : :
1602 : : Either -Wlong-long or -Wno-long-long override any other settings.
1603 : : ??? These conditions should be handled in c.opt. */
1604 : 206965 : if (warn_long_long == -1)
1605 : : {
1606 : 159343 : warn_long_long = ((pedantic || warn_traditional)
1607 : 163023 : && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1608 : 162999 : cpp_opts->cpp_warn_long_long = warn_long_long;
1609 : : }
1610 : :
1611 : : /* If we're generating preprocessor output, emit current directory
1612 : : if explicitly requested or if debugging information is enabled.
1613 : : ??? Maybe we should only do it for debugging formats that
1614 : : actually output the current directory? */
1615 : 206965 : if (flag_working_directory == -1)
1616 : 205563 : flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1617 : :
1618 : 206965 : if (warn_implicit_fallthrough < 5)
1619 : 206961 : cpp_opts->cpp_warn_implicit_fallthrough = warn_implicit_fallthrough;
1620 : : else
1621 : 4 : cpp_opts->cpp_warn_implicit_fallthrough = 0;
1622 : :
1623 : 206965 : if (cpp_opts->directives_only)
1624 : : {
1625 : 109 : if (cpp_warn_unused_macros)
1626 : 4 : error ("%<-fdirectives-only%> is incompatible "
1627 : : "with %<-Wunused-macros%>");
1628 : 109 : if (cpp_opts->traditional)
1629 : 1 : error ("%<-fdirectives-only%> is incompatible with %<-traditional%>");
1630 : : }
1631 : 206965 : }
1632 : :
1633 : : /* Add include path with a prefix at the front of its name. */
1634 : : static void
1635 : 0 : add_prefixed_path (const char *suffix, incpath_kind chain)
1636 : : {
1637 : 0 : char *path;
1638 : 0 : const char *prefix;
1639 : 0 : size_t prefix_len, suffix_len;
1640 : :
1641 : 0 : suffix_len = strlen (suffix);
1642 : 0 : prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1643 : 0 : prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1644 : :
1645 : 0 : path = (char *) xmalloc (prefix_len + suffix_len + 1);
1646 : 0 : memcpy (path, prefix, prefix_len);
1647 : 0 : memcpy (path + prefix_len, suffix, suffix_len);
1648 : 0 : path[prefix_len + suffix_len] = '\0';
1649 : :
1650 : 0 : add_path (path, chain, 0, false);
1651 : 0 : }
1652 : :
1653 : : /* Handle -D, -U, -A, -imacros, and the first -include. */
1654 : : static void
1655 : 206755 : c_finish_options (void)
1656 : : {
1657 : 206755 : if (!cpp_opts->preprocessed)
1658 : : {
1659 : 206230 : const line_map_ordinary *bltin_map
1660 : 206230 : = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1661 : : special_fname_builtin (), 0));
1662 : 206230 : cb_file_change (parse_in, bltin_map);
1663 : 206230 : linemap_line_start (line_table, 0, 1);
1664 : :
1665 : : /* Make sure all of the builtins about to be declared have
1666 : : BUILTINS_LOCATION has their location_t. */
1667 : 206230 : cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
1668 : :
1669 : 206230 : cpp_init_builtins (parse_in, flag_hosted);
1670 : 206230 : c_cpp_builtins (parse_in);
1671 : :
1672 : : /* We're about to send user input to cpplib, so make it warn for
1673 : : things that we previously (when we sent it internal definitions)
1674 : : told it to not warn.
1675 : :
1676 : : C99 permits implementation-defined characters in identifiers.
1677 : : The documented meaning of -std= is to turn off extensions that
1678 : : conflict with the specified standard, and since a strictly
1679 : : conforming program cannot contain a '$', we do not condition
1680 : : their acceptance on the -std= setting. */
1681 : 206230 : cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1682 : :
1683 : 206230 : const line_map_ordinary *cmd_map
1684 : 206230 : = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1685 : 206230 : _("<command-line>"), 0));
1686 : 206230 : cb_file_change (parse_in, cmd_map);
1687 : 206230 : linemap_line_start (line_table, 0, 1);
1688 : :
1689 : 206230 : bool fortify_seen_p = false;
1690 : 206230 : bool cxx_assert_seen_p = false;
1691 : :
1692 : : /* All command line defines must have the same location. */
1693 : 206230 : cpp_force_token_locations (parse_in, line_table->highest_line);
1694 : 387595 : for (size_t i = 0; i < deferred_count; i++)
1695 : : {
1696 : 181365 : struct deferred_opt *opt = &deferred_opts[i];
1697 : :
1698 : 181365 : if (opt->code == OPT_D)
1699 : 165289 : cpp_define (parse_in, opt->arg);
1700 : 16076 : else if (opt->code == OPT_U)
1701 : 61 : cpp_undef (parse_in, opt->arg);
1702 : 16015 : else if (opt->code == OPT_A)
1703 : : {
1704 : 10 : if (opt->arg[0] == '-')
1705 : 2 : cpp_unassert (parse_in, opt->arg + 1);
1706 : : else
1707 : 8 : cpp_assert (parse_in, opt->arg);
1708 : : }
1709 : :
1710 : 181365 : if (UNLIKELY (flag_hardened)
1711 : 83 : && (opt->code == OPT_D || opt->code == OPT_U))
1712 : : {
1713 : 83 : if (!fortify_seen_p)
1714 : 79 : fortify_seen_p
1715 : 79 : = (!strncmp (opt->arg, "_FORTIFY_SOURCE", 15)
1716 : 79 : && (opt->arg[15] == '\0' || opt->arg[15] == '='));
1717 : 83 : if (!cxx_assert_seen_p)
1718 : 83 : cxx_assert_seen_p
1719 : 83 : = (!strncmp (opt->arg, "_GLIBCXX_ASSERTIONS", 19)
1720 : 83 : && (opt->arg[19] == '\0' || opt->arg[19] == '='));
1721 : : }
1722 : : }
1723 : :
1724 : 206230 : if (flag_hardened)
1725 : : {
1726 : 91 : if (!fortify_seen_p && optimize > 0)
1727 : 71 : cpp_define_formatted (parse_in, "_FORTIFY_SOURCE=%u",
1728 : 71 : targetm.fortify_source_default_level ());
1729 : 20 : else if (optimize == 0)
1730 : 20 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1731 : : "%<_FORTIFY_SOURCE%> is not enabled by %<-fhardened%> "
1732 : : "because optimizations are turned off");
1733 : : else
1734 : 0 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1735 : : "%<_FORTIFY_SOURCE%> is not enabled by %<-fhardened%> "
1736 : : "because it was specified in %<-D%> or %<-U%>");
1737 : 91 : if (!cxx_assert_seen_p)
1738 : 87 : cpp_define (parse_in, "_GLIBCXX_ASSERTIONS");
1739 : : else
1740 : 4 : warning_at (UNKNOWN_LOCATION, OPT_Whardened,
1741 : : "%<_GLIBCXX_ASSERTIONS%> is not enabled by "
1742 : : "%<-fhardened%> because it was specified in %<-D%> "
1743 : : "or %<-U%>");
1744 : : }
1745 : :
1746 : 206230 : cpp_stop_forcing_token_locations (parse_in);
1747 : : }
1748 : 525 : else if (cpp_opts->directives_only)
1749 : 41 : cpp_init_special_builtins (parse_in);
1750 : :
1751 : : /* Start the main input file, if the debug writer wants it. */
1752 : 206755 : if (debug_hooks->start_end_main_source_file
1753 : 42753 : && !flag_preprocess_only)
1754 : 40397 : (*debug_hooks->start_source_file) (0, this_input_filename);
1755 : :
1756 : 206755 : if (!cpp_opts->preprocessed)
1757 : : /* Handle -imacros after -D and -U. */
1758 : 387595 : for (size_t i = 0; i < deferred_count; i++)
1759 : : {
1760 : 181365 : struct deferred_opt *opt = &deferred_opts[i];
1761 : :
1762 : 181365 : if (opt->code == OPT_imacros
1763 : 181365 : && cpp_push_include (parse_in, opt->arg))
1764 : : {
1765 : : /* Disable push_command_line_include callback for now. */
1766 : 8 : include_cursor = deferred_count + 1;
1767 : 8 : cpp_scan_nooutput (parse_in);
1768 : : }
1769 : : }
1770 : :
1771 : 206755 : include_cursor = 0;
1772 : 206755 : push_command_line_include ();
1773 : 206755 : }
1774 : :
1775 : : /* Give CPP the next file given by -include, if any. */
1776 : : static void
1777 : 732923 : push_command_line_include (void)
1778 : : {
1779 : : /* This can happen if disabled by -imacros for example.
1780 : : Punt so that we don't set "<command-line>" as the filename for
1781 : : the header. */
1782 : 732923 : if (include_cursor > deferred_count)
1783 : : return;
1784 : :
1785 : 423027 : if (!done_preinclude)
1786 : : {
1787 : 206755 : done_preinclude = true;
1788 : 206755 : if (flag_hosted && std_inc && !cpp_opts->preprocessed)
1789 : : {
1790 : 206148 : const char *preinc = targetcm.c_preinclude ();
1791 : 206148 : if (preinc && cpp_push_default_include (parse_in, preinc))
1792 : : return;
1793 : : }
1794 : : }
1795 : :
1796 : 216879 : pch_cpp_save_state ();
1797 : :
1798 : 605050 : while (include_cursor < deferred_count)
1799 : : {
1800 : 181417 : struct deferred_opt *opt = &deferred_opts[include_cursor++];
1801 : :
1802 : 362781 : if (!cpp_opts->preprocessed && opt->code == OPT_include
1803 : 191545 : && cpp_push_include (parse_in, opt->arg))
1804 : : return;
1805 : : }
1806 : :
1807 : 206754 : if (include_cursor == deferred_count)
1808 : : {
1809 : 206754 : include_cursor++;
1810 : : /* -Wunused-macros should only warn about macros defined hereafter. */
1811 : 206754 : cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
1812 : : /* Restore the line map back to the main file. */
1813 : 206754 : if (!cpp_opts->preprocessed)
1814 : : {
1815 : 206229 : cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1816 : 206229 : if (lang_hooks.preprocess_main_file)
1817 : : /* We're starting the main file. Inform the FE of that. */
1818 : 96726 : lang_hooks.preprocess_main_file
1819 : 96726 : (parse_in, line_table, LINEMAPS_LAST_ORDINARY_MAP (line_table));
1820 : : }
1821 : :
1822 : : /* Set this here so the client can change the option if it wishes,
1823 : : and after stacking the main file so we don't trace the main file. */
1824 : 206754 : line_table->trace_includes = cpp_opts->print_include_names;
1825 : : }
1826 : : }
1827 : :
1828 : : /* File change callback. Has to handle -include files. */
1829 : : static void
1830 : 19896976 : cb_file_change (cpp_reader *reader, const line_map_ordinary *new_map)
1831 : : {
1832 : 19896976 : if (flag_preprocess_only)
1833 : 160567 : pp_file_change (new_map);
1834 : : else
1835 : 19736409 : fe_file_change (new_map);
1836 : :
1837 : 19690608 : if (new_map && cpp_opts->preprocessed
1838 : 38004 : && lang_hooks.preprocess_main_file && MAIN_FILE_P (new_map)
1839 : 19899525 : && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map))
1840 : : /* We're starting the main file. Inform the FE of that. */
1841 : 450 : lang_hooks.preprocess_main_file (reader, line_table, new_map);
1842 : :
1843 : 19896976 : if (new_map
1844 : 19690608 : && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME))
1845 : : {
1846 : : /* Signal to plugins that a file is included. This could happen
1847 : : several times with the same file path, e.g. because of
1848 : : several '#include' or '#line' directives... */
1849 : 10261671 : invoke_plugin_callbacks
1850 : 10261671 : (PLUGIN_INCLUDE_FILE,
1851 : 10261671 : const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map)));
1852 : : }
1853 : :
1854 : 19690608 : if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1855 : : {
1856 : 526168 : pch_cpp_save_state ();
1857 : 526168 : push_command_line_include ();
1858 : : }
1859 : 19896975 : }
1860 : :
1861 : : void
1862 : 52 : cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1863 : : {
1864 : 52 : if (!set_src_pwd (dir))
1865 : 0 : warning (0, "too late for # directive to set debug directory");
1866 : 52 : }
1867 : :
1868 : : /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1869 : : extensions if ISO). There is no concept of gnu94. */
1870 : : static void
1871 : 6939 : set_std_c89 (int c94, int iso)
1872 : : {
1873 : 9891 : cpp_set_lang (parse_in, c94 ? CLK_STDC94 : iso ? CLK_STDC89 : CLK_GNUC89);
1874 : 6939 : flag_iso = iso;
1875 : 6939 : flag_no_asm = iso;
1876 : 6939 : flag_no_gnu_keywords = iso;
1877 : 6939 : flag_no_nonansi_builtin = iso;
1878 : 6939 : flag_isoc94 = c94;
1879 : 6939 : flag_isoc99 = 0;
1880 : 6939 : flag_isoc11 = 0;
1881 : 6939 : flag_isoc23 = 0;
1882 : 6939 : flag_isoc2y = 0;
1883 : 6939 : lang_hooks.name = "GNU C89";
1884 : 6939 : }
1885 : :
1886 : : /* Set the C 99 standard (without GNU extensions if ISO). */
1887 : : static void
1888 : 1182 : set_std_c99 (int iso)
1889 : : {
1890 : 1791 : cpp_set_lang (parse_in, iso ? CLK_STDC99 : CLK_GNUC99);
1891 : 1182 : flag_no_asm = iso;
1892 : 1182 : flag_no_nonansi_builtin = iso;
1893 : 1182 : flag_iso = iso;
1894 : 1182 : flag_isoc2y = 0;
1895 : 1182 : flag_isoc23 = 0;
1896 : 1182 : flag_isoc11 = 0;
1897 : 1182 : flag_isoc99 = 1;
1898 : 1182 : flag_isoc94 = 1;
1899 : 1182 : lang_hooks.name = "GNU C99";
1900 : 1182 : }
1901 : :
1902 : : /* Set the C 11 standard (without GNU extensions if ISO). */
1903 : : static void
1904 : 4199 : set_std_c11 (int iso)
1905 : : {
1906 : 7889 : cpp_set_lang (parse_in, iso ? CLK_STDC11 : CLK_GNUC11);
1907 : 4199 : flag_no_asm = iso;
1908 : 4199 : flag_no_nonansi_builtin = iso;
1909 : 4199 : flag_iso = iso;
1910 : 4199 : flag_isoc2y = 0;
1911 : 4199 : flag_isoc23 = 0;
1912 : 4199 : flag_isoc11 = 1;
1913 : 4199 : flag_isoc99 = 1;
1914 : 4199 : flag_isoc94 = 1;
1915 : 4199 : lang_hooks.name = "GNU C11";
1916 : 4199 : }
1917 : :
1918 : : /* Set the C 17 standard (without GNU extensions if ISO). */
1919 : : static void
1920 : 827 : set_std_c17 (int iso)
1921 : : {
1922 : 1612 : cpp_set_lang (parse_in, iso ? CLK_STDC17 : CLK_GNUC17);
1923 : 827 : flag_no_asm = iso;
1924 : 827 : flag_no_nonansi_builtin = iso;
1925 : 827 : flag_iso = iso;
1926 : 827 : flag_isoc2y = 0;
1927 : 827 : flag_isoc23 = 0;
1928 : 827 : flag_isoc11 = 1;
1929 : 827 : flag_isoc99 = 1;
1930 : 827 : flag_isoc94 = 1;
1931 : 827 : lang_hooks.name = "GNU C17";
1932 : 827 : }
1933 : :
1934 : : /* Set the C 23 standard (without GNU extensions if ISO). */
1935 : : static void
1936 : 111102 : set_std_c23 (int iso)
1937 : : {
1938 : 221361 : cpp_set_lang (parse_in, iso ? CLK_STDC23 : CLK_GNUC23);
1939 : 111102 : flag_no_asm = iso;
1940 : 111102 : flag_no_nonansi_builtin = iso;
1941 : 111102 : flag_iso = iso;
1942 : 111102 : flag_isoc2y = 0;
1943 : 111102 : flag_isoc23 = 1;
1944 : 111102 : flag_isoc11 = 1;
1945 : 111102 : flag_isoc99 = 1;
1946 : 111102 : flag_isoc94 = 1;
1947 : 111102 : lang_hooks.name = "GNU C23";
1948 : 111102 : }
1949 : :
1950 : : /* Set the C 2Y standard (without GNU extensions if ISO). */
1951 : : static void
1952 : 173 : set_std_c2y (int iso)
1953 : : {
1954 : 181 : cpp_set_lang (parse_in, iso ? CLK_STDC2Y : CLK_GNUC2Y);
1955 : 173 : flag_no_asm = iso;
1956 : 173 : flag_no_nonansi_builtin = iso;
1957 : 173 : flag_iso = iso;
1958 : 173 : flag_isoc2y = 1;
1959 : 173 : flag_isoc23 = 1;
1960 : 173 : flag_isoc11 = 1;
1961 : 173 : flag_isoc99 = 1;
1962 : 173 : flag_isoc94 = 1;
1963 : 173 : lang_hooks.name = "GNU C2Y";
1964 : 173 : }
1965 : :
1966 : :
1967 : : /* Set the C++ 98 standard (without GNU extensions if ISO). */
1968 : : static void
1969 : 14122 : set_std_cxx98 (int iso)
1970 : : {
1971 : 19463 : cpp_set_lang (parse_in, iso ? CLK_CXX98 : CLK_GNUCXX);
1972 : 14122 : flag_no_gnu_keywords = iso;
1973 : 14122 : flag_no_nonansi_builtin = iso;
1974 : 14122 : flag_iso = iso;
1975 : 14122 : flag_isoc94 = 0;
1976 : 14122 : flag_isoc99 = 0;
1977 : 14122 : cxx_dialect = cxx98;
1978 : 14122 : lang_hooks.name = "GNU C++98";
1979 : 14122 : }
1980 : :
1981 : : /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1982 : : static void
1983 : 5599 : set_std_cxx11 (int iso)
1984 : : {
1985 : 7025 : cpp_set_lang (parse_in, iso ? CLK_CXX11 : CLK_GNUCXX11);
1986 : 5599 : flag_no_gnu_keywords = iso;
1987 : 5599 : flag_no_nonansi_builtin = iso;
1988 : 5599 : flag_iso = iso;
1989 : : /* C++11 includes the C99 standard library. */
1990 : 5599 : flag_isoc94 = 1;
1991 : 5599 : flag_isoc99 = 1;
1992 : 5599 : cxx_dialect = cxx11;
1993 : 5599 : lang_hooks.name = "GNU C++11";
1994 : 5599 : }
1995 : :
1996 : : /* Set the C++ 2014 standard (without GNU extensions if ISO). */
1997 : : static void
1998 : 1278 : set_std_cxx14 (int iso)
1999 : : {
2000 : 1547 : cpp_set_lang (parse_in, iso ? CLK_CXX14 : CLK_GNUCXX14);
2001 : 1278 : flag_no_gnu_keywords = iso;
2002 : 1278 : flag_no_nonansi_builtin = iso;
2003 : 1278 : flag_iso = iso;
2004 : : /* C++14 includes the C99 standard library. */
2005 : 1278 : flag_isoc94 = 1;
2006 : 1278 : flag_isoc99 = 1;
2007 : 1278 : cxx_dialect = cxx14;
2008 : 1278 : lang_hooks.name = "GNU C++14";
2009 : 1278 : }
2010 : :
2011 : : /* Set the C++ 2017 standard (without GNU extensions if ISO). */
2012 : : static void
2013 : 127507 : set_std_cxx17 (int iso)
2014 : : {
2015 : 239247 : cpp_set_lang (parse_in, iso ? CLK_CXX17 : CLK_GNUCXX17);
2016 : 127507 : flag_no_gnu_keywords = iso;
2017 : 127507 : flag_no_nonansi_builtin = iso;
2018 : 127507 : flag_iso = iso;
2019 : : /* C++17 includes the C11 standard library. */
2020 : 127507 : flag_isoc94 = 1;
2021 : 127507 : flag_isoc99 = 1;
2022 : 127507 : flag_isoc11 = 1;
2023 : 127507 : cxx_dialect = cxx17;
2024 : 127507 : lang_hooks.name = "GNU C++17";
2025 : 127507 : }
2026 : :
2027 : : /* Set the C++ 2020 standard (without GNU extensions if ISO). */
2028 : : static void
2029 : 5009 : set_std_cxx20 (int iso)
2030 : : {
2031 : 6418 : cpp_set_lang (parse_in, iso ? CLK_CXX20 : CLK_GNUCXX20);
2032 : 5009 : flag_no_gnu_keywords = iso;
2033 : 5009 : flag_no_nonansi_builtin = iso;
2034 : 5009 : flag_iso = iso;
2035 : : /* C++20 includes the C11 standard library. */
2036 : 5009 : flag_isoc94 = 1;
2037 : 5009 : flag_isoc99 = 1;
2038 : 5009 : flag_isoc11 = 1;
2039 : 5009 : cxx_dialect = cxx20;
2040 : 5009 : lang_hooks.name = "GNU C++20";
2041 : 5009 : }
2042 : :
2043 : : /* Set the C++ 2023 standard (without GNU extensions if ISO). */
2044 : : static void
2045 : 1926 : set_std_cxx23 (int iso)
2046 : : {
2047 : 2432 : cpp_set_lang (parse_in, iso ? CLK_CXX23 : CLK_GNUCXX23);
2048 : 1926 : flag_no_gnu_keywords = iso;
2049 : 1926 : flag_no_nonansi_builtin = iso;
2050 : 1926 : flag_iso = iso;
2051 : : /* C++23 includes the C11 standard library. */
2052 : 1926 : flag_isoc94 = 1;
2053 : 1926 : flag_isoc99 = 1;
2054 : 1926 : flag_isoc11 = 1;
2055 : 1926 : cxx_dialect = cxx23;
2056 : 1926 : lang_hooks.name = "GNU C++23";
2057 : 1926 : }
2058 : :
2059 : : /* Set the C++ 2026 standard (without GNU extensions if ISO). */
2060 : : static void
2061 : 23597 : set_std_cxx26 (int iso)
2062 : : {
2063 : 31304 : cpp_set_lang (parse_in, iso ? CLK_CXX26 : CLK_GNUCXX26);
2064 : 23597 : flag_no_gnu_keywords = iso;
2065 : 23597 : flag_no_nonansi_builtin = iso;
2066 : 23597 : flag_iso = iso;
2067 : : /* C++26 includes the C11 standard library. */
2068 : 23597 : flag_isoc94 = 1;
2069 : 23597 : flag_isoc99 = 1;
2070 : 23597 : flag_isoc11 = 1;
2071 : 23597 : cxx_dialect = cxx26;
2072 : 23597 : lang_hooks.name = "GNU C++26";
2073 : 23597 : }
2074 : :
2075 : : /* Args to -d specify what to dump. Silently ignore
2076 : : unrecognized options; they may be aimed at toplev.cc. */
2077 : : static void
2078 : 1649 : handle_OPT_d (const char *arg)
2079 : : {
2080 : 1649 : char c;
2081 : :
2082 : 3298 : while ((c = *arg++) != '\0')
2083 : 1649 : switch (c)
2084 : : {
2085 : 836 : case 'M': /* Dump macros only. */
2086 : 836 : case 'N': /* Dump names. */
2087 : 836 : case 'D': /* Dump definitions. */
2088 : 836 : case 'U': /* Dump used macros. */
2089 : 836 : flag_dump_macros = c;
2090 : 836 : break;
2091 : :
2092 : 2 : case 'I':
2093 : 2 : flag_dump_includes = 1;
2094 : 2 : break;
2095 : : }
2096 : 1649 : }
|