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