tree-core.h: Include symtab.h.
[gcc.git] / gcc / c-family / c-opts.c
1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "options.h"
25 #include "alias.h"
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"
32 #include "diagnostic.h"
33 #include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
34 #include "intl.h"
35 #include "cppdefault.h"
36 #include "incpath.h"
37 #include "debug.h" /* For debug_hooks. */
38 #include "opts.h"
39 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
40 #include "mkdeps.h"
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. */
47 #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
48 #include "dumpfile.h"
49
50 #ifndef DOLLARS_IN_IDENTIFIERS
51 # define DOLLARS_IN_IDENTIFIERS true
52 #endif
53
54 #ifndef TARGET_SYSTEM_ROOT
55 # define TARGET_SYSTEM_ROOT NULL
56 #endif
57
58 #ifndef TARGET_OPTF
59 #define TARGET_OPTF(ARG)
60 #endif
61
62 /* CPP's options. */
63 cpp_options *cpp_opts;
64
65 /* Input filename. */
66 static const char *this_input_filename;
67
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
75 /* If dependency switches (-MF etc.) have been given. */
76 static bool deps_seen;
77
78 /* If -v seen. */
79 static bool verbose;
80
81 /* Dependency output file. */
82 static const char *deps_file;
83
84 /* The prefix given by -iprefix, if any. */
85 static const char *iprefix;
86
87 /* The multilib directory given by -imultilib, if any. */
88 static const char *imultilib;
89
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
102 /* Number of deferred options. */
103 static size_t deferred_count;
104
105 /* Number of deferred options scanned for -include. */
106 static size_t include_cursor;
107
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
114 /* Whether any standard preincluded header has been preincluded. */
115 static bool done_preinclude;
116
117 static void handle_OPT_d (const char *);
118 static void set_std_cxx98 (int);
119 static void set_std_cxx11 (int);
120 static void set_std_cxx14 (int);
121 static void set_std_cxx1z (int);
122 static void set_std_c89 (int, int);
123 static void set_std_c99 (int);
124 static void set_std_c11 (int);
125 static void 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);
130 static void cb_file_change (cpp_reader *, const line_map_ordinary *);
131 static void cb_dir_change (cpp_reader *, const char *);
132 static void c_finish_options (void);
133
134 #ifndef STDC_0_IN_SYSTEM_HEADERS
135 #define STDC_0_IN_SYSTEM_HEADERS 0
136 #endif
137
138 /* Holds switches parsed by c_common_handle_option (), but whose
139 handling is deferred to c_common_post_options (). */
140 static void defer_opt (enum opt_code, const char *);
141 static struct deferred_opt
142 {
143 enum opt_code code;
144 const char *arg;
145 } *deferred_opts;
146
147
148 extern const unsigned int
149 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
150
151 /* Defer option CODE with argument ARG. */
152 static void
153 defer_opt (enum opt_code code, const char *arg)
154 {
155 deferred_opts[deferred_count].code = code;
156 deferred_opts[deferred_count].arg = arg;
157 deferred_count++;
158 }
159
160 /* Return language mask for option parsing. */
161 unsigned int
162 c_common_option_lang_mask (void)
163 {
164 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
165
166 return lang_flags[c_language];
167 }
168
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
182 /* Common default settings for diagnostics. */
183 void
184 c_common_diagnostics_set_defaults (diagnostic_context *context)
185 {
186 diagnostic_finalizer (context) = c_diagnostic_finalizer;
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
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
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;
225
226 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
227 ident_hash, line_table);
228 cb = cpp_get_callbacks (parse_in);
229 cb->error = c_cpp_error;
230
231 cpp_opts = cpp_get_options (parse_in);
232 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
233 cpp_opts->objc = c_dialect_objc ();
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
239 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
240
241 if (c_language == clk_c)
242 {
243 /* The default for C is gnu11. */
244 set_std_c11 (false /* ISO */);
245
246 /* If preprocessing assembly language, accept any of the C-family
247 front end options since the driver may pass them through. */
248 for (i = 1; i < decoded_options_count; i++)
249 if (decoded_options[i].opt_index == OPT_lang_asm)
250 {
251 accept_all_c_family_options = true;
252 break;
253 }
254 }
255 }
256
257 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
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
261 c_common_handle_option (size_t scode, const char *arg, int value,
262 int kind, location_t loc,
263 const struct cl_option_handlers *handlers)
264 {
265 const struct cl_option *option = &cl_options[scode];
266 enum opt_code code = (enum opt_code) scode;
267 bool result = true;
268
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);
272
273 switch (code)
274 {
275 default:
276 if (cl_options[code].flags & c_family_lang_mask)
277 {
278 if ((option->flags & CL_TARGET)
279 && ! targetcm.handle_c_option (scode, arg, value))
280 result = false;
281 break;
282 }
283 result = false;
284 break;
285
286 case OPT__output_pch_:
287 pch_file = arg;
288 break;
289
290 case OPT_A:
291 defer_opt (code, arg);
292 break;
293
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
303 case OPT_D:
304 defer_opt (code, arg);
305 break;
306
307 case OPT_H:
308 cpp_opts->print_include_names = 1;
309 break;
310
311 case OPT_F:
312 TARGET_OPTF (xstrdup (arg));
313 break;
314
315 case OPT_I:
316 if (strcmp (arg, "-"))
317 add_path (xstrdup (arg), BRACKET, 0, true);
318 else
319 {
320 if (quote_chain_split)
321 error ("-I- specified twice");
322 quote_chain_split = true;
323 split_quote_chain ();
324 inform (input_location, "obsolete option -I- used, please use -iquote instead");
325 }
326 break;
327
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);
335 flag_no_output = 1;
336 break;
337
338 case OPT_MD:
339 case OPT_MMD:
340 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
341 cpp_opts->deps.need_preprocessor_output = true;
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
366 case OPT_P:
367 flag_no_line_commands = 1;
368 break;
369
370 case OPT_U:
371 defer_opt (code, arg);
372 break;
373
374 case OPT_Wall:
375 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
376
377 cpp_opts->warn_num_sign_change = value;
378 break;
379
380 case OPT_Wunknown_pragmas:
381 /* Set to greater than 1, so that even unknown pragmas in
382 system headers will be warned about. */
383 /* ??? There is no way to handle this automatically for now. */
384 warn_unknown_pragmas = value * 2;
385 break;
386
387 case OPT_ansi:
388 if (!c_dialect_cxx ())
389 set_std_c89 (false, true);
390 else
391 set_std_cxx98 (true);
392 break;
393
394 case OPT_d:
395 handle_OPT_d (arg);
396 break;
397
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
408 case OPT_fcanonical_system_headers:
409 cpp_opts->canonical_system_headers = value;
410 break;
411
412 case OPT_fcond_mismatch:
413 if (!c_dialect_cxx ())
414 {
415 flag_cond_mismatch = value;
416 break;
417 }
418 warning (0, "switch %qs is no longer supported", option->opt_text);
419 break;
420
421 case OPT_fbuiltin_:
422 if (value)
423 result = false;
424 else
425 disable_builtin_function (arg);
426 break;
427
428 case OPT_fdirectives_only:
429 cpp_opts->directives_only = value;
430 break;
431
432 case OPT_fdollars_in_identifiers:
433 cpp_opts->dollars_in_ident = value;
434 break;
435
436 case OPT_ffreestanding:
437 value = !value;
438 /* Fall through.... */
439 case OPT_fhosted:
440 flag_hosted = value;
441 flag_no_builtin = !value;
442 break;
443
444 case OPT_fconstant_string_class_:
445 constant_string_class_name = arg;
446 break;
447
448 case OPT_fextended_identifiers:
449 cpp_opts->extended_identifiers = value;
450 break;
451
452 case OPT_foperator_names:
453 cpp_opts->operator_names = value;
454 break;
455
456 case OPT_fpch_deps:
457 cpp_opts->restore_pch_deps = value;
458 break;
459
460 case OPT_fpch_preprocess:
461 flag_pch_preprocess = value;
462 break;
463
464 case OPT_fpermissive:
465 flag_permissive = value;
466 global_dc->permissive = value;
467 break;
468
469 case OPT_fpreprocessed:
470 cpp_opts->preprocessed = value;
471 break;
472
473 case OPT_fdebug_cpp:
474 cpp_opts->debug = 1;
475 break;
476
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
489 case OPT_frepo:
490 flag_use_repository = value;
491 if (value)
492 flag_implicit_templates = 0;
493 break;
494
495 case OPT_ftabstop_:
496 /* It is documented that we silently ignore silly values. */
497 if (value >= 1 && value <= 100)
498 cpp_opts->tabstop = value;
499 break;
500
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
509 case OPT_finput_charset_:
510 cpp_opts->input_charset = arg;
511 break;
512
513 case OPT_ftemplate_depth_:
514 max_tinst_depth = value;
515 break;
516
517 case OPT_fvisibility_inlines_hidden:
518 visibility_options.inlines_hidden = value;
519 break;
520
521 case OPT_femit_struct_debug_baseonly:
522 set_struct_debug_option (&global_options, loc, "base");
523 break;
524
525 case OPT_femit_struct_debug_reduced:
526 set_struct_debug_option (&global_options, loc,
527 "dir:ord:sys,dir:gen:any,ind:base");
528 break;
529
530 case OPT_femit_struct_debug_detailed_:
531 set_struct_debug_option (&global_options, loc, arg);
532 break;
533
534 case OPT_fext_numeric_literals:
535 cpp_opts->ext_numeric_literals = value;
536 break;
537
538 case OPT_idirafter:
539 add_path (xstrdup (arg), AFTER, 0, true);
540 break;
541
542 case OPT_imacros:
543 case OPT_include:
544 defer_opt (code, arg);
545 break;
546
547 case OPT_imultilib:
548 imultilib = arg;
549 break;
550
551 case OPT_iprefix:
552 iprefix = arg;
553 break;
554
555 case OPT_iquote:
556 add_path (xstrdup (arg), QUOTE, 0, true);
557 break;
558
559 case OPT_isysroot:
560 sysroot = arg;
561 break;
562
563 case OPT_isystem:
564 add_path (xstrdup (arg), SYSTEM, 0, true);
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
575 case OPT_lang_asm:
576 cpp_set_lang (parse_in, CLK_ASM);
577 cpp_opts->dollars_in_ident = false;
578 break;
579
580 case OPT_nostdinc:
581 std_inc = false;
582 break;
583
584 case OPT_nostdinc__:
585 std_cxx_inc = false;
586 break;
587
588 case OPT_o:
589 if (!out_fname)
590 out_fname = arg;
591 else
592 error ("output filename specified twice");
593 break;
594
595 case OPT_print_objc_runtime_info:
596 print_struct_values = 1;
597 break;
598
599 case OPT_remap:
600 cpp_opts->remap = 1;
601 break;
602
603 case OPT_std_c__98:
604 case OPT_std_gnu__98:
605 if (!preprocessing_asm_p)
606 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
607 break;
608
609 case OPT_std_c__11:
610 case OPT_std_gnu__11:
611 if (!preprocessing_asm_p)
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 }
617 break;
618
619 case OPT_std_c__14:
620 case OPT_std_gnu__14:
621 if (!preprocessing_asm_p)
622 {
623 set_std_cxx14 (code == OPT_std_c__14 /* ISO */);
624 if (code == OPT_std_c__14)
625 cpp_opts->ext_numeric_literals = 0;
626 }
627 break;
628
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
639 case OPT_std_c90:
640 case OPT_std_iso9899_199409:
641 if (!preprocessing_asm_p)
642 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
643 break;
644
645 case OPT_std_gnu90:
646 if (!preprocessing_asm_p)
647 set_std_c89 (false /* c94 */, false /* ISO */);
648 break;
649
650 case OPT_std_c99:
651 if (!preprocessing_asm_p)
652 set_std_c99 (true /* ISO */);
653 break;
654
655 case OPT_std_gnu99:
656 if (!preprocessing_asm_p)
657 set_std_c99 (false /* ISO */);
658 break;
659
660 case OPT_std_c11:
661 if (!preprocessing_asm_p)
662 set_std_c11 (true /* ISO */);
663 break;
664
665 case OPT_std_gnu11:
666 if (!preprocessing_asm_p)
667 set_std_c11 (false /* ISO */);
668 break;
669
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
678 case OPT_v:
679 verbose = true;
680 break;
681 }
682
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 }
716
717 cpp_handle_option_auto (&global_options, scode, cpp_opts);
718 return result;
719 }
720
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
731 /* Post-switch processing. */
732 bool
733 c_common_post_options (const char **pfilename)
734 {
735 struct cpp_callbacks *cb;
736
737 /* Canonicalize the input and output filenames. */
738 if (in_fnames == NULL)
739 {
740 in_fnames = XNEWVEC (const char *, 1);
741 in_fnames[0] = "";
742 }
743 else if (strcmp (in_fnames[0], "-") == 0)
744 in_fnames[0] = "";
745
746 if (out_fname == NULL || !strcmp (out_fname, "-"))
747 out_fname = "";
748
749 if (cpp_opts->deps.style == DEPS_NONE)
750 check_deps_environment_vars ();
751
752 handle_deferred_opts ();
753
754 sanitize_cpp_opts ();
755
756 register_include_chains (parse_in, sysroot, iprefix, imultilib,
757 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
758
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
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
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
785 == (enum fp_contract_mode) 0)
786 && flag_unsafe_math_optimizations == 0)
787 flag_fp_contract_mode = FP_CONTRACT_OFF;
788
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
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
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
808 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
809 It is never enabled in C++, as the minimum limit is not normative
810 in that standard. */
811 if (c_dialect_cxx ())
812 warn_overlength_strings = 0;
813
814 /* Wmain is enabled by default in C++ but not in C. */
815 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
816 even if -Wall or -Wpedantic was given (warn_main will be 2 if set
817 by -Wall, 1 if set by -Wmain). */
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
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. */
826 if (warn_enum_compare == -1)
827 warn_enum_compare = c_dialect_cxx () ? 1 : 0;
828
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;
834
835 /* Special format checking options don't work without -Wformat; warn if
836 they are used. */
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");
847 warning (OPT_Wformat_contains_nul,
848 "-Wformat-contains-nul ignored without -Wformat");
849 warning (OPT_Wformat_security,
850 "-Wformat-security ignored without -Wformat");
851 }
852
853 /* -Wimplicit-function-declaration is enabled by default for C99. */
854 if (warn_implicit_function_declaration == -1)
855 warn_implicit_function_declaration = flag_isoc99;
856
857 /* -Wimplicit-int is enabled by default for C99. */
858 if (warn_implicit_int == -1)
859 warn_implicit_int = flag_isoc99;
860
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
866 /* Declone C++ 'structors if -Os. */
867 if (flag_declone_ctor_dtor == -1)
868 flag_declone_ctor_dtor = optimize_size;
869
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
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)
889 flag_abi_version = 10;
890
891 /* Set C++ standard to C++14 if not specified on the command line. */
892 if (c_dialect_cxx () && cxx_dialect == cxx_unset)
893 set_std_cxx14 (/*ISO*/false);
894
895 if (cxx_dialect >= cxx11)
896 {
897 /* If we're allowing C++0x constructs, don't warn about C++98
898 identifiers which are keywords in C++0x. */
899 warn_cxx11_compat = 0;
900 cpp_opts->cpp_warn_cxx11_compat = 0;
901
902 if (warn_narrowing == -1)
903 warn_narrowing = 1;
904 }
905 else if (warn_narrowing == -1)
906 warn_narrowing = 0;
907
908 /* Global sized deallocation is new in C++14. */
909 if (flag_sized_deallocation == -1)
910 flag_sized_deallocation = (cxx_dialect >= cxx14);
911
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
926 if (flag_preprocess_only)
927 {
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)
937 {
938 fatal_error (input_location, "opening output file %s: %m", out_fname);
939 return false;
940 }
941
942 if (num_in_fnames > 1)
943 error ("too many filenames given. Type %s --help for usage",
944 progname);
945
946 init_pp_output (out_stream);
947 }
948 else
949 {
950 init_c_lex ();
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)
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)
966 c_common_no_more_pch ();
967
968 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
969 input_location = UNKNOWN_LOCATION;
970 }
971
972 cb = cpp_get_callbacks (parse_in);
973 cb->file_change = cb_file_change;
974 cb->dir_change = cb_dir_change;
975 cpp_post_options (parse_in);
976 init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in));
977
978 input_location = UNKNOWN_LOCATION;
979
980 *pfilename = this_input_filename
981 = cpp_read_main_file (parse_in, in_fnames[0]);
982 /* Don't do any compilation or preprocessing if there is no input file. */
983 if (this_input_filename == NULL)
984 {
985 errorcount++;
986 return false;
987 }
988
989 if (flag_working_directory
990 && flag_preprocess_only && !flag_no_line_commands)
991 pp_dir_change (parse_in, get_src_pwd ());
992
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
1000 return flag_preprocess_only;
1001 }
1002
1003 /* Front end initialization common to C, ObjC and C++. */
1004 bool
1005 c_common_init (void)
1006 {
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);
1013 cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
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);
1019
1020 if (version_flag)
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 }
1028
1029 /* Has to wait until now so that cpplib has its hash table. */
1030 init_pragma ();
1031
1032 if (flag_preprocess_only)
1033 {
1034 c_finish_options ();
1035 preprocess_file (parse_in);
1036 return false;
1037 }
1038
1039 return true;
1040 }
1041
1042 /* Initialize the integrated preprocessor after debug output has been
1043 initialized; loop over each input file. */
1044 void
1045 c_common_parse_file (void)
1046 {
1047 unsigned int i;
1048
1049 i = 0;
1050 for (;;)
1051 {
1052 c_finish_options ();
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);
1057 pch_init ();
1058 push_file_scope ();
1059 c_parse_file ();
1060 pop_file_scope ();
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);
1064 if (++i >= num_in_fnames)
1065 break;
1066 cpp_undef_all (parse_in);
1067 cpp_clear_file_cache (parse_in);
1068 this_input_filename
1069 = cpp_read_main_file (parse_in, in_fnames[i]);
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 }
1080 /* If an input file is missing, abandon further compilation.
1081 cpplib has issued a diagnostic. */
1082 if (!this_input_filename)
1083 break;
1084 }
1085
1086 c_parse_final_cleanups ();
1087 }
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 }
1105
1106 /* Common finish hook for the C, ObjC and C++ front ends. */
1107 void
1108 c_common_finish (void)
1109 {
1110 FILE *deps_stream = NULL;
1111
1112 /* Don't write the deps file if there are errors. */
1113 if (cpp_opts->deps.style != DEPS_NONE && !seen_error ())
1114 {
1115 /* If -M or -MM was seen without -MF, default output to the
1116 output stream. */
1117 if (!deps_file)
1118 deps_stream = out_stream;
1119 else
1120 {
1121 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1122 if (!deps_stream)
1123 fatal_error (input_location, "opening dependency file %s: %m",
1124 deps_file);
1125 }
1126 }
1127
1128 /* For performance, avoid tearing down cpplib's internal structures
1129 with cpp_destroy (). */
1130 cpp_finish (parse_in, deps_stream);
1131
1132 if (deps_stream && deps_stream != out_stream
1133 && (ferror (deps_stream) || fclose (deps_stream)))
1134 fatal_error (input_location, "closing dependency file %s: %m", deps_file);
1135
1136 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1137 fatal_error (input_location, "when writing output to %s: %m", out_fname);
1138 }
1139
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
1145 rather than overwriting it, and like Sun's compiler
1146 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1147 static void
1148 check_deps_environment_vars (void)
1149 {
1150 char *spec;
1151
1152 spec = getenv ("DEPENDENCIES_OUTPUT");
1153 if (spec)
1154 cpp_opts->deps.style = DEPS_USER;
1155 else
1156 {
1157 spec = getenv ("SUNPRO_DEPENDENCIES");
1158 if (spec)
1159 {
1160 cpp_opts->deps.style = DEPS_SYSTEM;
1161 cpp_opts->deps.ignore_main_file = true;
1162 }
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. */
1172 defer_opt (OPT_MT, s + 1);
1173 *s = '\0';
1174 }
1175
1176 /* Command line -MF overrides environment variables and default. */
1177 if (!deps_file)
1178 deps_file = spec;
1179
1180 deps_append = 1;
1181 deps_seen = true;
1182 }
1183 }
1184
1185 /* Handle deferred command line switches. */
1186 static void
1187 handle_deferred_opts (void)
1188 {
1189 size_t i;
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);
1199
1200 for (i = 0; i < deferred_count; i++)
1201 {
1202 struct deferred_opt *opt = &deferred_opts[i];
1203
1204 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1205 deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1206 }
1207 }
1208
1209 /* These settings are appropriate for GCC, but not necessarily so for
1210 cpplib as a library. */
1211 static void
1212 sanitize_cpp_opts (void)
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. */
1221 if (flag_dump_macros == 'M')
1222 flag_no_output = 1;
1223
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
1229 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1230 -dM since at least glibc relies on -M -dM to work. */
1231 /* Also, flag_no_output implies flag_no_line_commands, always. */
1232 if (flag_no_output)
1233 {
1234 if (flag_dump_macros != 'M')
1235 flag_dump_macros = 0;
1236 flag_dump_includes = 0;
1237 flag_no_line_commands = 1;
1238 }
1239 else if (cpp_opts->deps.missing_files)
1240 error ("-MG may only be used with -M or -MM");
1241
1242 cpp_opts->unsigned_char = !flag_signed_char;
1243 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1244
1245 /* Wlong-long is disabled by default. It is enabled by:
1246 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
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 }
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);
1264
1265 if (cpp_opts->directives_only)
1266 {
1267 if (cpp_warn_unused_macros)
1268 error ("-fdirectives-only is incompatible with -Wunused_macros");
1269 if (cpp_opts->traditional)
1270 error ("-fdirectives-only is incompatible with -traditional");
1271 }
1272 }
1273
1274 /* Add include path with a prefix at the front of its name. */
1275 static void
1276 add_prefixed_path (const char *suffix, size_t chain)
1277 {
1278 char *path;
1279 const char *prefix;
1280 size_t prefix_len, suffix_len;
1281
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
1286 path = (char *) xmalloc (prefix_len + suffix_len + 1);
1287 memcpy (path, prefix, prefix_len);
1288 memcpy (path + prefix_len, suffix, suffix_len);
1289 path[prefix_len + suffix_len] = '\0';
1290
1291 add_path (path, chain, 0, false);
1292 }
1293
1294 /* Handle -D, -U, -A, -imacros, and the first -include. */
1295 static void
1296 c_finish_options (void)
1297 {
1298 if (!cpp_opts->preprocessed)
1299 {
1300 size_t i;
1301
1302 cb_file_change (parse_in,
1303 linemap_check_ordinary (linemap_add (line_table,
1304 LC_RENAME, 0,
1305 _("<built-in>"),
1306 0)));
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);
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. */
1326 cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1327
1328 cb_file_change (parse_in,
1329 linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
1330 _("<command-line>"), 0)));
1331
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 }
1348
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
1354 /* Handle -imacros after -D and -U. */
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))
1361 {
1362 /* Disable push_command_line_include callback for now. */
1363 include_cursor = deferred_count + 1;
1364 cpp_scan_nooutput (parse_in);
1365 }
1366 }
1367 }
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 }
1378
1379 include_cursor = 0;
1380 push_command_line_include ();
1381 }
1382
1383 /* Give CPP the next file given by -include, if any. */
1384 static void
1385 push_command_line_include (void)
1386 {
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
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
1406 while (include_cursor < deferred_count)
1407 {
1408 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1409
1410 if (!cpp_opts->preprocessed && opt->code == OPT_include
1411 && cpp_push_include (parse_in, opt->arg))
1412 return;
1413 }
1414
1415 if (include_cursor == deferred_count)
1416 {
1417 include_cursor++;
1418 /* -Wunused-macros should only warn about macros defined hereafter. */
1419 cpp_opts->warn_unused_macros = cpp_warn_unused_macros;
1420 /* Restore the line map from <command line>. */
1421 if (!cpp_opts->preprocessed)
1422 cpp_change_file (parse_in, LC_RENAME, this_input_filename);
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. */
1426 line_table->trace_includes = cpp_opts->print_include_names;
1427 }
1428 }
1429
1430 /* File change callback. Has to handle -include files. */
1431 static void
1432 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
1433 const line_map_ordinary *new_map)
1434 {
1435 if (flag_preprocess_only)
1436 pp_file_change (new_map);
1437 else
1438 fe_file_change (new_map);
1439
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
1451 if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1452 {
1453 pch_cpp_save_state ();
1454 push_command_line_include ();
1455 }
1456 }
1457
1458 void
1459 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1460 {
1461 if (!set_src_pwd (dir))
1462 warning (0, "too late for # directive to set debug directory");
1463 }
1464
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
1468 set_std_c89 (int c94, int iso)
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;
1475 flag_isoc94 = c94;
1476 flag_isoc99 = 0;
1477 flag_isoc11 = 0;
1478 lang_hooks.name = "GNU C89";
1479 }
1480
1481 /* Set the C 99 standard (without GNU extensions if ISO). */
1482 static void
1483 set_std_c99 (int iso)
1484 {
1485 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1486 flag_no_asm = iso;
1487 flag_no_nonansi_builtin = iso;
1488 flag_iso = iso;
1489 flag_isoc11 = 0;
1490 flag_isoc99 = 1;
1491 flag_isoc94 = 1;
1492 lang_hooks.name = "GNU C99";
1493 }
1494
1495 /* Set the C 11 standard (without GNU extensions if ISO). */
1496 static void
1497 set_std_c11 (int iso)
1498 {
1499 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
1500 flag_no_asm = iso;
1501 flag_no_nonansi_builtin = iso;
1502 flag_iso = iso;
1503 flag_isoc11 = 1;
1504 flag_isoc99 = 1;
1505 flag_isoc94 = 1;
1506 lang_hooks.name = "GNU C11";
1507 }
1508
1509 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1510 static void
1511 set_std_cxx98 (int iso)
1512 {
1513 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1514 flag_no_gnu_keywords = iso;
1515 flag_no_nonansi_builtin = iso;
1516 flag_iso = iso;
1517 cxx_dialect = cxx98;
1518 lang_hooks.name = "GNU C++98";
1519 }
1520
1521 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1522 static void
1523 set_std_cxx11 (int iso)
1524 {
1525 cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
1526 flag_no_gnu_keywords = iso;
1527 flag_no_nonansi_builtin = iso;
1528 flag_iso = iso;
1529 /* C++11 includes the C99 standard library. */
1530 flag_isoc94 = 1;
1531 flag_isoc99 = 1;
1532 cxx_dialect = cxx11;
1533 lang_hooks.name = "GNU C++11";
1534 }
1535
1536 /* Set the C++ 2014 draft standard (without GNU extensions if ISO). */
1537 static void
1538 set_std_cxx14 (int iso)
1539 {
1540 cpp_set_lang (parse_in, iso ? CLK_CXX14: CLK_GNUCXX14);
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;
1547 cxx_dialect = cxx14;
1548 lang_hooks.name = "GNU C++14";
1549 }
1550
1551 /* Set the C++ 201z draft standard (without GNU extensions if ISO). */
1552 static void
1553 set_std_cxx1z (int iso)
1554 {
1555 cpp_set_lang (parse_in, iso ? CLK_CXX1Z: CLK_GNUCXX1Z);
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;
1562 flag_isoc11 = 1;
1563 cxx_dialect = cxx1z;
1564 lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standarization. */
1565 }
1566
1567 /* Args to -d specify what to dump. Silently ignore
1568 unrecognized options; they may be aimed at toplev.c. */
1569 static void
1570 handle_OPT_d (const char *arg)
1571 {
1572 char c;
1573
1574 while ((c = *arg++) != '\0')
1575 switch (c)
1576 {
1577 case 'M': /* Dump macros only. */
1578 case 'N': /* Dump names. */
1579 case 'D': /* Dump definitions. */
1580 case 'U': /* Dump used macros. */
1581 flag_dump_macros = c;
1582 break;
1583
1584 case 'I':
1585 flag_dump_includes = 1;
1586 break;
1587 }
1588 }