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