]>
Commit | Line | Data |
---|---|---|
0b6f2917 | 1 | /* C/ObjC/C++ command line option handling. |
5624e564 | 2 | Copyright (C) 2002-2015 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" |
40e23961 | 24 | #include "options.h" |
40e23961 | 25 | #include "alias.h" |
0b6f2917 NB |
26 | #include "tree.h" |
27 | #include "c-common.h" | |
28 | #include "c-pragma.h" | |
29 | #include "flags.h" | |
30 | #include "toplev.h" | |
31 | #include "langhooks.h" | |
0b6f2917 | 32 | #include "diagnostic.h" |
18767f65 | 33 | #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */ |
4b7091eb | 34 | #include "intl.h" |
5793b276 | 35 | #include "cppdefault.h" |
670637ee | 36 | #include "incpath.h" |
23345bbb | 37 | #include "debug.h" /* For debug_hooks. */ |
2772ef3e | 38 | #include "opts.h" |
b826515a | 39 | #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */ |
c6e83800 | 40 | #include "mkdeps.h" |
acce4e77 JM |
41 | #include "c-target.h" |
42 | #include "tm.h" /* For BYTES_BIG_ENDIAN, | |
43 | DOLLARS_IN_IDENTIFIERS, | |
44 | STDC_0_IN_SYSTEM_HEADERS, | |
45 | TARGET_FLT_EVAL_METHOD_NON_DEFAULT and | |
46 | TARGET_OPTF. */ | |
a4c97feb | 47 | #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */ |
f8a36c78 | 48 | #include "dumpfile.h" |
5793b276 | 49 | |
b1822ccc NB |
50 | #ifndef DOLLARS_IN_IDENTIFIERS |
51 | # define DOLLARS_IN_IDENTIFIERS true | |
52 | #endif | |
53 | ||
5793b276 NB |
54 | #ifndef TARGET_SYSTEM_ROOT |
55 | # define TARGET_SYSTEM_ROOT NULL | |
56 | #endif | |
0b6f2917 | 57 | |
7cd60054 AM |
58 | #ifndef TARGET_OPTF |
59 | #define TARGET_OPTF(ARG) | |
60 | #endif | |
61 | ||
f4ff5a69 | 62 | /* CPP's options. */ |
d2e796ad | 63 | cpp_options *cpp_opts; |
18bdccaa | 64 | |
460bd0e3 | 65 | /* Input filename. */ |
89e9faee | 66 | static const char *this_input_filename; |
460bd0e3 | 67 | |
76c3e73e NB |
68 | /* Filename and stream for preprocessed output. */ |
69 | static const char *out_fname; | |
70 | static FILE *out_stream; | |
71 | ||
72 | /* Append dependencies to deps_file. */ | |
73 | static bool deps_append; | |
74 | ||
f4ff5a69 NB |
75 | /* If dependency switches (-MF etc.) have been given. */ |
76 | static bool deps_seen; | |
77 | ||
5793b276 NB |
78 | /* If -v seen. */ |
79 | static bool verbose; | |
80 | ||
f4ff5a69 NB |
81 | /* Dependency output file. */ |
82 | static const char *deps_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 | ||
f8a36c78 TJ |
108 | /* Dump files/flags to use during parsing. */ |
109 | static FILE *original_dump_file = NULL; | |
110 | static int original_dump_flags; | |
111 | static FILE *class_dump_file = NULL; | |
112 | static int class_dump_flags; | |
113 | ||
1efcb8c6 JM |
114 | /* Whether any standard preincluded header has been preincluded. */ |
115 | static bool done_preinclude; | |
116 | ||
2f6e4e97 AJ |
117 | static void handle_OPT_d (const char *); |
118 | static void set_std_cxx98 (int); | |
97e3ad20 | 119 | static void set_std_cxx11 (int); |
e4276ba5 | 120 | static void set_std_cxx14 (int); |
da73100b | 121 | static void set_std_cxx1z (int); |
2f6e4e97 AJ |
122 | static void set_std_c89 (int, int); |
123 | static void set_std_c99 (int); | |
48b0b196 | 124 | static void set_std_c11 (int); |
2f6e4e97 AJ |
125 | static void check_deps_environment_vars (void); |
126 | static void handle_deferred_opts (void); | |
127 | static void sanitize_cpp_opts (void); | |
128 | static void add_prefixed_path (const char *, size_t); | |
129 | static void push_command_line_include (void); | |
0e50b624 | 130 | static void cb_file_change (cpp_reader *, const line_map_ordinary *); |
8e9ea4d7 | 131 | static void cb_dir_change (cpp_reader *, const char *); |
c98cd5bf | 132 | static void c_finish_options (void); |
460bd0e3 NB |
133 | |
134 | #ifndef STDC_0_IN_SYSTEM_HEADERS | |
135 | #define STDC_0_IN_SYSTEM_HEADERS 0 | |
136 | #endif | |
0b6f2917 | 137 | |
2772ef3e | 138 | /* Holds switches parsed by c_common_handle_option (), but whose |
95bd1dd7 | 139 | handling is deferred to c_common_post_options (). */ |
2f6e4e97 | 140 | static void defer_opt (enum opt_code, const char *); |
f4ff5a69 NB |
141 | static struct deferred_opt |
142 | { | |
143 | enum opt_code code; | |
144 | const char *arg; | |
145 | } *deferred_opts; | |
146 | ||
3734d960 | 147 | |
c5fa0890 | 148 | extern const unsigned int |
3734d960 MLI |
149 | c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX); |
150 | ||
f4ff5a69 NB |
151 | /* Defer option CODE with argument ARG. */ |
152 | static void | |
2f6e4e97 | 153 | defer_opt (enum opt_code code, const char *arg) |
f4ff5a69 | 154 | { |
f4ff5a69 NB |
155 | deferred_opts[deferred_count].code = code; |
156 | deferred_opts[deferred_count].arg = arg; | |
157 | deferred_count++; | |
158 | } | |
159 | ||
7a9bf9a4 | 160 | /* Return language mask for option parsing. */ |
b86f6cd9 | 161 | unsigned int |
7a9bf9a4 | 162 | c_common_option_lang_mask (void) |
0b6f2917 | 163 | { |
b86f6cd9 | 164 | static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; |
37fa72e9 | 165 | |
7a9bf9a4 JM |
166 | return lang_flags[c_language]; |
167 | } | |
168 | ||
18767f65 MLI |
169 | /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */ |
170 | static void | |
171 | c_diagnostic_finalizer (diagnostic_context *context, | |
172 | diagnostic_info *diagnostic) | |
173 | { | |
174 | diagnostic_show_locus (context, diagnostic); | |
175 | /* By default print macro expansion contexts in the diagnostic | |
176 | finalizer -- for tokens resulting from macro expansion. */ | |
177 | virt_loc_aware_diagnostic_finalizer (context, diagnostic); | |
178 | pp_destroy_prefix (context->printer); | |
179 | pp_newline_and_flush (context->printer); | |
180 | } | |
181 | ||
d723bb7c | 182 | /* Common default settings for diagnostics. */ |
7a9bf9a4 | 183 | void |
d723bb7c | 184 | c_common_diagnostics_set_defaults (diagnostic_context *context) |
7a9bf9a4 | 185 | { |
18767f65 | 186 | diagnostic_finalizer (context) = c_diagnostic_finalizer; |
7a9bf9a4 JM |
187 | context->opt_permissive = OPT_fpermissive; |
188 | } | |
189 | ||
190 | /* Whether options from all C-family languages should be accepted | |
191 | quietly. */ | |
192 | static bool accept_all_c_family_options = false; | |
193 | ||
194 | /* Return whether to complain about a wrong-language option. */ | |
195 | bool | |
196 | c_common_complain_wrong_lang_p (const struct cl_option *option) | |
197 | { | |
198 | if (accept_all_c_family_options | |
199 | && (option->flags & c_family_lang_mask)) | |
200 | return false; | |
201 | ||
202 | return true; | |
203 | } | |
204 | ||
a75bfaa6 JM |
205 | /* Initialize options structure OPTS. */ |
206 | void | |
207 | c_common_init_options_struct (struct gcc_options *opts) | |
208 | { | |
209 | opts->x_flag_exceptions = c_dialect_cxx (); | |
210 | opts->x_warn_pointer_arith = c_dialect_cxx (); | |
211 | opts->x_warn_write_strings = c_dialect_cxx (); | |
212 | opts->x_flag_warn_unused_result = true; | |
213 | ||
214 | /* By default, C99-like requirements for complex multiply and divide. */ | |
215 | opts->x_flag_complex_method = 2; | |
216 | } | |
217 | ||
7a9bf9a4 JM |
218 | /* Common initialization before calling option handlers. */ |
219 | void | |
220 | c_common_init_options (unsigned int decoded_options_count, | |
221 | struct cl_decoded_option *decoded_options) | |
222 | { | |
223 | unsigned int i; | |
224 | struct cpp_callbacks *cb; | |
5f0f4a3b | 225 | |
37fa72e9 | 226 | parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, |
5ffeb913 | 227 | ident_hash, line_table); |
148e4216 JM |
228 | cb = cpp_get_callbacks (parse_in); |
229 | cb->error = c_cpp_error; | |
37fa72e9 | 230 | |
18bdccaa | 231 | cpp_opts = cpp_get_options (parse_in); |
b1822ccc | 232 | cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; |
37fa72e9 | 233 | cpp_opts->objc = c_dialect_objc (); |
78b8811a HPN |
234 | |
235 | /* Reset to avoid warnings on internal definitions. We set it just | |
236 | before passing on command-line options to cpplib. */ | |
237 | cpp_opts->warn_dollars = 0; | |
238 | ||
7a9bf9a4 | 239 | deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count); |
33de9573 | 240 | |
afd85c1a | 241 | if (c_language == clk_c) |
33de9573 | 242 | { |
d73326ca MP |
243 | /* The default for C is gnu11. */ |
244 | set_std_c11 (false /* ISO */); | |
245 | ||
afd85c1a RS |
246 | /* If preprocessing assembly language, accept any of the C-family |
247 | front end options since the driver may pass them through. */ | |
7a9bf9a4 JM |
248 | for (i = 1; i < decoded_options_count; i++) |
249 | if (decoded_options[i].opt_index == OPT_lang_asm) | |
afd85c1a | 250 | { |
7a9bf9a4 | 251 | accept_all_c_family_options = true; |
afd85c1a RS |
252 | break; |
253 | } | |
33de9573 | 254 | } |
0b6f2917 NB |
255 | } |
256 | ||
b20d9f0c | 257 | /* Handle switch SCODE with argument ARG. VALUE is true, unless no- |
5f20c657 JM |
258 | form of an -f or -W option was given. Returns false if the switch was |
259 | invalid, true if valid. Use HANDLERS in recursive handle_option calls. */ | |
260 | bool | |
3734d960 | 261 | c_common_handle_option (size_t scode, const char *arg, int value, |
a4d8c676 JM |
262 | int kind, location_t loc, |
263 | const struct cl_option_handlers *handlers) | |
0b6f2917 | 264 | { |
2772ef3e NB |
265 | const struct cl_option *option = &cl_options[scode]; |
266 | enum opt_code code = (enum opt_code) scode; | |
5f20c657 | 267 | bool result = true; |
2772ef3e | 268 | |
69723be2 SB |
269 | /* Prevent resetting the language standard to a C dialect when the driver |
270 | has already determined that we're looking at assembler input. */ | |
271 | bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM); | |
b8698a0f | 272 | |
fef3106c | 273 | switch (code) |
0b6f2917 | 274 | { |
2772ef3e | 275 | default: |
3734d960 | 276 | if (cl_options[code].flags & c_family_lang_mask) |
1f1d5130 MS |
277 | { |
278 | if ((option->flags & CL_TARGET) | |
279 | && ! targetcm.handle_c_option (scode, arg, value)) | |
5f20c657 | 280 | result = false; |
1f1d5130 MS |
281 | break; |
282 | } | |
5f20c657 | 283 | result = false; |
33de9573 | 284 | break; |
0b6f2917 | 285 | |
fef3106c | 286 | case OPT__output_pch_: |
17211ab5 GK |
287 | pch_file = arg; |
288 | break; | |
289 | ||
c1bad961 NB |
290 | case OPT_A: |
291 | defer_opt (code, arg); | |
292 | break; | |
293 | ||
4b7091eb NB |
294 | case OPT_C: |
295 | cpp_opts->discard_comments = 0; | |
296 | break; | |
297 | ||
298 | case OPT_CC: | |
299 | cpp_opts->discard_comments = 0; | |
300 | cpp_opts->discard_comments_in_macro_exp = 0; | |
301 | break; | |
302 | ||
c1bad961 NB |
303 | case OPT_D: |
304 | defer_opt (code, arg); | |
305 | break; | |
306 | ||
4b7091eb NB |
307 | case OPT_H: |
308 | cpp_opts->print_include_names = 1; | |
309 | break; | |
310 | ||
94d1613b MS |
311 | case OPT_F: |
312 | TARGET_OPTF (xstrdup (arg)); | |
313 | break; | |
314 | ||
5793b276 NB |
315 | case OPT_I: |
316 | if (strcmp (arg, "-")) | |
b02398bd | 317 | add_path (xstrdup (arg), BRACKET, 0, true); |
5793b276 NB |
318 | else |
319 | { | |
320 | if (quote_chain_split) | |
321 | error ("-I- specified twice"); | |
322 | quote_chain_split = true; | |
323 | split_quote_chain (); | |
1f5b3869 | 324 | inform (input_location, "obsolete option -I- used, please use -iquote instead"); |
5793b276 NB |
325 | } |
326 | break; | |
327 | ||
f4ff5a69 NB |
328 | case OPT_M: |
329 | case OPT_MM: | |
330 | /* When doing dependencies with -M or -MM, suppress normal | |
331 | preprocessed output, but still do -dM etc. as software | |
332 | depends on this. Preprocessed output does occur if -MD, -MMD | |
333 | or environment var dependency generation is used. */ | |
334 | cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER); | |
63973df3 | 335 | flag_no_output = 1; |
f4ff5a69 NB |
336 | break; |
337 | ||
c878765b JM |
338 | case OPT_MD: |
339 | case OPT_MMD: | |
340 | cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER); | |
74dc6a11 | 341 | cpp_opts->deps.need_preprocessor_output = true; |
f4ff5a69 NB |
342 | deps_file = arg; |
343 | break; | |
344 | ||
345 | case OPT_MF: | |
346 | deps_seen = true; | |
347 | deps_file = arg; | |
348 | break; | |
349 | ||
350 | case OPT_MG: | |
351 | deps_seen = true; | |
352 | cpp_opts->deps.missing_files = true; | |
353 | break; | |
354 | ||
355 | case OPT_MP: | |
356 | deps_seen = true; | |
357 | cpp_opts->deps.phony_targets = true; | |
358 | break; | |
359 | ||
360 | case OPT_MQ: | |
361 | case OPT_MT: | |
362 | deps_seen = true; | |
363 | defer_opt (code, arg); | |
364 | break; | |
365 | ||
4b7091eb | 366 | case OPT_P: |
63973df3 | 367 | flag_no_line_commands = 1; |
4b7091eb NB |
368 | break; |
369 | ||
c1bad961 NB |
370 | case OPT_U: |
371 | defer_opt (code, arg); | |
372 | break; | |
373 | ||
0b6f2917 | 374 | case OPT_Wall: |
65d4f2cd | 375 | /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */ |
18bdccaa | 376 | |
7b086b11 | 377 | cpp_opts->warn_num_sign_change = value; |
0b6f2917 NB |
378 | break; |
379 | ||
0b6f2917 NB |
380 | case OPT_Wunknown_pragmas: |
381 | /* Set to greater than 1, so that even unknown pragmas in | |
2f6e4e97 | 382 | system headers will be warned about. */ |
34a180a6 | 383 | /* ??? There is no way to handle this automatically for now. */ |
7b086b11 | 384 | warn_unknown_pragmas = value * 2; |
0b6f2917 NB |
385 | break; |
386 | ||
f749a36b | 387 | case OPT_ansi: |
37fa72e9 | 388 | if (!c_dialect_cxx ()) |
f749a36b NB |
389 | set_std_c89 (false, true); |
390 | else | |
391 | set_std_cxx98 (true); | |
392 | break; | |
0b6f2917 | 393 | |
4b7091eb NB |
394 | case OPT_d: |
395 | handle_OPT_d (arg); | |
396 | break; | |
397 | ||
62984918 JM |
398 | case OPT_Wabi_: |
399 | warn_abi = true; | |
400 | if (value == 1) | |
401 | { | |
402 | warning (0, "%<-Wabi=1%> is not supported, using =2"); | |
403 | value = 2; | |
404 | } | |
405 | flag_abi_compat_version = value; | |
406 | break; | |
407 | ||
5dc99c46 SB |
408 | case OPT_fcanonical_system_headers: |
409 | cpp_opts->canonical_system_headers = value; | |
410 | break; | |
411 | ||
0b6f2917 | 412 | case OPT_fcond_mismatch: |
37fa72e9 | 413 | if (!c_dialect_cxx ()) |
0b6f2917 | 414 | { |
7b086b11 | 415 | flag_cond_mismatch = value; |
0b6f2917 NB |
416 | break; |
417 | } | |
d4ee4d25 | 418 | warning (0, "switch %qs is no longer supported", option->opt_text); |
0b6f2917 NB |
419 | break; |
420 | ||
0b6f2917 | 421 | case OPT_fbuiltin_: |
7b086b11 | 422 | if (value) |
5f20c657 | 423 | result = false; |
4b7091eb NB |
424 | else |
425 | disable_builtin_function (arg); | |
0b6f2917 NB |
426 | break; |
427 | ||
ccfc4c91 | 428 | case OPT_fdirectives_only: |
2710d6d7 | 429 | cpp_opts->directives_only = value; |
ccfc4c91 OW |
430 | break; |
431 | ||
0b6f2917 | 432 | case OPT_fdollars_in_identifiers: |
7b086b11 | 433 | cpp_opts->dollars_in_ident = value; |
0b6f2917 NB |
434 | break; |
435 | ||
0b6f2917 | 436 | case OPT_ffreestanding: |
7b086b11 | 437 | value = !value; |
938d968e | 438 | /* Fall through.... */ |
0b6f2917 | 439 | case OPT_fhosted: |
7b086b11 NB |
440 | flag_hosted = value; |
441 | flag_no_builtin = !value; | |
0b6f2917 NB |
442 | break; |
443 | ||
fef3106c | 444 | case OPT_fconstant_string_class_: |
4b7091eb | 445 | constant_string_class_name = arg; |
0b6f2917 NB |
446 | break; |
447 | ||
af15a2fe JM |
448 | case OPT_fextended_identifiers: |
449 | cpp_opts->extended_identifiers = value; | |
450 | break; | |
451 | ||
18bdccaa | 452 | case OPT_foperator_names: |
7b086b11 | 453 | cpp_opts->operator_names = value; |
18bdccaa NB |
454 | break; |
455 | ||
17211ab5 | 456 | case OPT_fpch_deps: |
7b086b11 | 457 | cpp_opts->restore_pch_deps = value; |
17211ab5 GK |
458 | break; |
459 | ||
c0d578e6 GK |
460 | case OPT_fpch_preprocess: |
461 | flag_pch_preprocess = value; | |
462 | break; | |
463 | ||
0b6f2917 | 464 | case OPT_fpermissive: |
0641fa97 RG |
465 | flag_permissive = value; |
466 | global_dc->permissive = value; | |
0b6f2917 NB |
467 | break; |
468 | ||
18bdccaa | 469 | case OPT_fpreprocessed: |
7b086b11 | 470 | cpp_opts->preprocessed = value; |
18bdccaa NB |
471 | break; |
472 | ||
847e697a TT |
473 | case OPT_fdebug_cpp: |
474 | cpp_opts->debug = 1; | |
475 | break; | |
476 | ||
92582b75 TT |
477 | case OPT_ftrack_macro_expansion: |
478 | if (value) | |
479 | value = 2; | |
480 | /* Fall Through. */ | |
481 | ||
482 | case OPT_ftrack_macro_expansion_: | |
483 | if (arg && *arg != '\0') | |
484 | cpp_opts->track_macro_expansion = value; | |
485 | else | |
486 | cpp_opts->track_macro_expansion = 2; | |
487 | break; | |
488 | ||
0b6f2917 | 489 | case OPT_frepo: |
7b086b11 NB |
490 | flag_use_repository = value; |
491 | if (value) | |
0b6f2917 NB |
492 | flag_implicit_templates = 0; |
493 | break; | |
494 | ||
fef3106c | 495 | case OPT_ftabstop_: |
18bdccaa | 496 | /* It is documented that we silently ignore silly values. */ |
7b086b11 NB |
497 | if (value >= 1 && value <= 100) |
498 | cpp_opts->tabstop = value; | |
18bdccaa NB |
499 | break; |
500 | ||
e6cc3a24 ZW |
501 | case OPT_fexec_charset_: |
502 | cpp_opts->narrow_charset = arg; | |
503 | break; | |
504 | ||
505 | case OPT_fwide_exec_charset_: | |
506 | cpp_opts->wide_charset = arg; | |
507 | break; | |
508 | ||
16dd5cfe EC |
509 | case OPT_finput_charset_: |
510 | cpp_opts->input_charset = arg; | |
511 | break; | |
512 | ||
fef3106c | 513 | case OPT_ftemplate_depth_: |
7b086b11 | 514 | max_tinst_depth = value; |
0b6f2917 NB |
515 | break; |
516 | ||
d7afec4b ND |
517 | case OPT_fvisibility_inlines_hidden: |
518 | visibility_options.inlines_hidden = value; | |
519 | break; | |
0b6f2917 | 520 | |
39ef6592 | 521 | case OPT_femit_struct_debug_baseonly: |
299404a1 | 522 | set_struct_debug_option (&global_options, loc, "base"); |
39ef6592 LC |
523 | break; |
524 | ||
525 | case OPT_femit_struct_debug_reduced: | |
299404a1 | 526 | set_struct_debug_option (&global_options, loc, |
69ccdddb | 527 | "dir:ord:sys,dir:gen:any,ind:base"); |
39ef6592 LC |
528 | break; |
529 | ||
530 | case OPT_femit_struct_debug_detailed_: | |
299404a1 | 531 | set_struct_debug_option (&global_options, loc, arg); |
39ef6592 LC |
532 | break; |
533 | ||
a4a0016d ESR |
534 | case OPT_fext_numeric_literals: |
535 | cpp_opts->ext_numeric_literals = value; | |
536 | break; | |
537 | ||
5793b276 | 538 | case OPT_idirafter: |
b02398bd | 539 | add_path (xstrdup (arg), AFTER, 0, true); |
5793b276 NB |
540 | break; |
541 | ||
255c10b1 | 542 | case OPT_imacros: |
23345bbb NB |
543 | case OPT_include: |
544 | defer_opt (code, arg); | |
545 | break; | |
546 | ||
2b6dd222 JM |
547 | case OPT_imultilib: |
548 | imultilib = arg; | |
549 | break; | |
550 | ||
5793b276 NB |
551 | case OPT_iprefix: |
552 | iprefix = arg; | |
553 | break; | |
554 | ||
4bed3787 | 555 | case OPT_iquote: |
b02398bd | 556 | add_path (xstrdup (arg), QUOTE, 0, true); |
4bed3787 MS |
557 | break; |
558 | ||
5793b276 NB |
559 | case OPT_isysroot: |
560 | sysroot = arg; | |
561 | break; | |
562 | ||
563 | case OPT_isystem: | |
b02398bd | 564 | add_path (xstrdup (arg), SYSTEM, 0, true); |
5793b276 NB |
565 | break; |
566 | ||
567 | case OPT_iwithprefix: | |
568 | add_prefixed_path (arg, SYSTEM); | |
569 | break; | |
570 | ||
571 | case OPT_iwithprefixbefore: | |
572 | add_prefixed_path (arg, BRACKET); | |
573 | break; | |
574 | ||
f749a36b NB |
575 | case OPT_lang_asm: |
576 | cpp_set_lang (parse_in, CLK_ASM); | |
170ea7b9 | 577 | cpp_opts->dollars_in_ident = false; |
f749a36b NB |
578 | break; |
579 | ||
4b7091eb | 580 | case OPT_nostdinc: |
5793b276 | 581 | std_inc = false; |
4b7091eb NB |
582 | break; |
583 | ||
fef3106c | 584 | case OPT_nostdinc__: |
5793b276 | 585 | std_cxx_inc = false; |
4b7091eb NB |
586 | break; |
587 | ||
b4a93904 | 588 | case OPT_o: |
76c3e73e NB |
589 | if (!out_fname) |
590 | out_fname = arg; | |
b4a93904 | 591 | else |
f75d3e11 | 592 | error ("output filename specified twice"); |
b4a93904 NB |
593 | break; |
594 | ||
0b6f2917 NB |
595 | case OPT_print_objc_runtime_info: |
596 | print_struct_values = 1; | |
597 | break; | |
598 | ||
b4a93904 NB |
599 | case OPT_remap: |
600 | cpp_opts->remap = 1; | |
0b6f2917 NB |
601 | break; |
602 | ||
fef3106c NB |
603 | case OPT_std_c__98: |
604 | case OPT_std_gnu__98: | |
69723be2 SB |
605 | if (!preprocessing_asm_p) |
606 | set_std_cxx98 (code == OPT_std_c__98 /* ISO */); | |
0b6f2917 NB |
607 | break; |
608 | ||
97e3ad20 JM |
609 | case OPT_std_c__11: |
610 | case OPT_std_gnu__11: | |
966541e3 | 611 | if (!preprocessing_asm_p) |
a4a0016d ESR |
612 | { |
613 | set_std_cxx11 (code == OPT_std_c__11 /* ISO */); | |
614 | if (code == OPT_std_c__11) | |
615 | cpp_opts->ext_numeric_literals = 0; | |
616 | } | |
966541e3 DG |
617 | break; |
618 | ||
028aee17 JM |
619 | case OPT_std_c__14: |
620 | case OPT_std_gnu__14: | |
552b8185 | 621 | if (!preprocessing_asm_p) |
a4a0016d | 622 | { |
028aee17 JM |
623 | set_std_cxx14 (code == OPT_std_c__14 /* ISO */); |
624 | if (code == OPT_std_c__14) | |
a4a0016d ESR |
625 | cpp_opts->ext_numeric_literals = 0; |
626 | } | |
552b8185 JM |
627 | break; |
628 | ||
da73100b JM |
629 | case OPT_std_c__1z: |
630 | case OPT_std_gnu__1z: | |
631 | if (!preprocessing_asm_p) | |
632 | { | |
633 | set_std_cxx1z (code == OPT_std_c__1z /* ISO */); | |
634 | if (code == OPT_std_c__1z) | |
635 | cpp_opts->ext_numeric_literals = 0; | |
636 | } | |
637 | break; | |
638 | ||
7e1542b9 | 639 | case OPT_std_c90: |
b4a93904 | 640 | case OPT_std_iso9899_199409: |
69723be2 SB |
641 | if (!preprocessing_asm_p) |
642 | set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */); | |
f749a36b NB |
643 | break; |
644 | ||
7e1542b9 | 645 | case OPT_std_gnu90: |
69723be2 SB |
646 | if (!preprocessing_asm_p) |
647 | set_std_c89 (false /* c94 */, false /* ISO */); | |
0b6f2917 NB |
648 | break; |
649 | ||
650 | case OPT_std_c99: | |
69723be2 SB |
651 | if (!preprocessing_asm_p) |
652 | set_std_c99 (true /* ISO */); | |
0b6f2917 NB |
653 | break; |
654 | ||
0b6f2917 | 655 | case OPT_std_gnu99: |
69723be2 SB |
656 | if (!preprocessing_asm_p) |
657 | set_std_c99 (false /* ISO */); | |
0b6f2917 NB |
658 | break; |
659 | ||
48b0b196 | 660 | case OPT_std_c11: |
2778d766 | 661 | if (!preprocessing_asm_p) |
48b0b196 | 662 | set_std_c11 (true /* ISO */); |
2778d766 JM |
663 | break; |
664 | ||
48b0b196 | 665 | case OPT_std_gnu11: |
2778d766 | 666 | if (!preprocessing_asm_p) |
48b0b196 | 667 | set_std_c11 (false /* ISO */); |
2778d766 JM |
668 | break; |
669 | ||
4b7091eb NB |
670 | case OPT_trigraphs: |
671 | cpp_opts->trigraphs = 1; | |
672 | break; | |
673 | ||
674 | case OPT_traditional_cpp: | |
675 | cpp_opts->traditional = 1; | |
676 | break; | |
677 | ||
4b7091eb | 678 | case OPT_v: |
5793b276 | 679 | verbose = true; |
4b7091eb NB |
680 | break; |
681 | } | |
0b6f2917 | 682 | |
f2bc201f MLI |
683 | switch (c_language) |
684 | { | |
685 | case clk_c: | |
686 | C_handle_option_auto (&global_options, &global_options_set, | |
687 | scode, arg, value, | |
688 | c_family_lang_mask, kind, | |
689 | loc, handlers, global_dc); | |
690 | break; | |
691 | ||
692 | case clk_objc: | |
693 | ObjC_handle_option_auto (&global_options, &global_options_set, | |
694 | scode, arg, value, | |
695 | c_family_lang_mask, kind, | |
696 | loc, handlers, global_dc); | |
697 | break; | |
698 | ||
699 | case clk_cxx: | |
700 | CXX_handle_option_auto (&global_options, &global_options_set, | |
701 | scode, arg, value, | |
702 | c_family_lang_mask, kind, | |
703 | loc, handlers, global_dc); | |
704 | break; | |
705 | ||
706 | case clk_objcxx: | |
707 | ObjCXX_handle_option_auto (&global_options, &global_options_set, | |
708 | scode, arg, value, | |
709 | c_family_lang_mask, kind, | |
710 | loc, handlers, global_dc); | |
711 | break; | |
712 | ||
713 | default: | |
714 | gcc_unreachable (); | |
715 | } | |
43f9a13c MLI |
716 | |
717 | cpp_handle_option_auto (&global_options, scode, cpp_opts); | |
0b6f2917 NB |
718 | return result; |
719 | } | |
720 | ||
acce4e77 JM |
721 | /* Default implementation of TARGET_HANDLE_C_OPTION. */ |
722 | ||
723 | bool | |
724 | default_handle_c_option (size_t code ATTRIBUTE_UNUSED, | |
725 | const char *arg ATTRIBUTE_UNUSED, | |
726 | int value ATTRIBUTE_UNUSED) | |
727 | { | |
728 | return false; | |
729 | } | |
730 | ||
0b6f2917 NB |
731 | /* Post-switch processing. */ |
732 | bool | |
8e9ea4d7 | 733 | c_common_post_options (const char **pfilename) |
0b6f2917 | 734 | { |
8e9ea4d7 PB |
735 | struct cpp_callbacks *cb; |
736 | ||
460bd0e3 | 737 | /* Canonicalize the input and output filenames. */ |
d1bd0ded GK |
738 | if (in_fnames == NULL) |
739 | { | |
5d038c4c | 740 | in_fnames = XNEWVEC (const char *, 1); |
d1bd0ded GK |
741 | in_fnames[0] = ""; |
742 | } | |
743 | else if (strcmp (in_fnames[0], "-") == 0) | |
744 | in_fnames[0] = ""; | |
460bd0e3 | 745 | |
76c3e73e NB |
746 | if (out_fname == NULL || !strcmp (out_fname, "-")) |
747 | out_fname = ""; | |
748 | ||
cd79e210 | 749 | if (cpp_opts->deps.style == DEPS_NONE) |
76c3e73e NB |
750 | check_deps_environment_vars (); |
751 | ||
f4ff5a69 | 752 | handle_deferred_opts (); |
76c3e73e | 753 | |
f4ff5a69 | 754 | sanitize_cpp_opts (); |
460bd0e3 | 755 | |
2b6dd222 | 756 | register_include_chains (parse_in, sysroot, iprefix, imultilib, |
37fa72e9 | 757 | std_inc, std_cxx_inc && c_dialect_cxx (), verbose); |
5793b276 | 758 | |
c7b5e395 GK |
759 | #ifdef C_COMMON_OVERRIDE_OPTIONS |
760 | /* Some machines may reject certain combinations of C | |
761 | language-specific options. */ | |
762 | C_COMMON_OVERRIDE_OPTIONS; | |
763 | #endif | |
764 | ||
8ce94e44 JM |
765 | /* Excess precision other than "fast" requires front-end |
766 | support. */ | |
767 | if (c_dialect_cxx ()) | |
768 | { | |
769 | if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD | |
770 | && TARGET_FLT_EVAL_METHOD_NON_DEFAULT) | |
771 | sorry ("-fexcess-precision=standard for C++"); | |
772 | flag_excess_precision_cmdline = EXCESS_PRECISION_FAST; | |
773 | } | |
774 | else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT) | |
775 | flag_excess_precision_cmdline = (flag_iso | |
776 | ? EXCESS_PRECISION_STANDARD | |
777 | : EXCESS_PRECISION_FAST); | |
778 | ||
6dbe0958 JM |
779 | /* ISO C restricts floating-point expression contraction to within |
780 | source-language expressions (-ffp-contract=on, currently an alias | |
781 | for -ffp-contract=off). */ | |
782 | if (flag_iso | |
783 | && !c_dialect_cxx () | |
784 | && (global_options_set.x_flag_fp_contract_mode | |
75b107f5 IB |
785 | == (enum fp_contract_mode) 0) |
786 | && flag_unsafe_math_optimizations == 0) | |
6dbe0958 JM |
787 | flag_fp_contract_mode = FP_CONTRACT_OFF; |
788 | ||
da1c7394 ILT |
789 | /* By default we use C99 inline semantics in GNU99 or C99 mode. C99 |
790 | inline semantics are not supported in GNU89 or C89 mode. */ | |
791 | if (flag_gnu89_inline == -1) | |
792 | flag_gnu89_inline = !flag_isoc99; | |
793 | else if (!flag_gnu89_inline && !flag_isoc99) | |
794 | error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode"); | |
795 | ||
093c7153 RH |
796 | /* Default to ObjC sjlj exception handling if NeXT runtime. */ |
797 | if (flag_objc_sjlj_exceptions < 0) | |
798 | flag_objc_sjlj_exceptions = flag_next_runtime; | |
799 | if (flag_objc_exceptions && !flag_objc_sjlj_exceptions) | |
800 | flag_exceptions = 1; | |
801 | ||
b15458be RB |
802 | /* If -ffreestanding, -fno-hosted or -fno-builtin then disable |
803 | pattern recognition. */ | |
804 | if (!global_options_set.x_flag_tree_loop_distribute_patterns | |
805 | && flag_no_builtin) | |
806 | flag_tree_loop_distribute_patterns = 0; | |
807 | ||
c1771a20 | 808 | /* -Woverlength-strings is off by default, but is enabled by -Wpedantic. |
89a42ac8 ZW |
809 | It is never enabled in C++, as the minimum limit is not normative |
810 | in that standard. */ | |
34a180a6 | 811 | if (c_dialect_cxx ()) |
89a42ac8 ZW |
812 | warn_overlength_strings = 0; |
813 | ||
4003301d MLI |
814 | /* Wmain is enabled by default in C++ but not in C. */ |
815 | /* Wmain is disabled by default for -ffreestanding (!flag_hosted), | |
34a180a6 MLI |
816 | even if -Wall or -Wpedantic was given (warn_main will be 2 if set |
817 | by -Wall, 1 if set by -Wmain). */ | |
4003301d MLI |
818 | if (warn_main == -1) |
819 | warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0; | |
820 | else if (warn_main == 2) | |
821 | warn_main = flag_hosted ? 1 : 0; | |
822 | ||
34a180a6 MLI |
823 | /* In C, -Wall and -Wc++-compat enable -Wenum-compare; if it has not |
824 | yet been set, it is disabled by default. In C++, it is enabled | |
825 | by default. */ | |
6866c6e8 ILT |
826 | if (warn_enum_compare == -1) |
827 | warn_enum_compare = c_dialect_cxx () ? 1 : 0; | |
828 | ||
bee6fa6d AN |
829 | /* -Wpacked-bitfield-compat is on by default for the C languages. The |
830 | warning is issued in stor-layout.c which is not part of the front-end so | |
831 | we need to selectively turn it on here. */ | |
832 | if (warn_packed_bitfield_compat == -1) | |
833 | warn_packed_bitfield_compat = 1; | |
9b439fe1 | 834 | |
0b6f2917 NB |
835 | /* Special format checking options don't work without -Wformat; warn if |
836 | they are used. */ | |
44c21c7f DD |
837 | if (!warn_format) |
838 | { | |
839 | warning (OPT_Wformat_y2k, | |
840 | "-Wformat-y2k ignored without -Wformat"); | |
841 | warning (OPT_Wformat_extra_args, | |
842 | "-Wformat-extra-args ignored without -Wformat"); | |
843 | warning (OPT_Wformat_zero_length, | |
844 | "-Wformat-zero-length ignored without -Wformat"); | |
845 | warning (OPT_Wformat_nonliteral, | |
846 | "-Wformat-nonliteral ignored without -Wformat"); | |
ca178f85 BK |
847 | warning (OPT_Wformat_contains_nul, |
848 | "-Wformat-contains-nul ignored without -Wformat"); | |
44c21c7f DD |
849 | warning (OPT_Wformat_security, |
850 | "-Wformat-security ignored without -Wformat"); | |
44c21c7f | 851 | } |
0b6f2917 | 852 | |
dc90f45b | 853 | /* -Wimplicit-function-declaration is enabled by default for C99. */ |
b8698a0f | 854 | if (warn_implicit_function_declaration == -1) |
dc90f45b | 855 | warn_implicit_function_declaration = flag_isoc99; |
c7463669 | 856 | |
92574c7c MP |
857 | /* -Wimplicit-int is enabled by default for C99. */ |
858 | if (warn_implicit_int == -1) | |
859 | warn_implicit_int = flag_isoc99; | |
860 | ||
0173bd2a MP |
861 | /* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 modes. */ |
862 | if (warn_shift_negative_value == -1) | |
863 | warn_shift_negative_value = (extra_warnings | |
864 | && (cxx_dialect >= cxx11 || flag_isoc99)); | |
865 | ||
1f26ac87 JM |
866 | /* Declone C++ 'structors if -Os. */ |
867 | if (flag_declone_ctor_dtor == -1) | |
868 | flag_declone_ctor_dtor = optimize_size; | |
869 | ||
62984918 JM |
870 | if (flag_abi_compat_version == 1) |
871 | { | |
872 | warning (0, "%<-fabi-compat-version=1%> is not supported, using =2"); | |
873 | flag_abi_compat_version = 2; | |
874 | } | |
875 | else if (flag_abi_compat_version == -1) | |
876 | { | |
877 | /* Generate compatibility aliases for ABI v2 (3.4-4.9) by default. */ | |
878 | flag_abi_compat_version = (flag_abi_version == 0 ? 2 : 0); | |
879 | ||
880 | /* But don't warn about backward compatibility unless explicitly | |
881 | requested with -Wabi=n. */ | |
882 | if (flag_abi_version == 0) | |
883 | warn_abi = false; | |
884 | } | |
885 | ||
785f21af JM |
886 | /* Change flag_abi_version to be the actual current ABI level for the |
887 | benefit of c_cpp_builtins. */ | |
888 | if (flag_abi_version == 0) | |
a03c9bf1 | 889 | flag_abi_version = 10; |
785f21af | 890 | |
e7fa68d5 | 891 | /* Set C++ standard to C++14 if not specified on the command line. */ |
129211bc | 892 | if (c_dialect_cxx () && cxx_dialect == cxx_unset) |
e7fa68d5 | 893 | set_std_cxx14 (/*ISO*/false); |
129211bc | 894 | |
604b2bfc | 895 | if (cxx_dialect >= cxx11) |
25339f10 JM |
896 | { |
897 | /* If we're allowing C++0x constructs, don't warn about C++98 | |
898 | identifiers which are keywords in C++0x. */ | |
765189ff | 899 | warn_cxx11_compat = 0; |
edff0c06 | 900 | cpp_opts->cpp_warn_cxx11_compat = 0; |
25339f10 JM |
901 | |
902 | if (warn_narrowing == -1) | |
903 | warn_narrowing = 1; | |
904 | } | |
905 | else if (warn_narrowing == -1) | |
906 | warn_narrowing = 0; | |
beeffe36 | 907 | |
20b06add JM |
908 | /* Global sized deallocation is new in C++14. */ |
909 | if (flag_sized_deallocation == -1) | |
910 | flag_sized_deallocation = (cxx_dialect >= cxx14); | |
911 | ||
5af057d8 JM |
912 | if (flag_extern_tls_init) |
913 | { | |
914 | #if !defined (ASM_OUTPUT_DEF) || !SUPPORTS_WEAK | |
915 | /* Lazy TLS initialization for a variable in another TU requires | |
916 | alias and weak reference support. */ | |
917 | if (flag_extern_tls_init > 0) | |
918 | sorry ("external TLS initialization functions not supported " | |
919 | "on this target"); | |
920 | flag_extern_tls_init = 0; | |
921 | #else | |
922 | flag_extern_tls_init = 1; | |
923 | #endif | |
924 | } | |
925 | ||
460bd0e3 NB |
926 | if (flag_preprocess_only) |
927 | { | |
63973df3 NB |
928 | /* Open the output now. We must do so even if flag_no_output is |
929 | on, because there may be other output than from the actual | |
930 | preprocessing (e.g. from -dM). */ | |
931 | if (out_fname[0] == '\0') | |
932 | out_stream = stdout; | |
933 | else | |
934 | out_stream = fopen (out_fname, "w"); | |
935 | ||
936 | if (out_stream == NULL) | |
9d10c9a9 | 937 | { |
40fecdd6 | 938 | fatal_error (input_location, "opening output file %s: %m", out_fname); |
c366ade5 | 939 | return false; |
9d10c9a9 | 940 | } |
63973df3 | 941 | |
d1bd0ded GK |
942 | if (num_in_fnames > 1) |
943 | error ("too many filenames given. Type %s --help for usage", | |
944 | progname); | |
945 | ||
9d10c9a9 | 946 | init_pp_output (out_stream); |
460bd0e3 | 947 | } |
9d10c9a9 NB |
948 | else |
949 | { | |
950 | init_c_lex (); | |
237e9384 JJ |
951 | |
952 | /* When writing a PCH file, avoid reading some other PCH file, | |
953 | because the default address space slot then can't be used | |
954 | for the output PCH file. */ | |
955 | if (pch_file) | |
f6007d99 JJ |
956 | { |
957 | c_common_no_more_pch (); | |
958 | /* Only -g0 and -gdwarf* are supported with PCH, for other | |
959 | debug formats we warn here and refuse to load any PCH files. */ | |
960 | if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG) | |
961 | warning (OPT_Wdeprecated, | |
962 | "the \"%s\" debug format cannot be used with " | |
963 | "pre-compiled headers", debug_type_names[write_symbols]); | |
964 | } | |
965 | else if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG) | |
237e9384 | 966 | c_common_no_more_pch (); |
460bd0e3 | 967 | |
9d10c9a9 | 968 | /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */ |
3c20847b | 969 | input_location = UNKNOWN_LOCATION; |
9d10c9a9 | 970 | } |
63973df3 | 971 | |
8e9ea4d7 PB |
972 | cb = cpp_get_callbacks (parse_in); |
973 | cb->file_change = cb_file_change; | |
974 | cb->dir_change = cb_dir_change; | |
4169c321 | 975 | cpp_post_options (parse_in); |
43f9a13c | 976 | init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in)); |
23345bbb | 977 | |
3c20847b | 978 | input_location = UNKNOWN_LOCATION; |
4bfec483 | 979 | |
8e9ea4d7 PB |
980 | *pfilename = this_input_filename |
981 | = cpp_read_main_file (parse_in, in_fnames[0]); | |
540554f4 | 982 | /* Don't do any compilation or preprocessing if there is no input file. */ |
8e9ea4d7 | 983 | if (this_input_filename == NULL) |
540554f4 JW |
984 | { |
985 | errorcount++; | |
986 | return false; | |
987 | } | |
8e9ea4d7 | 988 | |
8a4baa83 | 989 | if (flag_working_directory |
3f75a254 | 990 | && flag_preprocess_only && !flag_no_line_commands) |
8e9ea4d7 PB |
991 | pp_dir_change (parse_in, get_src_pwd ()); |
992 | ||
ba9b1f11 RG |
993 | /* Disable LTO output when outputting a precompiled header. */ |
994 | if (pch_file && flag_lto) | |
995 | { | |
996 | flag_lto = 0; | |
997 | flag_generate_lto = 0; | |
998 | } | |
999 | ||
4bfec483 NB |
1000 | return flag_preprocess_only; |
1001 | } | |
1002 | ||
1003 | /* Front end initialization common to C, ObjC and C++. */ | |
1004 | bool | |
2f6e4e97 | 1005 | c_common_init (void) |
4bfec483 | 1006 | { |
4bfec483 NB |
1007 | /* Set up preprocessor arithmetic. Must be done after call to |
1008 | c_common_nodes_and_builtins for type nodes to be good. */ | |
1009 | cpp_opts->precision = TYPE_PRECISION (intmax_type_node); | |
1010 | cpp_opts->char_precision = TYPE_PRECISION (char_type_node); | |
1011 | cpp_opts->int_precision = TYPE_PRECISION (integer_type_node); | |
1012 | cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node); | |
8df83eae | 1013 | cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node); |
e6cc3a24 ZW |
1014 | cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN; |
1015 | ||
1016 | /* This can't happen until after wchar_precision and bytes_big_endian | |
1017 | are known. */ | |
1018 | cpp_init_iconv (parse_in); | |
460bd0e3 | 1019 | |
3fd30b88 | 1020 | if (version_flag) |
8ca92d04 SB |
1021 | { |
1022 | int i; | |
1023 | fputs ("Compiler executable checksum: ", stderr); | |
1024 | for (i = 0; i < 16; i++) | |
1025 | fprintf (stderr, "%02x", executable_checksum[i]); | |
1026 | putc ('\n', stderr); | |
1027 | } | |
3fd30b88 | 1028 | |
a25a8f3b JJ |
1029 | /* Has to wait until now so that cpplib has its hash table. */ |
1030 | init_pragma (); | |
1031 | ||
9d10c9a9 NB |
1032 | if (flag_preprocess_only) |
1033 | { | |
c98cd5bf | 1034 | c_finish_options (); |
8e9ea4d7 | 1035 | preprocess_file (parse_in); |
4bfec483 | 1036 | return false; |
9d10c9a9 NB |
1037 | } |
1038 | ||
4bfec483 | 1039 | return true; |
76c3e73e NB |
1040 | } |
1041 | ||
d1bd0ded GK |
1042 | /* Initialize the integrated preprocessor after debug output has been |
1043 | initialized; loop over each input file. */ | |
23345bbb | 1044 | void |
b37421c6 | 1045 | c_common_parse_file (void) |
23345bbb | 1046 | { |
9affb2c7 ZW |
1047 | unsigned int i; |
1048 | ||
9affb2c7 ZW |
1049 | i = 0; |
1050 | for (;;) | |
1051 | { | |
c98cd5bf | 1052 | c_finish_options (); |
f8a36c78 TJ |
1053 | /* Open the dump files to use for the original and class dump output |
1054 | here, to be used during parsing for the current file. */ | |
1055 | original_dump_file = dump_begin (TDI_original, &original_dump_flags); | |
1056 | class_dump_file = dump_begin (TDI_class, &class_dump_flags); | |
9affb2c7 ZW |
1057 | pch_init (); |
1058 | push_file_scope (); | |
1059 | c_parse_file (); | |
9affb2c7 | 1060 | pop_file_scope (); |
9e9945c5 DB |
1061 | /* And end the main input file, if the debug writer wants it */ |
1062 | if (debug_hooks->start_end_main_source_file) | |
1063 | (*debug_hooks->end_source_file) (0); | |
9affb2c7 ZW |
1064 | if (++i >= num_in_fnames) |
1065 | break; | |
1066 | cpp_undef_all (parse_in); | |
97f6bd40 | 1067 | cpp_clear_file_cache (parse_in); |
9affb2c7 ZW |
1068 | this_input_filename |
1069 | = cpp_read_main_file (parse_in, in_fnames[i]); | |
f8a36c78 TJ |
1070 | if (original_dump_file) |
1071 | { | |
1072 | dump_end (TDI_original, original_dump_file); | |
1073 | original_dump_file = NULL; | |
1074 | } | |
1075 | if (class_dump_file) | |
1076 | { | |
1077 | dump_end (TDI_class, class_dump_file); | |
1078 | class_dump_file = NULL; | |
1079 | } | |
9affb2c7 | 1080 | /* If an input file is missing, abandon further compilation. |
c22cacf3 | 1081 | cpplib has issued a diagnostic. */ |
9affb2c7 ZW |
1082 | if (!this_input_filename) |
1083 | break; | |
1084 | } | |
d7438551 AH |
1085 | |
1086 | c_parse_final_cleanups (); | |
23345bbb | 1087 | } |
f8a36c78 TJ |
1088 | |
1089 | /* Returns the appropriate dump file for PHASE to dump with FLAGS. */ | |
1090 | FILE * | |
1091 | get_dump_info (int phase, int *flags) | |
1092 | { | |
1093 | gcc_assert (phase == TDI_original || phase == TDI_class); | |
1094 | if (phase == TDI_original) | |
1095 | { | |
1096 | *flags = original_dump_flags; | |
1097 | return original_dump_file; | |
1098 | } | |
1099 | else | |
1100 | { | |
1101 | *flags = class_dump_flags; | |
1102 | return class_dump_file; | |
1103 | } | |
1104 | } | |
23345bbb | 1105 | |
76c3e73e NB |
1106 | /* Common finish hook for the C, ObjC and C++ front ends. */ |
1107 | void | |
2f6e4e97 | 1108 | c_common_finish (void) |
76c3e73e NB |
1109 | { |
1110 | FILE *deps_stream = NULL; | |
1111 | ||
148e4216 | 1112 | /* Don't write the deps file if there are errors. */ |
1da2ed5f | 1113 | if (cpp_opts->deps.style != DEPS_NONE && !seen_error ()) |
76c3e73e NB |
1114 | { |
1115 | /* If -M or -MM was seen without -MF, default output to the | |
1116 | output stream. */ | |
f4ff5a69 | 1117 | if (!deps_file) |
76c3e73e NB |
1118 | deps_stream = out_stream; |
1119 | else | |
1120 | { | |
f4ff5a69 | 1121 | deps_stream = fopen (deps_file, deps_append ? "a": "w"); |
76c3e73e | 1122 | if (!deps_stream) |
40fecdd6 JM |
1123 | fatal_error (input_location, "opening dependency file %s: %m", |
1124 | deps_file); | |
76c3e73e NB |
1125 | } |
1126 | } | |
1127 | ||
1128 | /* For performance, avoid tearing down cpplib's internal structures | |
1129 | with cpp_destroy (). */ | |
148e4216 | 1130 | cpp_finish (parse_in, deps_stream); |
76c3e73e NB |
1131 | |
1132 | if (deps_stream && deps_stream != out_stream | |
1133 | && (ferror (deps_stream) || fclose (deps_stream))) | |
40fecdd6 | 1134 | fatal_error (input_location, "closing dependency file %s: %m", deps_file); |
76c3e73e NB |
1135 | |
1136 | if (out_stream && (ferror (out_stream) || fclose (out_stream))) | |
40fecdd6 | 1137 | fatal_error (input_location, "when writing output to %s: %m", out_fname); |
76c3e73e NB |
1138 | } |
1139 | ||
76c3e73e NB |
1140 | /* Either of two environment variables can specify output of |
1141 | dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE | |
1142 | DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to | |
1143 | and DEPS_TARGET is the target to mention in the deps. They also | |
1144 | result in dependency information being appended to the output file | |
182d89a3 NB |
1145 | rather than overwriting it, and like Sun's compiler |
1146 | SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */ | |
76c3e73e | 1147 | static void |
2f6e4e97 | 1148 | check_deps_environment_vars (void) |
76c3e73e NB |
1149 | { |
1150 | char *spec; | |
1151 | ||
71f3e391 | 1152 | spec = getenv ("DEPENDENCIES_OUTPUT"); |
76c3e73e | 1153 | if (spec) |
f4ff5a69 | 1154 | cpp_opts->deps.style = DEPS_USER; |
76c3e73e NB |
1155 | else |
1156 | { | |
71f3e391 | 1157 | spec = getenv ("SUNPRO_DEPENDENCIES"); |
76c3e73e | 1158 | if (spec) |
182d89a3 NB |
1159 | { |
1160 | cpp_opts->deps.style = DEPS_SYSTEM; | |
1161 | cpp_opts->deps.ignore_main_file = true; | |
1162 | } | |
76c3e73e NB |
1163 | } |
1164 | ||
1165 | if (spec) | |
1166 | { | |
1167 | /* Find the space before the DEPS_TARGET, if there is one. */ | |
1168 | char *s = strchr (spec, ' '); | |
1169 | if (s) | |
1170 | { | |
1171 | /* Let the caller perform MAKE quoting. */ | |
f4ff5a69 | 1172 | defer_opt (OPT_MT, s + 1); |
76c3e73e NB |
1173 | *s = '\0'; |
1174 | } | |
1175 | ||
1176 | /* Command line -MF overrides environment variables and default. */ | |
f4ff5a69 NB |
1177 | if (!deps_file) |
1178 | deps_file = spec; | |
76c3e73e | 1179 | |
f4ff5a69 | 1180 | deps_append = 1; |
1b3c8f46 | 1181 | deps_seen = true; |
f4ff5a69 NB |
1182 | } |
1183 | } | |
1184 | ||
1185 | /* Handle deferred command line switches. */ | |
1186 | static void | |
2f6e4e97 | 1187 | handle_deferred_opts (void) |
f4ff5a69 NB |
1188 | { |
1189 | size_t i; | |
c6e83800 ZW |
1190 | struct deps *deps; |
1191 | ||
1192 | /* Avoid allocating the deps buffer if we don't need it. | |
1193 | (This flag may be true without there having been -MT or -MQ | |
1194 | options, but we'll still need the deps buffer.) */ | |
1195 | if (!deps_seen) | |
1196 | return; | |
1197 | ||
1198 | deps = cpp_get_deps (parse_in); | |
f4ff5a69 NB |
1199 | |
1200 | for (i = 0; i < deferred_count; i++) | |
1201 | { | |
1202 | struct deferred_opt *opt = &deferred_opts[i]; | |
1203 | ||
c1bad961 | 1204 | if (opt->code == OPT_MT || opt->code == OPT_MQ) |
c6e83800 | 1205 | deps_add_target (deps, opt->arg, opt->code == OPT_MQ); |
f4ff5a69 | 1206 | } |
f4ff5a69 NB |
1207 | } |
1208 | ||
1209 | /* These settings are appropriate for GCC, but not necessarily so for | |
1210 | cpplib as a library. */ | |
1211 | static void | |
2f6e4e97 | 1212 | sanitize_cpp_opts (void) |
f4ff5a69 NB |
1213 | { |
1214 | /* If we don't know what style of dependencies to output, complain | |
1215 | if any other dependency switches have been given. */ | |
1216 | if (deps_seen && cpp_opts->deps.style == DEPS_NONE) | |
1217 | error ("to generate dependencies you must specify either -M or -MM"); | |
1218 | ||
1219 | /* -dM and dependencies suppress normal output; do it here so that | |
1220 | the last -d[MDN] switch overrides earlier ones. */ | |
63973df3 NB |
1221 | if (flag_dump_macros == 'M') |
1222 | flag_no_output = 1; | |
f4ff5a69 | 1223 | |
ccfc4c91 OW |
1224 | /* By default, -fdirectives-only implies -dD. This allows subsequent phases |
1225 | to perform proper macro expansion. */ | |
1226 | if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros) | |
1227 | flag_dump_macros = 'D'; | |
1228 | ||
f4ff5a69 NB |
1229 | /* Disable -dD, -dN and -dI if normal output is suppressed. Allow |
1230 | -dM since at least glibc relies on -M -dM to work. */ | |
6c6cfbfd | 1231 | /* Also, flag_no_output implies flag_no_line_commands, always. */ |
63973df3 | 1232 | if (flag_no_output) |
f4ff5a69 | 1233 | { |
63973df3 NB |
1234 | if (flag_dump_macros != 'M') |
1235 | flag_dump_macros = 0; | |
1236 | flag_dump_includes = 0; | |
f9c65623 | 1237 | flag_no_line_commands = 1; |
76c3e73e | 1238 | } |
4822e563 TT |
1239 | else if (cpp_opts->deps.missing_files) |
1240 | error ("-MG may only be used with -M or -MM"); | |
f4ff5a69 NB |
1241 | |
1242 | cpp_opts->unsigned_char = !flag_signed_char; | |
1243 | cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS; | |
1244 | ||
9c650d90 | 1245 | /* Wlong-long is disabled by default. It is enabled by: |
c1771a20 | 1246 | [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or |
2b71f4a4 MLI |
1247 | [-Wpedantic | -Wtraditional] -std=non-c99 |
1248 | ||
1249 | Either -Wlong-long or -Wno-long-long override any other settings. | |
1250 | ??? These conditions should be handled in c.opt. */ | |
1251 | if (warn_long_long == -1) | |
1252 | { | |
1253 | warn_long_long = ((pedantic || warn_traditional) | |
1254 | && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)); | |
1255 | cpp_opts->cpp_warn_long_long = warn_long_long; | |
1256 | } | |
b20d9f0c AO |
1257 | |
1258 | /* If we're generating preprocessor output, emit current directory | |
1259 | if explicitly requested or if debugging information is enabled. | |
1260 | ??? Maybe we should only do it for debugging formats that | |
1261 | actually output the current directory? */ | |
1262 | if (flag_working_directory == -1) | |
1263 | flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE); | |
ccfc4c91 OW |
1264 | |
1265 | if (cpp_opts->directives_only) | |
1266 | { | |
34a180a6 | 1267 | if (cpp_warn_unused_macros) |
ccfc4c91 OW |
1268 | error ("-fdirectives-only is incompatible with -Wunused_macros"); |
1269 | if (cpp_opts->traditional) | |
1270 | error ("-fdirectives-only is incompatible with -traditional"); | |
1271 | } | |
f4ff5a69 NB |
1272 | } |
1273 | ||
5793b276 NB |
1274 | /* Add include path with a prefix at the front of its name. */ |
1275 | static void | |
2f6e4e97 | 1276 | add_prefixed_path (const char *suffix, size_t chain) |
5793b276 | 1277 | { |
52999738 | 1278 | char *path; |
5793b276 | 1279 | const char *prefix; |
52999738 | 1280 | size_t prefix_len, suffix_len; |
5793b276 | 1281 | |
52999738 ZW |
1282 | suffix_len = strlen (suffix); |
1283 | prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR; | |
1284 | prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len; | |
1285 | ||
5d038c4c | 1286 | path = (char *) xmalloc (prefix_len + suffix_len + 1); |
52999738 ZW |
1287 | memcpy (path, prefix, prefix_len); |
1288 | memcpy (path + prefix_len, suffix, suffix_len); | |
1289 | path[prefix_len + suffix_len] = '\0'; | |
1290 | ||
b02398bd | 1291 | add_path (path, chain, 0, false); |
5793b276 NB |
1292 | } |
1293 | ||
8e9ea4d7 PB |
1294 | /* Handle -D, -U, -A, -imacros, and the first -include. */ |
1295 | static void | |
c98cd5bf | 1296 | c_finish_options (void) |
255c10b1 | 1297 | { |
255c10b1 NB |
1298 | if (!cpp_opts->preprocessed) |
1299 | { | |
c1bad961 NB |
1300 | size_t i; |
1301 | ||
b35e0fa0 | 1302 | cb_file_change (parse_in, |
0e50b624 DM |
1303 | linemap_check_ordinary (linemap_add (line_table, |
1304 | LC_RENAME, 0, | |
1305 | _("<built-in>"), | |
1306 | 0))); | |
b35e0fa0 JJ |
1307 | /* Make sure all of the builtins about to be declared have |
1308 | BUILTINS_LOCATION has their source_location. */ | |
1309 | source_location builtins_loc = BUILTINS_LOCATION; | |
1310 | cpp_force_token_locations (parse_in, &builtins_loc); | |
1311 | ||
1312 | cpp_init_builtins (parse_in, flag_hosted); | |
1313 | c_cpp_builtins (parse_in); | |
1314 | ||
1315 | cpp_stop_forcing_token_locations (parse_in); | |
78b8811a HPN |
1316 | |
1317 | /* We're about to send user input to cpplib, so make it warn for | |
1318 | things that we previously (when we sent it internal definitions) | |
1319 | told it to not warn. | |
1320 | ||
1321 | C99 permits implementation-defined characters in identifiers. | |
1322 | The documented meaning of -std= is to turn off extensions that | |
1323 | conflict with the specified standard, and since a strictly | |
1324 | conforming program cannot contain a '$', we do not condition | |
1325 | their acceptance on the -std= setting. */ | |
e3339d0f | 1326 | cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99); |
78b8811a | 1327 | |
112598f4 | 1328 | cb_file_change (parse_in, |
0e50b624 DM |
1329 | linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0, |
1330 | _("<command-line>"), 0))); | |
112598f4 | 1331 | |
c1bad961 NB |
1332 | for (i = 0; i < deferred_count; i++) |
1333 | { | |
1334 | struct deferred_opt *opt = &deferred_opts[i]; | |
1335 | ||
1336 | if (opt->code == OPT_D) | |
1337 | cpp_define (parse_in, opt->arg); | |
1338 | else if (opt->code == OPT_U) | |
1339 | cpp_undef (parse_in, opt->arg); | |
1340 | else if (opt->code == OPT_A) | |
1341 | { | |
1342 | if (opt->arg[0] == '-') | |
1343 | cpp_unassert (parse_in, opt->arg + 1); | |
1344 | else | |
1345 | cpp_assert (parse_in, opt->arg); | |
1346 | } | |
1347 | } | |
255c10b1 | 1348 | |
9d000e83 JJ |
1349 | /* Start the main input file, if the debug writer wants it. */ |
1350 | if (debug_hooks->start_end_main_source_file | |
1351 | && !flag_preprocess_only) | |
1352 | (*debug_hooks->start_source_file) (0, this_input_filename); | |
1353 | ||
c1bad961 | 1354 | /* Handle -imacros after -D and -U. */ |
255c10b1 NB |
1355 | for (i = 0; i < deferred_count; i++) |
1356 | { | |
1357 | struct deferred_opt *opt = &deferred_opts[i]; | |
1358 | ||
1359 | if (opt->code == OPT_imacros | |
1360 | && cpp_push_include (parse_in, opt->arg)) | |
9b49a0aa | 1361 | { |
6614fd40 | 1362 | /* Disable push_command_line_include callback for now. */ |
9b49a0aa PB |
1363 | include_cursor = deferred_count + 1; |
1364 | cpp_scan_nooutput (parse_in); | |
1365 | } | |
255c10b1 NB |
1366 | } |
1367 | } | |
9d000e83 JJ |
1368 | else |
1369 | { | |
1370 | if (cpp_opts->directives_only) | |
1371 | cpp_init_special_builtins (parse_in); | |
1372 | ||
1373 | /* Start the main input file, if the debug writer wants it. */ | |
1374 | if (debug_hooks->start_end_main_source_file | |
1375 | && !flag_preprocess_only) | |
1376 | (*debug_hooks->start_source_file) (0, this_input_filename); | |
1377 | } | |
255c10b1 | 1378 | |
e6ebd07b | 1379 | include_cursor = 0; |
255c10b1 NB |
1380 | push_command_line_include (); |
1381 | } | |
1382 | ||
23345bbb NB |
1383 | /* Give CPP the next file given by -include, if any. */ |
1384 | static void | |
2f6e4e97 | 1385 | push_command_line_include (void) |
23345bbb | 1386 | { |
cdc94aca MP |
1387 | /* This can happen if disabled by -imacros for example. |
1388 | Punt so that we don't set "<command-line>" as the filename for | |
1389 | the header. */ | |
1390 | if (include_cursor > deferred_count) | |
1391 | return; | |
1392 | ||
1efcb8c6 JM |
1393 | if (!done_preinclude) |
1394 | { | |
1395 | done_preinclude = true; | |
1396 | if (flag_hosted && std_inc && !cpp_opts->preprocessed) | |
1397 | { | |
1398 | const char *preinc = targetcm.c_preinclude (); | |
1399 | if (preinc && cpp_push_default_include (parse_in, preinc)) | |
1400 | return; | |
1401 | } | |
1402 | } | |
1403 | ||
1404 | pch_cpp_save_state (); | |
1405 | ||
23345bbb NB |
1406 | while (include_cursor < deferred_count) |
1407 | { | |
1408 | struct deferred_opt *opt = &deferred_opts[include_cursor++]; | |
2f6e4e97 | 1409 | |
3f75a254 | 1410 | if (!cpp_opts->preprocessed && opt->code == OPT_include |
31703a61 | 1411 | && cpp_push_include (parse_in, opt->arg)) |
23345bbb NB |
1412 | return; |
1413 | } | |
1414 | ||
1415 | if (include_cursor == deferred_count) | |
1416 | { | |
31703a61 | 1417 | include_cursor++; |
23345bbb | 1418 | /* -Wunused-macros should only warn about macros defined hereafter. */ |
34a180a6 | 1419 | cpp_opts->warn_unused_macros = cpp_warn_unused_macros; |
8e9ea4d7 | 1420 | /* Restore the line map from <command line>. */ |
3f75a254 | 1421 | if (!cpp_opts->preprocessed) |
3e6da82b | 1422 | cpp_change_file (parse_in, LC_RENAME, this_input_filename); |
8e9ea4d7 PB |
1423 | |
1424 | /* Set this here so the client can change the option if it wishes, | |
1425 | and after stacking the main file so we don't trace the main file. */ | |
5ffeb913 | 1426 | line_table->trace_includes = cpp_opts->print_include_names; |
23345bbb NB |
1427 | } |
1428 | } | |
1429 | ||
1430 | /* File change callback. Has to handle -include files. */ | |
1431 | static void | |
e18476eb | 1432 | cb_file_change (cpp_reader * ARG_UNUSED (pfile), |
0e50b624 | 1433 | const line_map_ordinary *new_map) |
23345bbb NB |
1434 | { |
1435 | if (flag_preprocess_only) | |
1436 | pp_file_change (new_map); | |
1437 | else | |
1438 | fe_file_change (new_map); | |
1439 | ||
b826515a BS |
1440 | if (new_map |
1441 | && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME)) | |
1442 | { | |
1443 | /* Signal to plugins that a file is included. This could happen | |
1444 | several times with the same file path, e.g. because of | |
1445 | several '#include' or '#line' directives... */ | |
1446 | invoke_plugin_callbacks | |
1447 | (PLUGIN_INCLUDE_FILE, | |
1448 | const_cast<char*> (ORDINARY_MAP_FILE_NAME (new_map))); | |
1449 | } | |
1450 | ||
31703a61 | 1451 | if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))) |
1efcb8c6 JM |
1452 | { |
1453 | pch_cpp_save_state (); | |
1454 | push_command_line_include (); | |
1455 | } | |
23345bbb NB |
1456 | } |
1457 | ||
8e9ea4d7 | 1458 | void |
e18476eb | 1459 | cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir) |
8e9ea4d7 | 1460 | { |
3f75a254 | 1461 | if (!set_src_pwd (dir)) |
d4ee4d25 | 1462 | warning (0, "too late for # directive to set debug directory"); |
8e9ea4d7 PB |
1463 | } |
1464 | ||
f4ff5a69 NB |
1465 | /* Set the C 89 standard (with 1994 amendments if C94, without GNU |
1466 | extensions if ISO). There is no concept of gnu94. */ | |
1467 | static void | |
2f6e4e97 | 1468 | set_std_c89 (int c94, int iso) |
f4ff5a69 NB |
1469 | { |
1470 | cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89); | |
1471 | flag_iso = iso; | |
1472 | flag_no_asm = iso; | |
1473 | flag_no_gnu_keywords = iso; | |
1474 | flag_no_nonansi_builtin = iso; | |
f4ff5a69 NB |
1475 | flag_isoc94 = c94; |
1476 | flag_isoc99 = 0; | |
48b0b196 | 1477 | flag_isoc11 = 0; |
dcc97066 | 1478 | lang_hooks.name = "GNU C89"; |
76c3e73e NB |
1479 | } |
1480 | ||
b4a93904 NB |
1481 | /* Set the C 99 standard (without GNU extensions if ISO). */ |
1482 | static void | |
2f6e4e97 | 1483 | set_std_c99 (int iso) |
b4a93904 NB |
1484 | { |
1485 | cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99); | |
1486 | flag_no_asm = iso; | |
1487 | flag_no_nonansi_builtin = iso; | |
b4a93904 | 1488 | flag_iso = iso; |
48b0b196 | 1489 | flag_isoc11 = 0; |
2778d766 JM |
1490 | flag_isoc99 = 1; |
1491 | flag_isoc94 = 1; | |
dcc97066 | 1492 | lang_hooks.name = "GNU C99"; |
2778d766 JM |
1493 | } |
1494 | ||
48b0b196 | 1495 | /* Set the C 11 standard (without GNU extensions if ISO). */ |
2778d766 | 1496 | static void |
48b0b196 | 1497 | set_std_c11 (int iso) |
2778d766 | 1498 | { |
48b0b196 | 1499 | cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11); |
2778d766 JM |
1500 | flag_no_asm = iso; |
1501 | flag_no_nonansi_builtin = iso; | |
1502 | flag_iso = iso; | |
48b0b196 | 1503 | flag_isoc11 = 1; |
b4a93904 NB |
1504 | flag_isoc99 = 1; |
1505 | flag_isoc94 = 1; | |
dcc97066 | 1506 | lang_hooks.name = "GNU C11"; |
b4a93904 NB |
1507 | } |
1508 | ||
f749a36b NB |
1509 | /* Set the C++ 98 standard (without GNU extensions if ISO). */ |
1510 | static void | |
2f6e4e97 | 1511 | set_std_cxx98 (int iso) |
f749a36b NB |
1512 | { |
1513 | cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX); | |
1514 | flag_no_gnu_keywords = iso; | |
1515 | flag_no_nonansi_builtin = iso; | |
f749a36b | 1516 | flag_iso = iso; |
c1ae8be5 | 1517 | cxx_dialect = cxx98; |
dcc97066 | 1518 | lang_hooks.name = "GNU C++98"; |
f749a36b NB |
1519 | } |
1520 | ||
97e3ad20 | 1521 | /* Set the C++ 2011 standard (without GNU extensions if ISO). */ |
966541e3 | 1522 | static void |
97e3ad20 | 1523 | set_std_cxx11 (int iso) |
966541e3 | 1524 | { |
97e3ad20 | 1525 | cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11); |
966541e3 DG |
1526 | flag_no_gnu_keywords = iso; |
1527 | flag_no_nonansi_builtin = iso; | |
1528 | flag_iso = iso; | |
97e3ad20 | 1529 | /* C++11 includes the C99 standard library. */ |
fcb21722 JM |
1530 | flag_isoc94 = 1; |
1531 | flag_isoc99 = 1; | |
97e3ad20 | 1532 | cxx_dialect = cxx11; |
dcc97066 | 1533 | lang_hooks.name = "GNU C++11"; |
966541e3 DG |
1534 | } |
1535 | ||
028aee17 | 1536 | /* Set the C++ 2014 draft standard (without GNU extensions if ISO). */ |
552b8185 | 1537 | static void |
e4276ba5 | 1538 | set_std_cxx14 (int iso) |
552b8185 | 1539 | { |
e4276ba5 | 1540 | cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14); |
552b8185 JM |
1541 | flag_no_gnu_keywords = iso; |
1542 | flag_no_nonansi_builtin = iso; | |
1543 | flag_iso = iso; | |
1544 | /* C++11 includes the C99 standard library. */ | |
1545 | flag_isoc94 = 1; | |
1546 | flag_isoc99 = 1; | |
e4276ba5 | 1547 | cxx_dialect = cxx14; |
dcc97066 | 1548 | lang_hooks.name = "GNU C++14"; |
552b8185 JM |
1549 | } |
1550 | ||
da73100b JM |
1551 | /* Set the C++ 201z draft standard (without GNU extensions if ISO). */ |
1552 | static void | |
1553 | set_std_cxx1z (int iso) | |
1554 | { | |
e4276ba5 | 1555 | cpp_set_lang (parse_in, iso ? CLK_CXX1Z: CLK_GNUCXX1Z); |
da73100b JM |
1556 | flag_no_gnu_keywords = iso; |
1557 | flag_no_nonansi_builtin = iso; | |
1558 | flag_iso = iso; | |
1559 | /* C++11 includes the C99 standard library. */ | |
1560 | flag_isoc94 = 1; | |
1561 | flag_isoc99 = 1; | |
e4276ba5 | 1562 | flag_isoc11 = 1; |
da73100b | 1563 | cxx_dialect = cxx1z; |
dcc97066 | 1564 | lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standarization. */ |
da73100b JM |
1565 | } |
1566 | ||
4b7091eb | 1567 | /* Args to -d specify what to dump. Silently ignore |
05713b80 | 1568 | unrecognized options; they may be aimed at toplev.c. */ |
0b6f2917 | 1569 | static void |
2f6e4e97 | 1570 | handle_OPT_d (const char *arg) |
0b6f2917 | 1571 | { |
4b7091eb NB |
1572 | char c; |
1573 | ||
1574 | while ((c = *arg++) != '\0') | |
1575 | switch (c) | |
1576 | { | |
63973df3 NB |
1577 | case 'M': /* Dump macros only. */ |
1578 | case 'N': /* Dump names. */ | |
1579 | case 'D': /* Dump definitions. */ | |
93d45d9e | 1580 | case 'U': /* Dump used macros. */ |
63973df3 | 1581 | flag_dump_macros = c; |
4b7091eb NB |
1582 | break; |
1583 | ||
1584 | case 'I': | |
63973df3 | 1585 | flag_dump_includes = 1; |
4b7091eb NB |
1586 | break; |
1587 | } | |
0b6f2917 | 1588 | } |