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