ebbf7d91c67444af9242a018a2e37cc0a5912878
[gcc.git] / gcc / c-family / c-opts.c
1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3 2012 Free Software Foundation, Inc.
4 Contributed by Neil Booth.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "c-common.h"
27 #include "c-pragma.h"
28 #include "flags.h"
29 #include "toplev.h"
30 #include "langhooks.h"
31 #include "diagnostic.h"
32 #include "intl.h"
33 #include "cppdefault.h"
34 #include "incpath.h"
35 #include "debug.h" /* For debug_hooks. */
36 #include "opts.h"
37 #include "options.h"
38 #include "mkdeps.h"
39 #include "c-target.h"
40 #include "tm.h" /* For BYTES_BIG_ENDIAN,
41 DOLLARS_IN_IDENTIFIERS,
42 STDC_0_IN_SYSTEM_HEADERS,
43 TARGET_FLT_EVAL_METHOD_NON_DEFAULT and
44 TARGET_OPTF. */
45 #include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
46
47 #ifndef DOLLARS_IN_IDENTIFIERS
48 # define DOLLARS_IN_IDENTIFIERS true
49 #endif
50
51 #ifndef TARGET_SYSTEM_ROOT
52 # define TARGET_SYSTEM_ROOT NULL
53 #endif
54
55 #ifndef TARGET_OPTF
56 #define TARGET_OPTF(ARG)
57 #endif
58
59 /* CPP's options. */
60 cpp_options *cpp_opts;
61
62 /* Input filename. */
63 static const char *this_input_filename;
64
65 /* Filename and stream for preprocessed output. */
66 static const char *out_fname;
67 static FILE *out_stream;
68
69 /* Append dependencies to deps_file. */
70 static bool deps_append;
71
72 /* If dependency switches (-MF etc.) have been given. */
73 static bool deps_seen;
74
75 /* If -v seen. */
76 static bool verbose;
77
78 /* Dependency output file. */
79 static const char *deps_file;
80
81 /* The prefix given by -iprefix, if any. */
82 static const char *iprefix;
83
84 /* The multilib directory given by -imultilib, if any. */
85 static const char *imultilib;
86
87 /* The system root, if any. Overridden by -isysroot. */
88 static const char *sysroot = TARGET_SYSTEM_ROOT;
89
90 /* Zero disables all standard directories for headers. */
91 static bool std_inc = true;
92
93 /* Zero disables the C++-specific standard directories for headers. */
94 static bool std_cxx_inc = true;
95
96 /* If the quote chain has been split by -I-. */
97 static bool quote_chain_split;
98
99 /* If -Wunused-macros. */
100 static bool warn_unused_macros;
101
102 /* If -Wvariadic-macros. */
103 static bool warn_variadic_macros = true;
104
105 /* Number of deferred options. */
106 static size_t deferred_count;
107
108 /* Number of deferred options scanned for -include. */
109 static size_t include_cursor;
110
111 static void handle_OPT_d (const char *);
112 static void set_std_cxx98 (int);
113 static void set_std_cxx11 (int);
114 static void set_std_cxx1y (int);
115 static void set_std_c89 (int, int);
116 static void set_std_c99 (int);
117 static void set_std_c11 (int);
118 static void check_deps_environment_vars (void);
119 static void handle_deferred_opts (void);
120 static void sanitize_cpp_opts (void);
121 static void add_prefixed_path (const char *, size_t);
122 static void push_command_line_include (void);
123 static void cb_file_change (cpp_reader *, const struct line_map *);
124 static void cb_dir_change (cpp_reader *, const char *);
125 static void c_finish_options (void);
126
127 #ifndef STDC_0_IN_SYSTEM_HEADERS
128 #define STDC_0_IN_SYSTEM_HEADERS 0
129 #endif
130
131 /* Holds switches parsed by c_common_handle_option (), but whose
132 handling is deferred to c_common_post_options (). */
133 static void defer_opt (enum opt_code, const char *);
134 static struct deferred_opt
135 {
136 enum opt_code code;
137 const char *arg;
138 } *deferred_opts;
139
140
141 extern const unsigned int
142 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
143
144 /* Defer option CODE with argument ARG. */
145 static void
146 defer_opt (enum opt_code code, const char *arg)
147 {
148 deferred_opts[deferred_count].code = code;
149 deferred_opts[deferred_count].arg = arg;
150 deferred_count++;
151 }
152
153 /* Return language mask for option parsing. */
154 unsigned int
155 c_common_option_lang_mask (void)
156 {
157 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
158
159 return lang_flags[c_language];
160 }
161
162 /* Common diagnostics initialization. */
163 void
164 c_common_initialize_diagnostics (diagnostic_context *context)
165 {
166 /* This is conditionalized only because that is the way the front
167 ends used to do it. Maybe this should be unconditional? */
168 if (c_dialect_cxx ())
169 {
170 /* By default wrap lines at 80 characters. Is getenv
171 ("COLUMNS") preferable? */
172 diagnostic_line_cutoff (context) = 80;
173 /* By default, emit location information once for every
174 diagnostic message. */
175 diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
176 }
177
178 context->opt_permissive = OPT_fpermissive;
179 }
180
181 /* Whether options from all C-family languages should be accepted
182 quietly. */
183 static bool accept_all_c_family_options = false;
184
185 /* Return whether to complain about a wrong-language option. */
186 bool
187 c_common_complain_wrong_lang_p (const struct cl_option *option)
188 {
189 if (accept_all_c_family_options
190 && (option->flags & c_family_lang_mask))
191 return false;
192
193 return true;
194 }
195
196 /* Initialize options structure OPTS. */
197 void
198 c_common_init_options_struct (struct gcc_options *opts)
199 {
200 opts->x_flag_exceptions = c_dialect_cxx ();
201 opts->x_warn_pointer_arith = c_dialect_cxx ();
202 opts->x_warn_write_strings = c_dialect_cxx ();
203 opts->x_flag_warn_unused_result = true;
204
205 /* By default, C99-like requirements for complex multiply and divide. */
206 opts->x_flag_complex_method = 2;
207 }
208
209 /* Common initialization before calling option handlers. */
210 void
211 c_common_init_options (unsigned int decoded_options_count,
212 struct cl_decoded_option *decoded_options)
213 {
214 unsigned int i;
215 struct cpp_callbacks *cb;
216
217 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
218 ident_hash, line_table);
219 cb = cpp_get_callbacks (parse_in);
220 cb->error = c_cpp_error;
221
222 cpp_opts = cpp_get_options (parse_in);
223 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
224 cpp_opts->objc = c_dialect_objc ();
225
226 /* Reset to avoid warnings on internal definitions. We set it just
227 before passing on command-line options to cpplib. */
228 cpp_opts->warn_dollars = 0;
229
230 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
231
232 if (c_language == clk_c)
233 {
234 /* If preprocessing assembly language, accept any of the C-family
235 front end options since the driver may pass them through. */
236 for (i = 1; i < decoded_options_count; i++)
237 if (decoded_options[i].opt_index == OPT_lang_asm)
238 {
239 accept_all_c_family_options = true;
240 break;
241 }
242 }
243 }
244
245 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
246 form of an -f or -W option was given. Returns false if the switch was
247 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
248 bool
249 c_common_handle_option (size_t scode, const char *arg, int value,
250 int kind, location_t loc,
251 const struct cl_option_handlers *handlers)
252 {
253 const struct cl_option *option = &cl_options[scode];
254 enum opt_code code = (enum opt_code) scode;
255 bool result = true;
256
257 /* Prevent resetting the language standard to a C dialect when the driver
258 has already determined that we're looking at assembler input. */
259 bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
260
261 switch (code)
262 {
263 default:
264 if (cl_options[code].flags & c_family_lang_mask)
265 {
266 if ((option->flags & CL_TARGET)
267 && ! targetcm.handle_c_option (scode, arg, value))
268 result = false;
269 break;
270 }
271 result = false;
272 break;
273
274 case OPT__output_pch_:
275 pch_file = arg;
276 break;
277
278 case OPT_A:
279 defer_opt (code, arg);
280 break;
281
282 case OPT_C:
283 cpp_opts->discard_comments = 0;
284 break;
285
286 case OPT_CC:
287 cpp_opts->discard_comments = 0;
288 cpp_opts->discard_comments_in_macro_exp = 0;
289 break;
290
291 case OPT_D:
292 defer_opt (code, arg);
293 break;
294
295 case OPT_H:
296 cpp_opts->print_include_names = 1;
297 break;
298
299 case OPT_F:
300 TARGET_OPTF (xstrdup (arg));
301 break;
302
303 case OPT_I:
304 if (strcmp (arg, "-"))
305 add_path (xstrdup (arg), BRACKET, 0, true);
306 else
307 {
308 if (quote_chain_split)
309 error ("-I- specified twice");
310 quote_chain_split = true;
311 split_quote_chain ();
312 inform (input_location, "obsolete option -I- used, please use -iquote instead");
313 }
314 break;
315
316 case OPT_M:
317 case OPT_MM:
318 /* When doing dependencies with -M or -MM, suppress normal
319 preprocessed output, but still do -dM etc. as software
320 depends on this. Preprocessed output does occur if -MD, -MMD
321 or environment var dependency generation is used. */
322 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
323 flag_no_output = 1;
324 break;
325
326 case OPT_MD:
327 case OPT_MMD:
328 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
329 cpp_opts->deps.need_preprocessor_output = true;
330 deps_file = arg;
331 break;
332
333 case OPT_MF:
334 deps_seen = true;
335 deps_file = arg;
336 break;
337
338 case OPT_MG:
339 deps_seen = true;
340 cpp_opts->deps.missing_files = true;
341 break;
342
343 case OPT_MP:
344 deps_seen = true;
345 cpp_opts->deps.phony_targets = true;
346 break;
347
348 case OPT_MQ:
349 case OPT_MT:
350 deps_seen = true;
351 defer_opt (code, arg);
352 break;
353
354 case OPT_P:
355 flag_no_line_commands = 1;
356 break;
357
358 case OPT_U:
359 defer_opt (code, arg);
360 break;
361
362 case OPT_Wall:
363 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
364 handle_generated_option (&global_options, &global_options_set,
365 OPT_Wunused, NULL, value,
366 c_family_lang_mask, kind, loc,
367 handlers, global_dc);
368 set_Wformat (value);
369 handle_generated_option (&global_options, &global_options_set,
370 OPT_Wimplicit, NULL, value,
371 c_family_lang_mask, kind, loc,
372 handlers, global_dc);
373 warn_char_subscripts = value;
374 warn_parentheses = value;
375 warn_return_type = value;
376 warn_sequence_point = value; /* Was C only. */
377 warn_switch = value;
378 warn_sizeof_pointer_memaccess = value;
379 warn_address = value;
380 warn_array_bounds = value;
381 warn_volatile_register_var = value;
382
383 /* Only warn about unknown pragmas that are not in system
384 headers. */
385 warn_unknown_pragmas = value;
386
387 warn_uninitialized = value;
388 warn_maybe_uninitialized = value;
389
390 if (!c_dialect_cxx ())
391 {
392 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
393 can turn it off only if it's not explicit. */
394 if (warn_main == -1)
395 warn_main = (value ? 2 : 0);
396
397 /* In C, -Wall and -Wc++-compat turns on -Wenum-compare,
398 which we do here. In C++ it is on by default, which is
399 done in c_common_post_options. */
400 if (warn_enum_compare == -1)
401 warn_enum_compare = value;
402 }
403 else
404 {
405 /* C++-specific warnings. */
406 warn_sign_compare = value;
407 warn_narrowing = value;
408 }
409
410 cpp_opts->warn_trigraphs = value;
411 cpp_opts->warn_comments = value;
412 cpp_opts->warn_num_sign_change = value;
413
414 if (warn_pointer_sign == -1)
415 warn_pointer_sign = value;
416 break;
417
418 case OPT_Wbuiltin_macro_redefined:
419 cpp_opts->warn_builtin_macro_redefined = value;
420 break;
421
422 case OPT_Wcomment:
423 cpp_opts->warn_comments = value;
424 break;
425
426 case OPT_Wc___compat:
427 /* Because -Wenum-compare is the default in C++, -Wc++-compat
428 implies -Wenum-compare. */
429 if (warn_enum_compare == -1 && value)
430 warn_enum_compare = value;
431 cpp_opts->warn_cxx_operator_names = value;
432 break;
433
434 case OPT_Wc__0x_compat:
435 warn_narrowing = value;
436 break;
437
438 case OPT_Wdeprecated:
439 cpp_opts->cpp_warn_deprecated = value;
440 break;
441
442 case OPT_Wendif_labels:
443 cpp_opts->warn_endif_labels = value;
444 break;
445
446 case OPT_Wformat:
447 set_Wformat (value);
448 break;
449
450 case OPT_Wformat_:
451 set_Wformat (atoi (arg));
452 break;
453
454 case OPT_Wimplicit:
455 gcc_assert (value == 0 || value == 1);
456 if (warn_implicit_int == -1)
457 handle_generated_option (&global_options, &global_options_set,
458 OPT_Wimplicit_int, NULL, value,
459 c_family_lang_mask, kind, loc, handlers,
460 global_dc);
461 if (warn_implicit_function_declaration == -1)
462 handle_generated_option (&global_options, &global_options_set,
463 OPT_Wimplicit_function_declaration, NULL,
464 value, c_family_lang_mask, kind, loc,
465 handlers, global_dc);
466 break;
467
468 case OPT_Winvalid_pch:
469 cpp_opts->warn_invalid_pch = value;
470 break;
471
472 case OPT_Wliteral_suffix:
473 cpp_opts->warn_literal_suffix = value;
474 break;
475
476 case OPT_Wlong_long:
477 cpp_opts->cpp_warn_long_long = value;
478 break;
479
480 case OPT_Wmissing_include_dirs:
481 cpp_opts->warn_missing_include_dirs = value;
482 break;
483
484 case OPT_Wmultichar:
485 cpp_opts->warn_multichar = value;
486 break;
487
488 case OPT_Wnormalized_:
489 if (kind == DK_ERROR)
490 {
491 gcc_assert (!arg);
492 inform (input_location, "-Werror=normalized=: set -Wnormalized=nfc");
493 cpp_opts->warn_normalize = normalized_C;
494 }
495 else
496 {
497 if (!value || (arg && strcasecmp (arg, "none") == 0))
498 cpp_opts->warn_normalize = normalized_none;
499 else if (!arg || strcasecmp (arg, "nfkc") == 0)
500 cpp_opts->warn_normalize = normalized_KC;
501 else if (strcasecmp (arg, "id") == 0)
502 cpp_opts->warn_normalize = normalized_identifier_C;
503 else if (strcasecmp (arg, "nfc") == 0)
504 cpp_opts->warn_normalize = normalized_C;
505 else
506 error ("argument %qs to %<-Wnormalized%> not recognized", arg);
507 break;
508 }
509
510 case OPT_Wtraditional:
511 cpp_opts->cpp_warn_traditional = value;
512 break;
513
514 case OPT_Wtrigraphs:
515 cpp_opts->warn_trigraphs = value;
516 break;
517
518 case OPT_Wundef:
519 cpp_opts->warn_undef = value;
520 break;
521
522 case OPT_Wunknown_pragmas:
523 /* Set to greater than 1, so that even unknown pragmas in
524 system headers will be warned about. */
525 warn_unknown_pragmas = value * 2;
526 break;
527
528 case OPT_Wunused_macros:
529 warn_unused_macros = value;
530 break;
531
532 case OPT_Wvariadic_macros:
533 warn_variadic_macros = value;
534 break;
535
536 case OPT_Weffc__:
537 if (value)
538 warn_nonvdtor = true;
539 break;
540
541 case OPT_ansi:
542 if (!c_dialect_cxx ())
543 set_std_c89 (false, true);
544 else
545 set_std_cxx98 (true);
546 break;
547
548 case OPT_d:
549 handle_OPT_d (arg);
550 break;
551
552 case OPT_fcond_mismatch:
553 if (!c_dialect_cxx ())
554 {
555 flag_cond_mismatch = value;
556 break;
557 }
558 warning (0, "switch %qs is no longer supported", option->opt_text);
559 break;
560
561 case OPT_fbuiltin_:
562 if (value)
563 result = false;
564 else
565 disable_builtin_function (arg);
566 break;
567
568 case OPT_fdirectives_only:
569 cpp_opts->directives_only = value;
570 break;
571
572 case OPT_fdollars_in_identifiers:
573 cpp_opts->dollars_in_ident = value;
574 break;
575
576 case OPT_ffreestanding:
577 value = !value;
578 /* Fall through.... */
579 case OPT_fhosted:
580 flag_hosted = value;
581 flag_no_builtin = !value;
582 break;
583
584 case OPT_fconstant_string_class_:
585 constant_string_class_name = arg;
586 break;
587
588 case OPT_fextended_identifiers:
589 cpp_opts->extended_identifiers = value;
590 break;
591
592 case OPT_foperator_names:
593 cpp_opts->operator_names = value;
594 break;
595
596 case OPT_fpch_deps:
597 cpp_opts->restore_pch_deps = value;
598 break;
599
600 case OPT_fpch_preprocess:
601 flag_pch_preprocess = value;
602 break;
603
604 case OPT_fpermissive:
605 flag_permissive = value;
606 global_dc->permissive = value;
607 break;
608
609 case OPT_fpreprocessed:
610 cpp_opts->preprocessed = value;
611 break;
612
613 case OPT_fdebug_cpp:
614 cpp_opts->debug = 1;
615 break;
616
617 case OPT_ftrack_macro_expansion:
618 if (value)
619 value = 2;
620 /* Fall Through. */
621
622 case OPT_ftrack_macro_expansion_:
623 if (arg && *arg != '\0')
624 cpp_opts->track_macro_expansion = value;
625 else
626 cpp_opts->track_macro_expansion = 2;
627 break;
628
629 case OPT_frepo:
630 flag_use_repository = value;
631 if (value)
632 flag_implicit_templates = 0;
633 break;
634
635 case OPT_ftabstop_:
636 /* It is documented that we silently ignore silly values. */
637 if (value >= 1 && value <= 100)
638 cpp_opts->tabstop = value;
639 break;
640
641 case OPT_fexec_charset_:
642 cpp_opts->narrow_charset = arg;
643 break;
644
645 case OPT_fwide_exec_charset_:
646 cpp_opts->wide_charset = arg;
647 break;
648
649 case OPT_finput_charset_:
650 cpp_opts->input_charset = arg;
651 break;
652
653 case OPT_ftemplate_depth_:
654 max_tinst_depth = value;
655 break;
656
657 case OPT_fvisibility_inlines_hidden:
658 visibility_options.inlines_hidden = value;
659 break;
660
661 case OPT_femit_struct_debug_baseonly:
662 set_struct_debug_option (&global_options, loc, "base");
663 break;
664
665 case OPT_femit_struct_debug_reduced:
666 set_struct_debug_option (&global_options, loc,
667 "dir:ord:sys,dir:gen:any,ind:base");
668 break;
669
670 case OPT_femit_struct_debug_detailed_:
671 set_struct_debug_option (&global_options, loc, arg);
672 break;
673
674 case OPT_idirafter:
675 add_path (xstrdup (arg), AFTER, 0, true);
676 break;
677
678 case OPT_imacros:
679 case OPT_include:
680 defer_opt (code, arg);
681 break;
682
683 case OPT_imultilib:
684 imultilib = arg;
685 break;
686
687 case OPT_iprefix:
688 iprefix = arg;
689 break;
690
691 case OPT_iquote:
692 add_path (xstrdup (arg), QUOTE, 0, true);
693 break;
694
695 case OPT_isysroot:
696 sysroot = arg;
697 break;
698
699 case OPT_isystem:
700 add_path (xstrdup (arg), SYSTEM, 0, true);
701 break;
702
703 case OPT_iwithprefix:
704 add_prefixed_path (arg, SYSTEM);
705 break;
706
707 case OPT_iwithprefixbefore:
708 add_prefixed_path (arg, BRACKET);
709 break;
710
711 case OPT_lang_asm:
712 cpp_set_lang (parse_in, CLK_ASM);
713 cpp_opts->dollars_in_ident = false;
714 break;
715
716 case OPT_nostdinc:
717 std_inc = false;
718 break;
719
720 case OPT_nostdinc__:
721 std_cxx_inc = false;
722 break;
723
724 case OPT_o:
725 if (!out_fname)
726 out_fname = arg;
727 else
728 error ("output filename specified twice");
729 break;
730
731 /* We need to handle the -Wpedantic switch here, rather than in
732 c_common_post_options, so that a subsequent -Wno-endif-labels
733 is not overridden. */
734 case OPT_Wpedantic:
735 cpp_opts->cpp_pedantic = 1;
736 cpp_opts->warn_endif_labels = 1;
737 if (warn_pointer_sign == -1)
738 warn_pointer_sign = 1;
739 if (warn_overlength_strings == -1)
740 warn_overlength_strings = 1;
741 if (warn_main == -1)
742 warn_main = 2;
743 break;
744
745 case OPT_print_objc_runtime_info:
746 print_struct_values = 1;
747 break;
748
749 case OPT_remap:
750 cpp_opts->remap = 1;
751 break;
752
753 case OPT_std_c__98:
754 case OPT_std_gnu__98:
755 if (!preprocessing_asm_p)
756 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
757 break;
758
759 case OPT_std_c__11:
760 case OPT_std_gnu__11:
761 if (!preprocessing_asm_p)
762 set_std_cxx11 (code == OPT_std_c__11 /* ISO */);
763 break;
764
765 case OPT_std_c__1y:
766 case OPT_std_gnu__1y:
767 if (!preprocessing_asm_p)
768 set_std_cxx1y (code == OPT_std_c__11 /* ISO */);
769 break;
770
771 case OPT_std_c90:
772 case OPT_std_iso9899_199409:
773 if (!preprocessing_asm_p)
774 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
775 break;
776
777 case OPT_std_gnu90:
778 if (!preprocessing_asm_p)
779 set_std_c89 (false /* c94 */, false /* ISO */);
780 break;
781
782 case OPT_std_c99:
783 if (!preprocessing_asm_p)
784 set_std_c99 (true /* ISO */);
785 break;
786
787 case OPT_std_gnu99:
788 if (!preprocessing_asm_p)
789 set_std_c99 (false /* ISO */);
790 break;
791
792 case OPT_std_c11:
793 if (!preprocessing_asm_p)
794 set_std_c11 (true /* ISO */);
795 break;
796
797 case OPT_std_gnu11:
798 if (!preprocessing_asm_p)
799 set_std_c11 (false /* ISO */);
800 break;
801
802 case OPT_trigraphs:
803 cpp_opts->trigraphs = 1;
804 break;
805
806 case OPT_traditional_cpp:
807 cpp_opts->traditional = 1;
808 break;
809
810 case OPT_v:
811 verbose = true;
812 break;
813
814 case OPT_Wabi:
815 warn_psabi = value;
816 break;
817 }
818
819 switch (c_language)
820 {
821 case clk_c:
822 C_handle_option_auto (&global_options, &global_options_set,
823 scode, arg, value,
824 c_family_lang_mask, kind,
825 loc, handlers, global_dc);
826 break;
827
828 case clk_objc:
829 ObjC_handle_option_auto (&global_options, &global_options_set,
830 scode, arg, value,
831 c_family_lang_mask, kind,
832 loc, handlers, global_dc);
833 break;
834
835 case clk_cxx:
836 CXX_handle_option_auto (&global_options, &global_options_set,
837 scode, arg, value,
838 c_family_lang_mask, kind,
839 loc, handlers, global_dc);
840 break;
841
842 case clk_objcxx:
843 ObjCXX_handle_option_auto (&global_options, &global_options_set,
844 scode, arg, value,
845 c_family_lang_mask, kind,
846 loc, handlers, global_dc);
847 break;
848
849 default:
850 gcc_unreachable ();
851 }
852
853 return result;
854 }
855
856 /* Default implementation of TARGET_HANDLE_C_OPTION. */
857
858 bool
859 default_handle_c_option (size_t code ATTRIBUTE_UNUSED,
860 const char *arg ATTRIBUTE_UNUSED,
861 int value ATTRIBUTE_UNUSED)
862 {
863 return false;
864 }
865
866 /* Post-switch processing. */
867 bool
868 c_common_post_options (const char **pfilename)
869 {
870 struct cpp_callbacks *cb;
871
872 /* Canonicalize the input and output filenames. */
873 if (in_fnames == NULL)
874 {
875 in_fnames = XNEWVEC (const char *, 1);
876 in_fnames[0] = "";
877 }
878 else if (strcmp (in_fnames[0], "-") == 0)
879 in_fnames[0] = "";
880
881 if (out_fname == NULL || !strcmp (out_fname, "-"))
882 out_fname = "";
883
884 if (cpp_opts->deps.style == DEPS_NONE)
885 check_deps_environment_vars ();
886
887 handle_deferred_opts ();
888
889 sanitize_cpp_opts ();
890
891 register_include_chains (parse_in, sysroot, iprefix, imultilib,
892 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
893
894 #ifdef C_COMMON_OVERRIDE_OPTIONS
895 /* Some machines may reject certain combinations of C
896 language-specific options. */
897 C_COMMON_OVERRIDE_OPTIONS;
898 #endif
899
900 /* Excess precision other than "fast" requires front-end
901 support. */
902 if (c_dialect_cxx ())
903 {
904 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
905 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
906 sorry ("-fexcess-precision=standard for C++");
907 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
908 }
909 else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
910 flag_excess_precision_cmdline = (flag_iso
911 ? EXCESS_PRECISION_STANDARD
912 : EXCESS_PRECISION_FAST);
913
914 /* By default we use C99 inline semantics in GNU99 or C99 mode. C99
915 inline semantics are not supported in GNU89 or C89 mode. */
916 if (flag_gnu89_inline == -1)
917 flag_gnu89_inline = !flag_isoc99;
918 else if (!flag_gnu89_inline && !flag_isoc99)
919 error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
920
921 /* Default to ObjC sjlj exception handling if NeXT runtime. */
922 if (flag_objc_sjlj_exceptions < 0)
923 flag_objc_sjlj_exceptions = flag_next_runtime;
924 if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
925 flag_exceptions = 1;
926
927 /* -Wextra implies the following flags
928 unless explicitly overridden. */
929
930 /* Wsign-compare is also enabled by -Wall in C++. */
931 if (warn_sign_compare == -1)
932 warn_sign_compare = extra_warnings;
933
934 /* -Wpointer-sign is disabled by default, but it is enabled if any
935 of -Wall or -Wpedantic are given. */
936 if (warn_pointer_sign == -1)
937 warn_pointer_sign = 0;
938
939 /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
940 It is never enabled in C++, as the minimum limit is not normative
941 in that standard. */
942 if (warn_overlength_strings == -1 || c_dialect_cxx ())
943 warn_overlength_strings = 0;
944
945 /* Wmain is enabled by default in C++ but not in C. */
946 /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
947 even if -Wall was given (warn_main will be 2 if set by -Wall, 1
948 if set by -Wmain). */
949 if (warn_main == -1)
950 warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
951 else if (warn_main == 2)
952 warn_main = flag_hosted ? 1 : 0;
953
954 /* In C, -Wconversion enables -Wsign-conversion (unless disabled
955 through -Wno-sign-conversion). While in C++,
956 -Wsign-conversion needs to be requested explicitly. */
957 if (warn_sign_conversion == -1)
958 warn_sign_conversion = (c_dialect_cxx ()) ? 0 : warn_conversion;
959
960 /* In C, -Wall and -Wc++-compat enable -Wenum-compare, which we do
961 in c_common_handle_option; if it has not yet been set, it is
962 disabled by default. In C++, it is enabled by default. */
963 if (warn_enum_compare == -1)
964 warn_enum_compare = c_dialect_cxx () ? 1 : 0;
965
966 /* -Wpacked-bitfield-compat is on by default for the C languages. The
967 warning is issued in stor-layout.c which is not part of the front-end so
968 we need to selectively turn it on here. */
969 if (warn_packed_bitfield_compat == -1)
970 warn_packed_bitfield_compat = 1;
971
972 /* Special format checking options don't work without -Wformat; warn if
973 they are used. */
974 if (!warn_format)
975 {
976 warning (OPT_Wformat_y2k,
977 "-Wformat-y2k ignored without -Wformat");
978 warning (OPT_Wformat_extra_args,
979 "-Wformat-extra-args ignored without -Wformat");
980 warning (OPT_Wformat_zero_length,
981 "-Wformat-zero-length ignored without -Wformat");
982 warning (OPT_Wformat_nonliteral,
983 "-Wformat-nonliteral ignored without -Wformat");
984 warning (OPT_Wformat_contains_nul,
985 "-Wformat-contains-nul ignored without -Wformat");
986 warning (OPT_Wformat_security,
987 "-Wformat-security ignored without -Wformat");
988 }
989
990 if (warn_implicit == -1)
991 warn_implicit = 0;
992
993 if (warn_implicit_int == -1)
994 warn_implicit_int = 0;
995
996 /* -Wimplicit-function-declaration is enabled by default for C99. */
997 if (warn_implicit_function_declaration == -1)
998 warn_implicit_function_declaration = flag_isoc99;
999
1000 if (cxx_dialect >= cxx0x)
1001 {
1002 /* If we're allowing C++0x constructs, don't warn about C++98
1003 identifiers which are keywords in C++0x. */
1004 warn_cxx0x_compat = 0;
1005
1006 if (warn_narrowing == -1)
1007 warn_narrowing = 1;
1008 }
1009 else if (warn_narrowing == -1)
1010 warn_narrowing = 0;
1011
1012 if (flag_preprocess_only)
1013 {
1014 /* Open the output now. We must do so even if flag_no_output is
1015 on, because there may be other output than from the actual
1016 preprocessing (e.g. from -dM). */
1017 if (out_fname[0] == '\0')
1018 out_stream = stdout;
1019 else
1020 out_stream = fopen (out_fname, "w");
1021
1022 if (out_stream == NULL)
1023 {
1024 fatal_error ("opening output file %s: %m", out_fname);
1025 return false;
1026 }
1027
1028 if (num_in_fnames > 1)
1029 error ("too many filenames given. Type %s --help for usage",
1030 progname);
1031
1032 init_pp_output (out_stream);
1033 }
1034 else
1035 {
1036 init_c_lex ();
1037
1038 /* When writing a PCH file, avoid reading some other PCH file,
1039 because the default address space slot then can't be used
1040 for the output PCH file. */
1041 if (pch_file)
1042 c_common_no_more_pch ();
1043
1044 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1045 input_location = UNKNOWN_LOCATION;
1046 }
1047
1048 cb = cpp_get_callbacks (parse_in);
1049 cb->file_change = cb_file_change;
1050 cb->dir_change = cb_dir_change;
1051 cpp_post_options (parse_in);
1052
1053 input_location = UNKNOWN_LOCATION;
1054
1055 *pfilename = this_input_filename
1056 = cpp_read_main_file (parse_in, in_fnames[0]);
1057 /* Don't do any compilation or preprocessing if there is no input file. */
1058 if (this_input_filename == NULL)
1059 {
1060 errorcount++;
1061 return false;
1062 }
1063
1064 if (flag_working_directory
1065 && flag_preprocess_only && !flag_no_line_commands)
1066 pp_dir_change (parse_in, get_src_pwd ());
1067
1068 /* Disable LTO output when outputting a precompiled header. */
1069 if (pch_file && flag_lto)
1070 {
1071 flag_lto = 0;
1072 flag_generate_lto = 0;
1073 }
1074
1075 return flag_preprocess_only;
1076 }
1077
1078 /* Front end initialization common to C, ObjC and C++. */
1079 bool
1080 c_common_init (void)
1081 {
1082 /* Set up preprocessor arithmetic. Must be done after call to
1083 c_common_nodes_and_builtins for type nodes to be good. */
1084 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1085 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1086 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1087 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1088 cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1089 cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1090
1091 /* This can't happen until after wchar_precision and bytes_big_endian
1092 are known. */
1093 cpp_init_iconv (parse_in);
1094
1095 if (version_flag)
1096 {
1097 int i;
1098 fputs ("Compiler executable checksum: ", stderr);
1099 for (i = 0; i < 16; i++)
1100 fprintf (stderr, "%02x", executable_checksum[i]);
1101 putc ('\n', stderr);
1102 }
1103
1104 /* Has to wait until now so that cpplib has its hash table. */
1105 init_pragma ();
1106
1107 if (flag_preprocess_only)
1108 {
1109 c_finish_options ();
1110 preprocess_file (parse_in);
1111 return false;
1112 }
1113
1114 return true;
1115 }
1116
1117 /* Initialize the integrated preprocessor after debug output has been
1118 initialized; loop over each input file. */
1119 void
1120 c_common_parse_file (void)
1121 {
1122 unsigned int i;
1123
1124 i = 0;
1125 for (;;)
1126 {
1127 c_finish_options ();
1128 pch_init ();
1129 push_file_scope ();
1130 c_parse_file ();
1131 pop_file_scope ();
1132 /* And end the main input file, if the debug writer wants it */
1133 if (debug_hooks->start_end_main_source_file)
1134 (*debug_hooks->end_source_file) (0);
1135 if (++i >= num_in_fnames)
1136 break;
1137 cpp_undef_all (parse_in);
1138 cpp_clear_file_cache (parse_in);
1139 this_input_filename
1140 = cpp_read_main_file (parse_in, in_fnames[i]);
1141 /* If an input file is missing, abandon further compilation.
1142 cpplib has issued a diagnostic. */
1143 if (!this_input_filename)
1144 break;
1145 }
1146 }
1147
1148 /* Common finish hook for the C, ObjC and C++ front ends. */
1149 void
1150 c_common_finish (void)
1151 {
1152 FILE *deps_stream = NULL;
1153
1154 /* Don't write the deps file if there are errors. */
1155 if (cpp_opts->deps.style != DEPS_NONE && !seen_error ())
1156 {
1157 /* If -M or -MM was seen without -MF, default output to the
1158 output stream. */
1159 if (!deps_file)
1160 deps_stream = out_stream;
1161 else
1162 {
1163 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1164 if (!deps_stream)
1165 fatal_error ("opening dependency file %s: %m", deps_file);
1166 }
1167 }
1168
1169 /* For performance, avoid tearing down cpplib's internal structures
1170 with cpp_destroy (). */
1171 cpp_finish (parse_in, deps_stream);
1172
1173 if (deps_stream && deps_stream != out_stream
1174 && (ferror (deps_stream) || fclose (deps_stream)))
1175 fatal_error ("closing dependency file %s: %m", deps_file);
1176
1177 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1178 fatal_error ("when writing output to %s: %m", out_fname);
1179 }
1180
1181 /* Either of two environment variables can specify output of
1182 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1183 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1184 and DEPS_TARGET is the target to mention in the deps. They also
1185 result in dependency information being appended to the output file
1186 rather than overwriting it, and like Sun's compiler
1187 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1188 static void
1189 check_deps_environment_vars (void)
1190 {
1191 char *spec;
1192
1193 spec = getenv ("DEPENDENCIES_OUTPUT");
1194 if (spec)
1195 cpp_opts->deps.style = DEPS_USER;
1196 else
1197 {
1198 spec = getenv ("SUNPRO_DEPENDENCIES");
1199 if (spec)
1200 {
1201 cpp_opts->deps.style = DEPS_SYSTEM;
1202 cpp_opts->deps.ignore_main_file = true;
1203 }
1204 }
1205
1206 if (spec)
1207 {
1208 /* Find the space before the DEPS_TARGET, if there is one. */
1209 char *s = strchr (spec, ' ');
1210 if (s)
1211 {
1212 /* Let the caller perform MAKE quoting. */
1213 defer_opt (OPT_MT, s + 1);
1214 *s = '\0';
1215 }
1216
1217 /* Command line -MF overrides environment variables and default. */
1218 if (!deps_file)
1219 deps_file = spec;
1220
1221 deps_append = 1;
1222 deps_seen = true;
1223 }
1224 }
1225
1226 /* Handle deferred command line switches. */
1227 static void
1228 handle_deferred_opts (void)
1229 {
1230 size_t i;
1231 struct deps *deps;
1232
1233 /* Avoid allocating the deps buffer if we don't need it.
1234 (This flag may be true without there having been -MT or -MQ
1235 options, but we'll still need the deps buffer.) */
1236 if (!deps_seen)
1237 return;
1238
1239 deps = cpp_get_deps (parse_in);
1240
1241 for (i = 0; i < deferred_count; i++)
1242 {
1243 struct deferred_opt *opt = &deferred_opts[i];
1244
1245 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1246 deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1247 }
1248 }
1249
1250 /* These settings are appropriate for GCC, but not necessarily so for
1251 cpplib as a library. */
1252 static void
1253 sanitize_cpp_opts (void)
1254 {
1255 /* If we don't know what style of dependencies to output, complain
1256 if any other dependency switches have been given. */
1257 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1258 error ("to generate dependencies you must specify either -M or -MM");
1259
1260 /* -dM and dependencies suppress normal output; do it here so that
1261 the last -d[MDN] switch overrides earlier ones. */
1262 if (flag_dump_macros == 'M')
1263 flag_no_output = 1;
1264
1265 /* By default, -fdirectives-only implies -dD. This allows subsequent phases
1266 to perform proper macro expansion. */
1267 if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1268 flag_dump_macros = 'D';
1269
1270 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1271 -dM since at least glibc relies on -M -dM to work. */
1272 /* Also, flag_no_output implies flag_no_line_commands, always. */
1273 if (flag_no_output)
1274 {
1275 if (flag_dump_macros != 'M')
1276 flag_dump_macros = 0;
1277 flag_dump_includes = 0;
1278 flag_no_line_commands = 1;
1279 }
1280 else if (cpp_opts->deps.missing_files)
1281 error ("-MG may only be used with -M or -MM");
1282
1283 cpp_opts->unsigned_char = !flag_signed_char;
1284 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1285
1286 /* Wlong-long is disabled by default. It is enabled by:
1287 [-Wpedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1288 [-Wpedantic | -Wtraditional] -std=non-c99 .
1289
1290 Either -Wlong-long or -Wno-long-long override any other settings. */
1291 if (warn_long_long == -1)
1292 warn_long_long = ((pedantic || warn_traditional)
1293 && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1294 cpp_opts->cpp_warn_long_long = warn_long_long;
1295
1296 /* Similarly with -Wno-variadic-macros. No check for c99 here, since
1297 this also turns off warnings about GCCs extension. */
1298 cpp_opts->warn_variadic_macros
1299 = warn_variadic_macros && (pedantic || warn_traditional);
1300
1301 /* If we're generating preprocessor output, emit current directory
1302 if explicitly requested or if debugging information is enabled.
1303 ??? Maybe we should only do it for debugging formats that
1304 actually output the current directory? */
1305 if (flag_working_directory == -1)
1306 flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1307
1308 if (cpp_opts->directives_only)
1309 {
1310 if (warn_unused_macros)
1311 error ("-fdirectives-only is incompatible with -Wunused_macros");
1312 if (cpp_opts->traditional)
1313 error ("-fdirectives-only is incompatible with -traditional");
1314 }
1315 }
1316
1317 /* Add include path with a prefix at the front of its name. */
1318 static void
1319 add_prefixed_path (const char *suffix, size_t chain)
1320 {
1321 char *path;
1322 const char *prefix;
1323 size_t prefix_len, suffix_len;
1324
1325 suffix_len = strlen (suffix);
1326 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1327 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1328
1329 path = (char *) xmalloc (prefix_len + suffix_len + 1);
1330 memcpy (path, prefix, prefix_len);
1331 memcpy (path + prefix_len, suffix, suffix_len);
1332 path[prefix_len + suffix_len] = '\0';
1333
1334 add_path (path, chain, 0, false);
1335 }
1336
1337 /* Handle -D, -U, -A, -imacros, and the first -include. */
1338 static void
1339 c_finish_options (void)
1340 {
1341 if (!cpp_opts->preprocessed)
1342 {
1343 size_t i;
1344
1345 {
1346 /* Make sure all of the builtins about to be declared have
1347 BUILTINS_LOCATION has their source_location. */
1348 source_location builtins_loc = BUILTINS_LOCATION;
1349 cpp_force_token_locations (parse_in, &builtins_loc);
1350
1351 cpp_init_builtins (parse_in, flag_hosted);
1352 c_cpp_builtins (parse_in);
1353
1354 cpp_stop_forcing_token_locations (parse_in);
1355 }
1356
1357 /* We're about to send user input to cpplib, so make it warn for
1358 things that we previously (when we sent it internal definitions)
1359 told it to not warn.
1360
1361 C99 permits implementation-defined characters in identifiers.
1362 The documented meaning of -std= is to turn off extensions that
1363 conflict with the specified standard, and since a strictly
1364 conforming program cannot contain a '$', we do not condition
1365 their acceptance on the -std= setting. */
1366 cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1367
1368 cb_file_change (parse_in,
1369 linemap_add (line_table, LC_RENAME, 0,
1370 _("<command-line>"), 0));
1371
1372 for (i = 0; i < deferred_count; i++)
1373 {
1374 struct deferred_opt *opt = &deferred_opts[i];
1375
1376 if (opt->code == OPT_D)
1377 cpp_define (parse_in, opt->arg);
1378 else if (opt->code == OPT_U)
1379 cpp_undef (parse_in, opt->arg);
1380 else if (opt->code == OPT_A)
1381 {
1382 if (opt->arg[0] == '-')
1383 cpp_unassert (parse_in, opt->arg + 1);
1384 else
1385 cpp_assert (parse_in, opt->arg);
1386 }
1387 }
1388
1389 /* Start the main input file, if the debug writer wants it. */
1390 if (debug_hooks->start_end_main_source_file
1391 && !flag_preprocess_only)
1392 (*debug_hooks->start_source_file) (0, this_input_filename);
1393
1394 /* Handle -imacros after -D and -U. */
1395 for (i = 0; i < deferred_count; i++)
1396 {
1397 struct deferred_opt *opt = &deferred_opts[i];
1398
1399 if (opt->code == OPT_imacros
1400 && cpp_push_include (parse_in, opt->arg))
1401 {
1402 /* Disable push_command_line_include callback for now. */
1403 include_cursor = deferred_count + 1;
1404 cpp_scan_nooutput (parse_in);
1405 }
1406 }
1407 }
1408 else
1409 {
1410 if (cpp_opts->directives_only)
1411 cpp_init_special_builtins (parse_in);
1412
1413 /* Start the main input file, if the debug writer wants it. */
1414 if (debug_hooks->start_end_main_source_file
1415 && !flag_preprocess_only)
1416 (*debug_hooks->start_source_file) (0, this_input_filename);
1417 }
1418
1419 include_cursor = 0;
1420 push_command_line_include ();
1421 }
1422
1423 /* Give CPP the next file given by -include, if any. */
1424 static void
1425 push_command_line_include (void)
1426 {
1427 while (include_cursor < deferred_count)
1428 {
1429 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1430
1431 if (!cpp_opts->preprocessed && opt->code == OPT_include
1432 && cpp_push_include (parse_in, opt->arg))
1433 return;
1434 }
1435
1436 if (include_cursor == deferred_count)
1437 {
1438 include_cursor++;
1439 /* -Wunused-macros should only warn about macros defined hereafter. */
1440 cpp_opts->warn_unused_macros = warn_unused_macros;
1441 /* Restore the line map from <command line>. */
1442 if (!cpp_opts->preprocessed)
1443 cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1444
1445 /* Set this here so the client can change the option if it wishes,
1446 and after stacking the main file so we don't trace the main file. */
1447 line_table->trace_includes = cpp_opts->print_include_names;
1448 }
1449 }
1450
1451 /* File change callback. Has to handle -include files. */
1452 static void
1453 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
1454 const struct line_map *new_map)
1455 {
1456 if (flag_preprocess_only)
1457 pp_file_change (new_map);
1458 else
1459 fe_file_change (new_map);
1460
1461 if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1462 push_command_line_include ();
1463 }
1464
1465 void
1466 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1467 {
1468 if (!set_src_pwd (dir))
1469 warning (0, "too late for # directive to set debug directory");
1470 }
1471
1472 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1473 extensions if ISO). There is no concept of gnu94. */
1474 static void
1475 set_std_c89 (int c94, int iso)
1476 {
1477 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1478 flag_iso = iso;
1479 flag_no_asm = iso;
1480 flag_no_gnu_keywords = iso;
1481 flag_no_nonansi_builtin = iso;
1482 flag_isoc94 = c94;
1483 flag_isoc99 = 0;
1484 flag_isoc11 = 0;
1485 }
1486
1487 /* Set the C 99 standard (without GNU extensions if ISO). */
1488 static void
1489 set_std_c99 (int iso)
1490 {
1491 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1492 flag_no_asm = iso;
1493 flag_no_nonansi_builtin = iso;
1494 flag_iso = iso;
1495 flag_isoc11 = 0;
1496 flag_isoc99 = 1;
1497 flag_isoc94 = 1;
1498 }
1499
1500 /* Set the C 11 standard (without GNU extensions if ISO). */
1501 static void
1502 set_std_c11 (int iso)
1503 {
1504 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
1505 flag_no_asm = iso;
1506 flag_no_nonansi_builtin = iso;
1507 flag_iso = iso;
1508 flag_isoc11 = 1;
1509 flag_isoc99 = 1;
1510 flag_isoc94 = 1;
1511 }
1512
1513 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1514 static void
1515 set_std_cxx98 (int iso)
1516 {
1517 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1518 flag_no_gnu_keywords = iso;
1519 flag_no_nonansi_builtin = iso;
1520 flag_iso = iso;
1521 cxx_dialect = cxx98;
1522 }
1523
1524 /* Set the C++ 2011 standard (without GNU extensions if ISO). */
1525 static void
1526 set_std_cxx11 (int iso)
1527 {
1528 cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
1529 flag_no_gnu_keywords = iso;
1530 flag_no_nonansi_builtin = iso;
1531 flag_iso = iso;
1532 /* C++11 includes the C99 standard library. */
1533 flag_isoc94 = 1;
1534 flag_isoc99 = 1;
1535 cxx_dialect = cxx11;
1536 }
1537
1538 /* Set the C++ 201y draft standard (without GNU extensions if ISO). */
1539 static void
1540 set_std_cxx1y (int iso)
1541 {
1542 cpp_set_lang (parse_in, iso ? CLK_CXX11: CLK_GNUCXX11);
1543 flag_no_gnu_keywords = iso;
1544 flag_no_nonansi_builtin = iso;
1545 flag_iso = iso;
1546 /* C++11 includes the C99 standard library. */
1547 flag_isoc94 = 1;
1548 flag_isoc99 = 1;
1549 cxx_dialect = cxx1y;
1550 }
1551
1552 /* Args to -d specify what to dump. Silently ignore
1553 unrecognized options; they may be aimed at toplev.c. */
1554 static void
1555 handle_OPT_d (const char *arg)
1556 {
1557 char c;
1558
1559 while ((c = *arg++) != '\0')
1560 switch (c)
1561 {
1562 case 'M': /* Dump macros only. */
1563 case 'N': /* Dump names. */
1564 case 'D': /* Dump definitions. */
1565 case 'U': /* Dump used macros. */
1566 flag_dump_macros = c;
1567 break;
1568
1569 case 'I':
1570 flag_dump_includes = 1;
1571 break;
1572 }
1573 }