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