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