c-opts.c revision 260568
1117395Skan/* C/ObjC/C++ command line option handling. 2169699Skan Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 3169699Skan Free Software Foundation, Inc. 4117395Skan Contributed by Neil Booth. 5117395Skan 6117395SkanThis file is part of GCC. 7117395Skan 8117395SkanGCC is free software; you can redistribute it and/or modify it under 9117395Skanthe terms of the GNU General Public License as published by the Free 10117395SkanSoftware Foundation; either version 2, or (at your option) any later 11117395Skanversion. 12117395Skan 13117395SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 14117395SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 15117395SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16117395Skanfor more details. 17117395Skan 18117395SkanYou should have received a copy of the GNU General Public License 19117395Skanalong with GCC; see the file COPYING. If not, write to the Free 20169699SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 21169699Skan02110-1301, USA. */ 22117395Skan 23132811Skan/* $FreeBSD: stable/10/contrib/gcc/c-opts.c 260568 2014-01-12 20:09:17Z pfg $ */ 24189824Sdas/* Merged C99 inline changes from gcc trunk 122565 2007-03-05 */ 25132811Skan 26117395Skan#include "config.h" 27117395Skan#include "system.h" 28132718Skan#include "coretypes.h" 29132718Skan#include "tm.h" 30117395Skan#include "tree.h" 31117395Skan#include "c-common.h" 32117395Skan#include "c-pragma.h" 33117395Skan#include "flags.h" 34117395Skan#include "toplev.h" 35117395Skan#include "langhooks.h" 36117395Skan#include "tree-inline.h" 37117395Skan#include "diagnostic.h" 38117395Skan#include "intl.h" 39132718Skan#include "cppdefault.h" 40132718Skan#include "c-incpath.h" 41132718Skan#include "debug.h" /* For debug_hooks. */ 42132718Skan#include "opts.h" 43132718Skan#include "options.h" 44169699Skan#include "mkdeps.h" 45117395Skan 46132718Skan#ifndef DOLLARS_IN_IDENTIFIERS 47132718Skan# define DOLLARS_IN_IDENTIFIERS true 48132718Skan#endif 49132718Skan 50132718Skan#ifndef TARGET_SYSTEM_ROOT 51132718Skan# define TARGET_SYSTEM_ROOT NULL 52132718Skan#endif 53132718Skan 54169699Skan#ifndef TARGET_OPTF 55169699Skan#define TARGET_OPTF(ARG) 56169699Skan#endif 57132718Skan 58117395Skan/* CPP's options. */ 59117395Skanstatic cpp_options *cpp_opts; 60117395Skan 61117395Skan/* Input filename. */ 62132718Skanstatic const char *this_input_filename; 63117395Skan 64117395Skan/* Filename and stream for preprocessed output. */ 65117395Skanstatic const char *out_fname; 66117395Skanstatic FILE *out_stream; 67117395Skan 68117395Skan/* Append dependencies to deps_file. */ 69117395Skanstatic bool deps_append; 70117395Skan 71117395Skan/* If dependency switches (-MF etc.) have been given. */ 72117395Skanstatic bool deps_seen; 73117395Skan 74132718Skan/* If -v seen. */ 75132718Skanstatic bool verbose; 76132718Skan 77169699Skan/* If -lang-fortran seen. */ 78169699Skanstatic bool lang_fortran = false; 79169699Skan 80117395Skan/* Dependency output file. */ 81117395Skanstatic const char *deps_file; 82117395Skan 83132718Skan/* The prefix given by -iprefix, if any. */ 84132718Skanstatic const char *iprefix; 85117395Skan 86169699Skan/* The multilib directory given by -imultilib, if any. */ 87169699Skanstatic const char *imultilib; 88169699Skan 89132718Skan/* The system root, if any. Overridden by -isysroot. */ 90132718Skanstatic const char *sysroot = TARGET_SYSTEM_ROOT; 91117395Skan 92132718Skan/* Zero disables all standard directories for headers. */ 93132718Skanstatic bool std_inc = true; 94117395Skan 95132718Skan/* Zero disables the C++-specific standard directories for headers. */ 96132718Skanstatic bool std_cxx_inc = true; 97117395Skan 98132718Skan/* If the quote chain has been split by -I-. */ 99132718Skanstatic bool quote_chain_split; 100117395Skan 101132718Skan/* If -Wunused-macros. */ 102132718Skanstatic bool warn_unused_macros; 103117395Skan 104169699Skan/* If -Wvariadic-macros. */ 105169699Skanstatic bool warn_variadic_macros = true; 106169699Skan 107132718Skan/* Number of deferred options. */ 108132718Skanstatic size_t deferred_count; 109117395Skan 110132718Skan/* Number of deferred options scanned for -include. */ 111132718Skanstatic size_t include_cursor; 112117395Skan 113132718Skanstatic void set_Wimplicit (int); 114132718Skanstatic void handle_OPT_d (const char *); 115132718Skanstatic void set_std_cxx98 (int); 116132718Skanstatic void set_std_c89 (int, int); 117132718Skanstatic void set_std_c99 (int); 118132718Skanstatic void check_deps_environment_vars (void); 119132718Skanstatic void handle_deferred_opts (void); 120132718Skanstatic void sanitize_cpp_opts (void); 121132718Skanstatic void add_prefixed_path (const char *, size_t); 122132718Skanstatic void push_command_line_include (void); 123132718Skanstatic void cb_file_change (cpp_reader *, const struct line_map *); 124132718Skanstatic void cb_dir_change (cpp_reader *, const char *); 125132718Skanstatic void finish_options (void); 126117395Skan 127132718Skan#ifndef STDC_0_IN_SYSTEM_HEADERS 128132718Skan#define STDC_0_IN_SYSTEM_HEADERS 0 129117395Skan#endif 130117395Skan 131132718Skan/* Holds switches parsed by c_common_handle_option (), but whose 132132718Skan handling is deferred to c_common_post_options (). */ 133132718Skanstatic void defer_opt (enum opt_code, const char *); 134117395Skanstatic struct deferred_opt 135117395Skan{ 136117395Skan enum opt_code code; 137117395Skan const char *arg; 138117395Skan} *deferred_opts; 139117395Skan 140132718Skan/* Complain that switch CODE expects an argument but none was 141132718Skan provided. OPT was the command-line option. Return FALSE to get 142132718Skan the default message in opts.c, TRUE if we provide a specialized 143132718Skan one. */ 144132718Skanbool 145132718Skanc_common_missing_argument (const char *opt, size_t code) 146117395Skan{ 147132718Skan switch (code) 148117395Skan { 149117395Skan default: 150132718Skan /* Pick up the default message. */ 151132718Skan return false; 152132718Skan 153132718Skan case OPT_fconstant_string_class_: 154169699Skan error ("no class name specified with %qs", opt); 155117395Skan break; 156117395Skan 157132718Skan case OPT_A: 158169699Skan error ("assertion missing after %qs", opt); 159117395Skan break; 160117395Skan 161132718Skan case OPT_D: 162132718Skan case OPT_U: 163169699Skan error ("macro name missing after %qs", opt); 164132718Skan break; 165132718Skan 166169699Skan case OPT_F: 167132718Skan case OPT_I: 168132718Skan case OPT_idirafter: 169132718Skan case OPT_isysroot: 170132718Skan case OPT_isystem: 171169699Skan case OPT_iquote: 172169699Skan error ("missing path after %qs", opt); 173132718Skan break; 174132718Skan 175117395Skan case OPT_MF: 176117395Skan case OPT_MD: 177117395Skan case OPT_MMD: 178132718Skan case OPT_include: 179132718Skan case OPT_imacros: 180117395Skan case OPT_o: 181169699Skan error ("missing filename after %qs", opt); 182117395Skan break; 183117395Skan 184117395Skan case OPT_MQ: 185117395Skan case OPT_MT: 186169699Skan error ("missing makefile target after %qs", opt); 187117395Skan break; 188117395Skan } 189117395Skan 190132718Skan return true; 191117395Skan} 192117395Skan 193117395Skan/* Defer option CODE with argument ARG. */ 194117395Skanstatic void 195132718Skandefer_opt (enum opt_code code, const char *arg) 196117395Skan{ 197117395Skan deferred_opts[deferred_count].code = code; 198117395Skan deferred_opts[deferred_count].arg = arg; 199117395Skan deferred_count++; 200117395Skan} 201117395Skan 202117395Skan/* Common initialization before parsing options. */ 203132718Skanunsigned int 204146908Skanc_common_init_options (unsigned int argc, const char **argv) 205117395Skan{ 206132718Skan static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; 207146908Skan unsigned int i, result; 208117395Skan 209132718Skan /* This is conditionalized only because that is the way the front 210132718Skan ends used to do it. Maybe this should be unconditional? */ 211132718Skan if (c_dialect_cxx ()) 212132718Skan { 213132718Skan /* By default wrap lines at 80 characters. Is getenv 214132718Skan ("COLUMNS") preferable? */ 215132718Skan diagnostic_line_cutoff (global_dc) = 80; 216132718Skan /* By default, emit location information once for every 217132718Skan diagnostic message. */ 218132718Skan diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE; 219132718Skan } 220117395Skan 221132718Skan parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, 222169699Skan ident_hash, &line_table); 223132718Skan 224117395Skan cpp_opts = cpp_get_options (parse_in); 225132718Skan cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; 226132718Skan cpp_opts->objc = c_dialect_objc (); 227117395Skan 228132718Skan /* Reset to avoid warnings on internal definitions. We set it just 229132718Skan before passing on command-line options to cpplib. */ 230132718Skan cpp_opts->warn_dollars = 0; 231117395Skan 232132718Skan flag_exceptions = c_dialect_cxx (); 233132718Skan warn_pointer_arith = c_dialect_cxx (); 234169699Skan warn_write_strings = c_dialect_cxx(); 235117395Skan 236169699Skan deferred_opts = XNEWVEC (struct deferred_opt, argc); 237117395Skan 238132718Skan result = lang_flags[c_language]; 239117395Skan 240146908Skan if (c_language == clk_c) 241146908Skan { 242169699Skan /* If preprocessing assembly language, accept any of the C-family 243169699Skan front end options since the driver may pass them through. */ 244146908Skan for (i = 1; i < argc; i++) 245169699Skan if (! strcmp (argv[i], "-lang-asm")) 246169699Skan { 247169699Skan result |= CL_C | CL_ObjC | CL_CXX | CL_ObjCXX; 248169699Skan break; 249169699Skan } 250169699Skan 251169699Skan#ifdef CL_Fortran 252169699Skan for (i = 1; i < argc; i++) 253169699Skan if (! strcmp (argv[i], "-lang-fortran")) 254146908Skan { 255169699Skan result |= CL_Fortran; 256169699Skan break; 257169699Skan } 258146908Skan#endif 259117395Skan } 260169699Skan 261132718Skan return result; 262132718Skan} 263117395Skan 264132718Skan/* Handle switch SCODE with argument ARG. VALUE is true, unless no- 265132718Skan form of an -f or -W option was given. Returns 0 if the switch was 266132718Skan invalid, a negative number to prevent language-independent 267132718Skan processing in toplev.c (a hack necessary for the short-term). */ 268132718Skanint 269132718Skanc_common_handle_option (size_t scode, const char *arg, int value) 270132718Skan{ 271132718Skan const struct cl_option *option = &cl_options[scode]; 272132718Skan enum opt_code code = (enum opt_code) scode; 273132718Skan int result = 1; 274117395Skan 275169699Skan /* Prevent resetting the language standard to a C dialect when the driver 276169699Skan has already determined that we're looking at assembler input. */ 277169699Skan bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM); 278169699Skan 279132718Skan switch (code) 280117395Skan { 281132718Skan default: 282169699Skan if (cl_options[code].flags & (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX)) 283169699Skan break; 284169699Skan#ifdef CL_Fortran 285169699Skan if (lang_fortran && (cl_options[code].flags & (CL_Fortran))) 286169699Skan break; 287169699Skan#endif 288169699Skan result = 0; 289132718Skan break; 290117395Skan 291132718Skan case OPT__output_pch_: 292132718Skan pch_file = arg; 293117395Skan break; 294117395Skan 295132718Skan case OPT_A: 296132718Skan defer_opt (code, arg); 297117395Skan break; 298117395Skan 299117395Skan case OPT_C: 300117395Skan cpp_opts->discard_comments = 0; 301117395Skan break; 302117395Skan 303117395Skan case OPT_CC: 304117395Skan cpp_opts->discard_comments = 0; 305117395Skan cpp_opts->discard_comments_in_macro_exp = 0; 306117395Skan break; 307117395Skan 308132718Skan case OPT_D: 309132718Skan defer_opt (code, arg); 310132718Skan break; 311132718Skan 312117395Skan case OPT_E: 313117395Skan flag_preprocess_only = 1; 314117395Skan break; 315117395Skan 316117395Skan case OPT_H: 317117395Skan cpp_opts->print_include_names = 1; 318117395Skan break; 319117395Skan 320169699Skan case OPT_F: 321169699Skan TARGET_OPTF (xstrdup (arg)); 322169699Skan break; 323169699Skan 324132718Skan case OPT_I: 325132718Skan if (strcmp (arg, "-")) 326169699Skan add_path (xstrdup (arg), BRACKET, 0, true); 327132718Skan else 328132718Skan { 329132718Skan if (quote_chain_split) 330132718Skan error ("-I- specified twice"); 331132718Skan quote_chain_split = true; 332132718Skan split_quote_chain (); 333169699Skan inform ("obsolete option -I- used, please use -iquote instead"); 334132718Skan } 335132718Skan break; 336132718Skan 337117395Skan case OPT_M: 338117395Skan case OPT_MM: 339117395Skan /* When doing dependencies with -M or -MM, suppress normal 340117395Skan preprocessed output, but still do -dM etc. as software 341117395Skan depends on this. Preprocessed output does occur if -MD, -MMD 342117395Skan or environment var dependency generation is used. */ 343117395Skan cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER); 344132718Skan flag_no_output = 1; 345117395Skan cpp_opts->inhibit_warnings = 1; 346117395Skan break; 347117395Skan 348117395Skan case OPT_MD: 349117395Skan case OPT_MMD: 350117395Skan cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER); 351117395Skan deps_file = arg; 352117395Skan break; 353117395Skan 354117395Skan case OPT_MF: 355117395Skan deps_seen = true; 356117395Skan deps_file = arg; 357117395Skan break; 358117395Skan 359117395Skan case OPT_MG: 360117395Skan deps_seen = true; 361117395Skan cpp_opts->deps.missing_files = true; 362117395Skan break; 363117395Skan 364117395Skan case OPT_MP: 365117395Skan deps_seen = true; 366117395Skan cpp_opts->deps.phony_targets = true; 367117395Skan break; 368117395Skan 369117395Skan case OPT_MQ: 370117395Skan case OPT_MT: 371117395Skan deps_seen = true; 372117395Skan defer_opt (code, arg); 373117395Skan break; 374117395Skan 375117395Skan case OPT_P: 376132718Skan flag_no_line_commands = 1; 377117395Skan break; 378117395Skan 379132718Skan case OPT_fworking_directory: 380132718Skan flag_working_directory = value; 381132718Skan break; 382132718Skan 383132718Skan case OPT_U: 384132718Skan defer_opt (code, arg); 385132718Skan break; 386132718Skan 387117395Skan case OPT_Wall: 388260568Spfg /* APPLE LOCAL -Wmost */ 389260568Spfg case OPT_Wmost: 390132718Skan set_Wunused (value); 391132718Skan set_Wformat (value); 392132718Skan set_Wimplicit (value); 393132718Skan warn_char_subscripts = value; 394132718Skan warn_missing_braces = value; 395260568Spfg /* APPLE LOCAL begin -Wmost --dpatel */ 396260568Spfg if (code != OPT_Wmost) 397260568Spfg warn_parentheses = value; 398260568Spfg /* APPLE LOCAL end -Wmost --dpatel */ 399132718Skan warn_return_type = value; 400132718Skan warn_sequence_point = value; /* Was C only. */ 401132718Skan if (c_dialect_cxx ()) 402132718Skan warn_sign_compare = value; 403132718Skan warn_switch = value; 404259405Spfg set_warn_strict_aliasing (value); 405169699Skan warn_strict_overflow = value; 406169699Skan warn_address = value; 407132718Skan 408117395Skan /* Only warn about unknown pragmas that are not in system 409132718Skan headers. */ 410132718Skan warn_unknown_pragmas = value; 411117395Skan 412117395Skan /* We save the value of warn_uninitialized, since if they put 413117395Skan -Wuninitialized on the command line, we need to generate a 414117395Skan warning about not using it without also specifying -O. */ 415117395Skan if (warn_uninitialized != 1) 416132718Skan warn_uninitialized = (value ? 2 : 0); 417117395Skan 418132718Skan if (!c_dialect_cxx ()) 419117395Skan /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding 420117395Skan can turn it off only if it's not explicit. */ 421132718Skan warn_main = value * 2; 422117395Skan else 423117395Skan { 424117395Skan /* C++-specific warnings. */ 425132718Skan warn_reorder = value; 426132718Skan warn_nontemplate_friend = value; 427117395Skan } 428117395Skan 429132718Skan cpp_opts->warn_trigraphs = value; 430132718Skan cpp_opts->warn_comments = value; 431132718Skan cpp_opts->warn_num_sign_change = value; 432132718Skan cpp_opts->warn_multichar = value; /* Was C++ only. */ 433117395Skan 434169699Skan if (warn_pointer_sign == -1) 435169699Skan warn_pointer_sign = 1; 436117395Skan break; 437117395Skan 438117395Skan case OPT_Wcomment: 439117395Skan case OPT_Wcomments: 440132718Skan cpp_opts->warn_comments = value; 441117395Skan break; 442117395Skan 443117395Skan case OPT_Wdeprecated: 444132718Skan cpp_opts->warn_deprecated = value; 445117395Skan break; 446117395Skan 447117395Skan case OPT_Wendif_labels: 448132718Skan cpp_opts->warn_endif_labels = value; 449117395Skan break; 450117395Skan 451117395Skan case OPT_Werror: 452132718Skan cpp_opts->warnings_are_errors = value; 453169699Skan global_dc->warning_as_error_requested = value; 454117395Skan break; 455117395Skan 456132718Skan case OPT_Werror_implicit_function_declaration: 457132718Skan mesg_implicit_function_declaration = 2; 458117395Skan break; 459117395Skan 460117395Skan case OPT_Wformat: 461132718Skan set_Wformat (value); 462117395Skan break; 463117395Skan 464132718Skan case OPT_Wformat_: 465117395Skan set_Wformat (atoi (arg)); 466117395Skan break; 467117395Skan 468117395Skan case OPT_Wimplicit: 469132718Skan set_Wimplicit (value); 470117395Skan break; 471117395Skan 472117395Skan case OPT_Wimport: 473132718Skan /* Silently ignore for now. */ 474117395Skan break; 475117395Skan 476132718Skan case OPT_Winvalid_pch: 477132718Skan cpp_opts->warn_invalid_pch = value; 478132718Skan break; 479132718Skan 480117395Skan case OPT_Wmain: 481132718Skan if (value) 482117395Skan warn_main = 1; 483117395Skan else 484117395Skan warn_main = -1; 485117395Skan break; 486117395Skan 487169699Skan case OPT_Wmissing_include_dirs: 488169699Skan cpp_opts->warn_missing_include_dirs = value; 489117395Skan break; 490117395Skan 491117395Skan case OPT_Wmultichar: 492132718Skan cpp_opts->warn_multichar = value; 493117395Skan break; 494117395Skan 495259890Spfg /* APPLE LOCAL begin -Wnewline-eof */ 496259890Spfg case OPT_Wnewline_eof: 497259890Spfg cpp_opts->warn_newline_at_eof = value; 498259890Spfg break; 499259890Spfg /* APPLE LOCAL end -Wnewline-eof */ 500259890Spfg 501169699Skan case OPT_Wnormalized_: 502169699Skan if (!value || (arg && strcasecmp (arg, "none") == 0)) 503169699Skan cpp_opts->warn_normalize = normalized_none; 504169699Skan else if (!arg || strcasecmp (arg, "nfkc") == 0) 505169699Skan cpp_opts->warn_normalize = normalized_KC; 506169699Skan else if (strcasecmp (arg, "id") == 0) 507169699Skan cpp_opts->warn_normalize = normalized_identifier_C; 508169699Skan else if (strcasecmp (arg, "nfc") == 0) 509169699Skan cpp_opts->warn_normalize = normalized_C; 510169699Skan else 511169699Skan error ("argument %qs to %<-Wnormalized%> not recognized", arg); 512117395Skan break; 513117395Skan 514117395Skan case OPT_Wreturn_type: 515132718Skan warn_return_type = value; 516117395Skan break; 517117395Skan 518169699Skan case OPT_Wstrict_null_sentinel: 519169699Skan warn_strict_null_sentinel = value; 520117395Skan break; 521117395Skan 522117395Skan case OPT_Wsystem_headers: 523132718Skan cpp_opts->warn_system_headers = value; 524117395Skan break; 525117395Skan 526117395Skan case OPT_Wtraditional: 527132718Skan cpp_opts->warn_traditional = value; 528117395Skan break; 529117395Skan 530117395Skan case OPT_Wtrigraphs: 531132718Skan cpp_opts->warn_trigraphs = value; 532117395Skan break; 533117395Skan 534117395Skan case OPT_Wundef: 535132718Skan cpp_opts->warn_undef = value; 536117395Skan break; 537117395Skan 538117395Skan case OPT_Wunknown_pragmas: 539117395Skan /* Set to greater than 1, so that even unknown pragmas in 540132718Skan system headers will be warned about. */ 541132718Skan warn_unknown_pragmas = value * 2; 542117395Skan break; 543117395Skan 544117395Skan case OPT_Wunused_macros: 545132718Skan warn_unused_macros = value; 546117395Skan break; 547117395Skan 548169699Skan case OPT_Wvariadic_macros: 549169699Skan warn_variadic_macros = value; 550169699Skan break; 551169699Skan 552117395Skan case OPT_Wwrite_strings: 553169699Skan warn_write_strings = value; 554117395Skan break; 555132718Skan 556169699Skan case OPT_Weffc__: 557169699Skan warn_ecpp = value; 558169699Skan if (value) 559169699Skan warn_nonvdtor = true; 560169699Skan break; 561169699Skan 562117395Skan case OPT_ansi: 563132718Skan if (!c_dialect_cxx ()) 564117395Skan set_std_c89 (false, true); 565117395Skan else 566117395Skan set_std_cxx98 (true); 567117395Skan break; 568117395Skan 569117395Skan case OPT_d: 570117395Skan handle_OPT_d (arg); 571117395Skan break; 572117395Skan 573117395Skan case OPT_fcond_mismatch: 574132718Skan if (!c_dialect_cxx ()) 575117395Skan { 576132718Skan flag_cond_mismatch = value; 577117395Skan break; 578117395Skan } 579117395Skan /* Fall through. */ 580117395Skan 581117395Skan case OPT_fall_virtual: 582132718Skan case OPT_falt_external_templates: 583117395Skan case OPT_fenum_int_equiv: 584132718Skan case OPT_fexternal_templates: 585117395Skan case OPT_fguiding_decls: 586117395Skan case OPT_fhonor_std: 587117395Skan case OPT_fhuge_objects: 588117395Skan case OPT_flabels_ok: 589132718Skan case OPT_fname_mangling_version_: 590117395Skan case OPT_fnew_abi: 591117395Skan case OPT_fnonnull_objects: 592117395Skan case OPT_fsquangle: 593117395Skan case OPT_fstrict_prototype: 594117395Skan case OPT_fthis_is_variable: 595117395Skan case OPT_fvtable_thunks: 596117395Skan case OPT_fxref: 597132718Skan case OPT_fvtable_gc: 598169699Skan warning (0, "switch %qs is no longer supported", option->opt_text); 599117395Skan break; 600117395Skan 601117395Skan case OPT_faccess_control: 602132718Skan flag_access_control = value; 603117395Skan break; 604117395Skan 605117395Skan case OPT_fasm: 606132718Skan flag_no_asm = !value; 607117395Skan break; 608117395Skan 609117395Skan case OPT_fbuiltin: 610132718Skan flag_no_builtin = !value; 611117395Skan break; 612117395Skan 613117395Skan case OPT_fbuiltin_: 614132718Skan if (value) 615117395Skan result = 0; 616117395Skan else 617117395Skan disable_builtin_function (arg); 618117395Skan break; 619117395Skan 620259405Spfg case OPT_fdirectives_only: 621259405Spfg cpp_opts->directives_only = 1; 622259405Spfg break; 623259405Spfg 624117395Skan case OPT_fdollars_in_identifiers: 625132718Skan cpp_opts->dollars_in_ident = value; 626117395Skan break; 627117395Skan 628117395Skan case OPT_ffreestanding: 629132718Skan value = !value; 630132718Skan /* Fall through.... */ 631117395Skan case OPT_fhosted: 632132718Skan flag_hosted = value; 633132718Skan flag_no_builtin = !value; 634117395Skan /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */ 635132718Skan if (!value && warn_main == 2) 636117395Skan warn_main = 0; 637117395Skan break; 638117395Skan 639117395Skan case OPT_fshort_double: 640132718Skan flag_short_double = value; 641117395Skan break; 642117395Skan 643117395Skan case OPT_fshort_enums: 644132718Skan flag_short_enums = value; 645117395Skan break; 646117395Skan 647117395Skan case OPT_fshort_wchar: 648132718Skan flag_short_wchar = value; 649117395Skan break; 650117395Skan 651117395Skan case OPT_fsigned_bitfields: 652132718Skan flag_signed_bitfields = value; 653117395Skan break; 654117395Skan 655117395Skan case OPT_fsigned_char: 656132718Skan flag_signed_char = value; 657117395Skan break; 658117395Skan 659117395Skan case OPT_funsigned_bitfields: 660132718Skan flag_signed_bitfields = !value; 661117395Skan break; 662117395Skan 663117395Skan case OPT_funsigned_char: 664132718Skan flag_signed_char = !value; 665117395Skan break; 666117395Skan 667117395Skan case OPT_fcheck_new: 668132718Skan flag_check_new = value; 669117395Skan break; 670117395Skan 671117395Skan case OPT_fconserve_space: 672132718Skan flag_conserve_space = value; 673117395Skan break; 674117395Skan 675132718Skan case OPT_fconstant_string_class_: 676117395Skan constant_string_class_name = arg; 677117395Skan break; 678117395Skan 679117395Skan case OPT_fdefault_inline: 680132718Skan flag_default_inline = value; 681117395Skan break; 682117395Skan 683117395Skan case OPT_felide_constructors: 684132718Skan flag_elide_constructors = value; 685117395Skan break; 686117395Skan 687117395Skan case OPT_fenforce_eh_specs: 688132718Skan flag_enforce_eh_specs = value; 689117395Skan break; 690117395Skan 691169699Skan case OPT_fextended_identifiers: 692169699Skan cpp_opts->extended_identifiers = value; 693117395Skan break; 694117395Skan 695117395Skan case OPT_ffor_scope: 696132718Skan flag_new_for_scope = value; 697117395Skan break; 698117395Skan 699117395Skan case OPT_fgnu_keywords: 700132718Skan flag_no_gnu_keywords = !value; 701117395Skan break; 702117395Skan 703117395Skan case OPT_fgnu_runtime: 704132718Skan flag_next_runtime = !value; 705117395Skan break; 706117395Skan 707117395Skan case OPT_fhandle_exceptions: 708169699Skan warning (0, "-fhandle-exceptions has been renamed -fexceptions (and is now on by default)"); 709132718Skan flag_exceptions = value; 710117395Skan break; 711117395Skan 712117395Skan case OPT_fimplement_inlines: 713132718Skan flag_implement_inlines = value; 714117395Skan break; 715117395Skan 716117395Skan case OPT_fimplicit_inline_templates: 717132718Skan flag_implicit_inline_templates = value; 718117395Skan break; 719117395Skan 720117395Skan case OPT_fimplicit_templates: 721132718Skan flag_implicit_templates = value; 722117395Skan break; 723117395Skan 724260074Spfg case OPT_flax_vector_conversions: 725260074Spfg flag_lax_vector_conversions = value; 726260074Spfg break; 727260074Spfg 728117395Skan case OPT_fms_extensions: 729132718Skan flag_ms_extensions = value; 730117395Skan break; 731117395Skan 732117395Skan case OPT_fnext_runtime: 733132718Skan flag_next_runtime = value; 734117395Skan break; 735117395Skan 736132718Skan case OPT_fnil_receivers: 737132718Skan flag_nil_receivers = value; 738132718Skan break; 739132718Skan 740117395Skan case OPT_fnonansi_builtins: 741132718Skan flag_no_nonansi_builtin = !value; 742117395Skan break; 743117395Skan 744117395Skan case OPT_foperator_names: 745132718Skan cpp_opts->operator_names = value; 746117395Skan break; 747117395Skan 748117395Skan case OPT_foptional_diags: 749132718Skan flag_optional_diags = value; 750117395Skan break; 751117395Skan 752132718Skan case OPT_fpch_deps: 753132718Skan cpp_opts->restore_pch_deps = value; 754132718Skan break; 755132718Skan 756169699Skan case OPT_fpch_preprocess: 757169699Skan flag_pch_preprocess = value; 758169699Skan break; 759169699Skan 760117395Skan case OPT_fpermissive: 761132718Skan flag_permissive = value; 762117395Skan break; 763117395Skan 764117395Skan case OPT_fpreprocessed: 765132718Skan cpp_opts->preprocessed = value; 766117395Skan break; 767117395Skan 768132718Skan case OPT_freplace_objc_classes: 769132718Skan flag_replace_objc_classes = value; 770132718Skan break; 771169699Skan 772117395Skan case OPT_frepo: 773132718Skan flag_use_repository = value; 774132718Skan if (value) 775117395Skan flag_implicit_templates = 0; 776117395Skan break; 777117395Skan 778117395Skan case OPT_frtti: 779132718Skan flag_rtti = value; 780117395Skan break; 781117395Skan 782117395Skan case OPT_fshow_column: 783132718Skan cpp_opts->show_column = value; 784117395Skan break; 785117395Skan 786117395Skan case OPT_fstats: 787132718Skan flag_detailed_statistics = value; 788117395Skan break; 789117395Skan 790132718Skan case OPT_ftabstop_: 791117395Skan /* It is documented that we silently ignore silly values. */ 792132718Skan if (value >= 1 && value <= 100) 793132718Skan cpp_opts->tabstop = value; 794117395Skan break; 795117395Skan 796132718Skan case OPT_fexec_charset_: 797132718Skan cpp_opts->narrow_charset = arg; 798117395Skan break; 799117395Skan 800132718Skan case OPT_fwide_exec_charset_: 801132718Skan cpp_opts->wide_charset = arg; 802117395Skan break; 803117395Skan 804132718Skan case OPT_finput_charset_: 805132718Skan cpp_opts->input_charset = arg; 806132718Skan break; 807132718Skan 808132718Skan case OPT_ftemplate_depth_: 809132718Skan max_tinst_depth = value; 810132718Skan break; 811132718Skan 812117395Skan case OPT_fuse_cxa_atexit: 813132718Skan flag_use_cxa_atexit = value; 814117395Skan break; 815169699Skan 816169699Skan case OPT_fuse_cxa_get_exception_ptr: 817169699Skan flag_use_cxa_get_exception_ptr = value; 818169699Skan break; 819117395Skan 820169699Skan case OPT_fvisibility_inlines_hidden: 821169699Skan visibility_options.inlines_hidden = value; 822169699Skan break; 823169699Skan 824117395Skan case OPT_fweak: 825132718Skan flag_weak = value; 826117395Skan break; 827117395Skan 828169699Skan case OPT_fthreadsafe_statics: 829169699Skan flag_threadsafe_statics = value; 830169699Skan break; 831169699Skan 832132718Skan case OPT_fzero_link: 833132718Skan flag_zero_link = value; 834132718Skan break; 835132718Skan 836117395Skan case OPT_gen_decls: 837117395Skan flag_gen_declaration = 1; 838117395Skan break; 839117395Skan 840259268Spfg case OPT_femit_struct_debug_baseonly: 841259268Spfg set_struct_debug_option ("base"); 842259268Spfg break; 843259268Spfg 844259268Spfg case OPT_femit_struct_debug_reduced: 845259268Spfg set_struct_debug_option ("dir:ord:sys,dir:gen:any,ind:base"); 846259268Spfg break; 847259268Spfg 848259268Spfg case OPT_femit_struct_debug_detailed_: 849259268Spfg set_struct_debug_option (arg); 850259268Spfg break; 851259268Spfg 852132718Skan case OPT_idirafter: 853169699Skan add_path (xstrdup (arg), AFTER, 0, true); 854132718Skan break; 855132718Skan 856132718Skan case OPT_imacros: 857132718Skan case OPT_include: 858132718Skan defer_opt (code, arg); 859132718Skan break; 860132718Skan 861169699Skan case OPT_imultilib: 862169699Skan imultilib = arg; 863169699Skan break; 864169699Skan 865132718Skan case OPT_iprefix: 866132718Skan iprefix = arg; 867132718Skan break; 868132718Skan 869169699Skan case OPT_iquote: 870169699Skan add_path (xstrdup (arg), QUOTE, 0, true); 871169699Skan break; 872169699Skan 873132718Skan case OPT_isysroot: 874132718Skan sysroot = arg; 875132718Skan break; 876132718Skan 877132718Skan case OPT_isystem: 878169699Skan add_path (xstrdup (arg), SYSTEM, 0, true); 879132718Skan break; 880132718Skan 881132718Skan case OPT_iwithprefix: 882132718Skan add_prefixed_path (arg, SYSTEM); 883132718Skan break; 884132718Skan 885132718Skan case OPT_iwithprefixbefore: 886132718Skan add_prefixed_path (arg, BRACKET); 887132718Skan break; 888132718Skan 889117395Skan case OPT_lang_asm: 890117395Skan cpp_set_lang (parse_in, CLK_ASM); 891132718Skan cpp_opts->dollars_in_ident = false; 892117395Skan break; 893117395Skan 894169699Skan case OPT_lang_fortran: 895169699Skan lang_fortran = true; 896169699Skan break; 897169699Skan 898117395Skan case OPT_lang_objc: 899117395Skan cpp_opts->objc = 1; 900117395Skan break; 901117395Skan 902117395Skan case OPT_nostdinc: 903132718Skan std_inc = false; 904117395Skan break; 905117395Skan 906132718Skan case OPT_nostdinc__: 907132718Skan std_cxx_inc = false; 908117395Skan break; 909117395Skan 910117395Skan case OPT_o: 911117395Skan if (!out_fname) 912117395Skan out_fname = arg; 913117395Skan else 914132718Skan error ("output filename specified twice"); 915117395Skan break; 916117395Skan 917117395Skan /* We need to handle the -pedantic switches here, rather than in 918117395Skan c_common_post_options, so that a subsequent -Wno-endif-labels 919117395Skan is not overridden. */ 920117395Skan case OPT_pedantic_errors: 921117395Skan cpp_opts->pedantic_errors = 1; 922132718Skan /* Fall through. */ 923117395Skan case OPT_pedantic: 924117395Skan cpp_opts->pedantic = 1; 925117395Skan cpp_opts->warn_endif_labels = 1; 926169699Skan if (warn_pointer_sign == -1) 927169699Skan warn_pointer_sign = 1; 928169699Skan if (warn_overlength_strings == -1) 929169699Skan warn_overlength_strings = 1; 930117395Skan break; 931117395Skan 932117395Skan case OPT_print_objc_runtime_info: 933117395Skan print_struct_values = 1; 934117395Skan break; 935117395Skan 936169699Skan case OPT_print_pch_checksum: 937169699Skan c_common_print_pch_checksum (stdout); 938169699Skan exit_after_options = true; 939169699Skan break; 940169699Skan 941117395Skan case OPT_remap: 942117395Skan cpp_opts->remap = 1; 943117395Skan break; 944117395Skan 945132718Skan case OPT_std_c__98: 946132718Skan case OPT_std_gnu__98: 947169699Skan if (!preprocessing_asm_p) 948169699Skan set_std_cxx98 (code == OPT_std_c__98 /* ISO */); 949117395Skan break; 950117395Skan 951117395Skan case OPT_std_c89: 952117395Skan case OPT_std_iso9899_1990: 953117395Skan case OPT_std_iso9899_199409: 954169699Skan if (!preprocessing_asm_p) 955169699Skan set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */); 956117395Skan break; 957117395Skan 958117395Skan case OPT_std_gnu89: 959169699Skan if (!preprocessing_asm_p) 960169699Skan set_std_c89 (false /* c94 */, false /* ISO */); 961117395Skan break; 962117395Skan 963117395Skan case OPT_std_c99: 964117395Skan case OPT_std_c9x: 965117395Skan case OPT_std_iso9899_1999: 966117395Skan case OPT_std_iso9899_199x: 967169699Skan if (!preprocessing_asm_p) 968169699Skan set_std_c99 (true /* ISO */); 969117395Skan break; 970117395Skan 971117395Skan case OPT_std_gnu99: 972117395Skan case OPT_std_gnu9x: 973169699Skan if (!preprocessing_asm_p) 974169699Skan set_std_c99 (false /* ISO */); 975117395Skan break; 976117395Skan 977117395Skan case OPT_trigraphs: 978117395Skan cpp_opts->trigraphs = 1; 979117395Skan break; 980117395Skan 981117395Skan case OPT_traditional_cpp: 982117395Skan cpp_opts->traditional = 1; 983117395Skan break; 984117395Skan 985117395Skan case OPT_undef: 986117395Skan flag_undef = 1; 987117395Skan break; 988117395Skan 989117395Skan case OPT_w: 990117395Skan cpp_opts->inhibit_warnings = 1; 991117395Skan break; 992117395Skan 993117395Skan case OPT_v: 994132718Skan verbose = true; 995117395Skan break; 996117395Skan } 997117395Skan 998117395Skan return result; 999117395Skan} 1000117395Skan 1001117395Skan/* Post-switch processing. */ 1002117395Skanbool 1003132718Skanc_common_post_options (const char **pfilename) 1004117395Skan{ 1005132718Skan struct cpp_callbacks *cb; 1006132718Skan 1007117395Skan /* Canonicalize the input and output filenames. */ 1008132718Skan if (in_fnames == NULL) 1009132718Skan { 1010169699Skan in_fnames = XNEWVEC (const char *, 1); 1011132718Skan in_fnames[0] = ""; 1012132718Skan } 1013132718Skan else if (strcmp (in_fnames[0], "-") == 0) 1014132718Skan in_fnames[0] = ""; 1015117395Skan 1016117395Skan if (out_fname == NULL || !strcmp (out_fname, "-")) 1017117395Skan out_fname = ""; 1018117395Skan 1019117395Skan if (cpp_opts->deps.style == DEPS_NONE) 1020117395Skan check_deps_environment_vars (); 1021117395Skan 1022117395Skan handle_deferred_opts (); 1023117395Skan 1024117395Skan sanitize_cpp_opts (); 1025117395Skan 1026169699Skan register_include_chains (parse_in, sysroot, iprefix, imultilib, 1027132718Skan std_inc, std_cxx_inc && c_dialect_cxx (), verbose); 1028132718Skan 1029169699Skan#ifdef C_COMMON_OVERRIDE_OPTIONS 1030169699Skan /* Some machines may reject certain combinations of C 1031169699Skan language-specific options. */ 1032169699Skan C_COMMON_OVERRIDE_OPTIONS; 1033169699Skan#endif 1034169699Skan 1035117395Skan flag_inline_trees = 1; 1036117395Skan 1037169699Skan /* Use tree inlining. */ 1038169699Skan if (!flag_no_inline) 1039169699Skan flag_no_inline = 1; 1040169699Skan if (flag_inline_functions) 1041169699Skan flag_inline_trees = 2; 1042117395Skan 1043189824Sdas /* By default we use C99 inline semantics in GNU99 or C99 mode. C99 1044189824Sdas inline semantics are not supported in GNU89 or C89 mode. */ 1045189824Sdas if (flag_gnu89_inline == -1) 1046189824Sdas flag_gnu89_inline = !flag_isoc99; 1047189824Sdas else if (!flag_gnu89_inline && !flag_isoc99) 1048189824Sdas error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode"); 1049169699Skan 1050169699Skan /* If we are given more than one input file, we must use 1051169699Skan unit-at-a-time mode. */ 1052169699Skan if (num_in_fnames > 1) 1053169699Skan flag_unit_at_a_time = 1; 1054169699Skan 1055169699Skan /* Default to ObjC sjlj exception handling if NeXT runtime. */ 1056169699Skan if (flag_objc_sjlj_exceptions < 0) 1057169699Skan flag_objc_sjlj_exceptions = flag_next_runtime; 1058169699Skan if (flag_objc_exceptions && !flag_objc_sjlj_exceptions) 1059169699Skan flag_exceptions = 1; 1060169699Skan 1061169699Skan /* -Wextra implies -Wsign-compare, -Wmissing-field-initializers and 1062169699Skan -Woverride-init, but not if explicitly overridden. */ 1063132718Skan if (warn_sign_compare == -1) 1064132718Skan warn_sign_compare = extra_warnings; 1065169699Skan if (warn_missing_field_initializers == -1) 1066169699Skan warn_missing_field_initializers = extra_warnings; 1067169699Skan if (warn_override_init == -1) 1068169699Skan warn_override_init = extra_warnings; 1069132718Skan 1070169699Skan /* -Wpointer_sign is disabled by default, but it is enabled if any 1071169699Skan of -Wall or -pedantic are given. */ 1072169699Skan if (warn_pointer_sign == -1) 1073169699Skan warn_pointer_sign = 0; 1074169699Skan 1075169699Skan /* -Woverlength-strings is off by default, but is enabled by -pedantic. 1076169699Skan It is never enabled in C++, as the minimum limit is not normative 1077169699Skan in that standard. */ 1078169699Skan if (warn_overlength_strings == -1 || c_dialect_cxx ()) 1079169699Skan warn_overlength_strings = 0; 1080169699Skan 1081117395Skan /* Special format checking options don't work without -Wformat; warn if 1082117395Skan they are used. */ 1083169699Skan if (!warn_format) 1084169699Skan { 1085169699Skan warning (OPT_Wformat_y2k, 1086169699Skan "-Wformat-y2k ignored without -Wformat"); 1087169699Skan warning (OPT_Wformat_extra_args, 1088169699Skan "-Wformat-extra-args ignored without -Wformat"); 1089169699Skan warning (OPT_Wformat_zero_length, 1090169699Skan "-Wformat-zero-length ignored without -Wformat"); 1091169699Skan warning (OPT_Wformat_nonliteral, 1092169699Skan "-Wformat-nonliteral ignored without -Wformat"); 1093169699Skan warning (OPT_Wformat_security, 1094169699Skan "-Wformat-security ignored without -Wformat"); 1095169699Skan } 1096117395Skan 1097169699Skan /* C99 requires special handling of complex multiplication and division; 1098169699Skan -ffast-math and -fcx-limited-range are handled in process_options. */ 1099169699Skan if (flag_isoc99) 1100169699Skan flag_complex_method = 2; 1101169699Skan 1102132718Skan if (flag_preprocess_only) 1103132718Skan { 1104132718Skan /* Open the output now. We must do so even if flag_no_output is 1105132718Skan on, because there may be other output than from the actual 1106132718Skan preprocessing (e.g. from -dM). */ 1107132718Skan if (out_fname[0] == '\0') 1108132718Skan out_stream = stdout; 1109132718Skan else 1110132718Skan out_stream = fopen (out_fname, "w"); 1111132718Skan 1112132718Skan if (out_stream == NULL) 1113132718Skan { 1114132718Skan fatal_error ("opening output file %s: %m", out_fname); 1115132718Skan return false; 1116132718Skan } 1117132718Skan 1118132718Skan if (num_in_fnames > 1) 1119132718Skan error ("too many filenames given. Type %s --help for usage", 1120132718Skan progname); 1121132718Skan 1122132718Skan init_pp_output (out_stream); 1123132718Skan } 1124132718Skan else 1125132718Skan { 1126132718Skan init_c_lex (); 1127132718Skan 1128132718Skan /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */ 1129169699Skan input_location = UNKNOWN_LOCATION; 1130132718Skan } 1131132718Skan 1132132718Skan cb = cpp_get_callbacks (parse_in); 1133132718Skan cb->file_change = cb_file_change; 1134132718Skan cb->dir_change = cb_dir_change; 1135132718Skan cpp_post_options (parse_in); 1136132718Skan 1137169699Skan input_location = UNKNOWN_LOCATION; 1138132718Skan 1139117395Skan /* If an error has occurred in cpplib, note it so we fail 1140117395Skan immediately. */ 1141117395Skan errorcount += cpp_errors (parse_in); 1142117395Skan 1143132718Skan *pfilename = this_input_filename 1144132718Skan = cpp_read_main_file (parse_in, in_fnames[0]); 1145146908Skan /* Don't do any compilation or preprocessing if there is no input file. */ 1146132718Skan if (this_input_filename == NULL) 1147146908Skan { 1148146908Skan errorcount++; 1149146908Skan return false; 1150146908Skan } 1151117395Skan 1152132718Skan if (flag_working_directory 1153169699Skan && flag_preprocess_only && !flag_no_line_commands) 1154132718Skan pp_dir_change (parse_in, get_src_pwd ()); 1155117395Skan 1156132718Skan return flag_preprocess_only; 1157117395Skan} 1158117395Skan 1159117395Skan/* Front end initialization common to C, ObjC and C++. */ 1160132718Skanbool 1161132718Skanc_common_init (void) 1162117395Skan{ 1163117395Skan /* Set up preprocessor arithmetic. Must be done after call to 1164117395Skan c_common_nodes_and_builtins for type nodes to be good. */ 1165117395Skan cpp_opts->precision = TYPE_PRECISION (intmax_type_node); 1166117395Skan cpp_opts->char_precision = TYPE_PRECISION (char_type_node); 1167117395Skan cpp_opts->int_precision = TYPE_PRECISION (integer_type_node); 1168117395Skan cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node); 1169169699Skan cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node); 1170132718Skan cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN; 1171117395Skan 1172132718Skan /* This can't happen until after wchar_precision and bytes_big_endian 1173132718Skan are known. */ 1174132718Skan cpp_init_iconv (parse_in); 1175117395Skan 1176169699Skan if (version_flag) 1177169699Skan c_common_print_pch_checksum (stderr); 1178169699Skan 1179117395Skan if (flag_preprocess_only) 1180117395Skan { 1181132718Skan finish_options (); 1182132718Skan preprocess_file (parse_in); 1183132718Skan return false; 1184117395Skan } 1185117395Skan 1186132718Skan /* Has to wait until now so that cpplib has its hash table. */ 1187117395Skan init_pragma (); 1188117395Skan 1189132718Skan return true; 1190117395Skan} 1191117395Skan 1192132718Skan/* Initialize the integrated preprocessor after debug output has been 1193132718Skan initialized; loop over each input file. */ 1194132718Skanvoid 1195169699Skanc_common_parse_file (int set_yydebug) 1196132718Skan{ 1197169699Skan unsigned int i; 1198169699Skan 1199169699Skan /* Enable parser debugging, if requested and we can. If requested 1200169699Skan and we can't, notify the user. */ 1201132718Skan#if YYDEBUG != 0 1202132718Skan yydebug = set_yydebug; 1203132718Skan#else 1204169699Skan if (set_yydebug) 1205169699Skan warning (0, "YYDEBUG was not defined at build time, -dy ignored"); 1206132718Skan#endif 1207132718Skan 1208169699Skan i = 0; 1209169699Skan for (;;) 1210132718Skan { 1211169699Skan /* Start the main input file, if the debug writer wants it. */ 1212169699Skan if (debug_hooks->start_end_main_source_file) 1213169699Skan (*debug_hooks->start_source_file) (0, this_input_filename); 1214132718Skan finish_options (); 1215169699Skan pch_init (); 1216169699Skan push_file_scope (); 1217132718Skan c_parse_file (); 1218169699Skan finish_file (); 1219169699Skan pop_file_scope (); 1220169699Skan /* And end the main input file, if the debug writer wants it */ 1221169699Skan if (debug_hooks->start_end_main_source_file) 1222169699Skan (*debug_hooks->end_source_file) (0); 1223169699Skan if (++i >= num_in_fnames) 1224169699Skan break; 1225169699Skan cpp_undef_all (parse_in); 1226169699Skan this_input_filename 1227169699Skan = cpp_read_main_file (parse_in, in_fnames[i]); 1228169699Skan /* If an input file is missing, abandon further compilation. 1229169699Skan cpplib has issued a diagnostic. */ 1230169699Skan if (!this_input_filename) 1231169699Skan break; 1232169699Skan } 1233132718Skan} 1234132718Skan 1235117395Skan/* Common finish hook for the C, ObjC and C++ front ends. */ 1236117395Skanvoid 1237132718Skanc_common_finish (void) 1238117395Skan{ 1239117395Skan FILE *deps_stream = NULL; 1240117395Skan 1241117395Skan if (cpp_opts->deps.style != DEPS_NONE) 1242117395Skan { 1243117395Skan /* If -M or -MM was seen without -MF, default output to the 1244117395Skan output stream. */ 1245117395Skan if (!deps_file) 1246117395Skan deps_stream = out_stream; 1247117395Skan else 1248117395Skan { 1249117395Skan deps_stream = fopen (deps_file, deps_append ? "a": "w"); 1250117395Skan if (!deps_stream) 1251132718Skan fatal_error ("opening dependency file %s: %m", deps_file); 1252117395Skan } 1253117395Skan } 1254117395Skan 1255117395Skan /* For performance, avoid tearing down cpplib's internal structures 1256117395Skan with cpp_destroy (). */ 1257117395Skan errorcount += cpp_finish (parse_in, deps_stream); 1258117395Skan 1259117395Skan if (deps_stream && deps_stream != out_stream 1260117395Skan && (ferror (deps_stream) || fclose (deps_stream))) 1261132718Skan fatal_error ("closing dependency file %s: %m", deps_file); 1262117395Skan 1263117395Skan if (out_stream && (ferror (out_stream) || fclose (out_stream))) 1264132718Skan fatal_error ("when writing output to %s: %m", out_fname); 1265117395Skan} 1266117395Skan 1267117395Skan/* Either of two environment variables can specify output of 1268117395Skan dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE 1269117395Skan DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to 1270117395Skan and DEPS_TARGET is the target to mention in the deps. They also 1271117395Skan result in dependency information being appended to the output file 1272117395Skan rather than overwriting it, and like Sun's compiler 1273117395Skan SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */ 1274117395Skanstatic void 1275132718Skancheck_deps_environment_vars (void) 1276117395Skan{ 1277117395Skan char *spec; 1278117395Skan 1279117395Skan GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT"); 1280117395Skan if (spec) 1281117395Skan cpp_opts->deps.style = DEPS_USER; 1282117395Skan else 1283117395Skan { 1284117395Skan GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES"); 1285117395Skan if (spec) 1286117395Skan { 1287117395Skan cpp_opts->deps.style = DEPS_SYSTEM; 1288117395Skan cpp_opts->deps.ignore_main_file = true; 1289117395Skan } 1290117395Skan } 1291117395Skan 1292117395Skan if (spec) 1293117395Skan { 1294117395Skan /* Find the space before the DEPS_TARGET, if there is one. */ 1295117395Skan char *s = strchr (spec, ' '); 1296117395Skan if (s) 1297117395Skan { 1298117395Skan /* Let the caller perform MAKE quoting. */ 1299117395Skan defer_opt (OPT_MT, s + 1); 1300117395Skan *s = '\0'; 1301117395Skan } 1302117395Skan 1303117395Skan /* Command line -MF overrides environment variables and default. */ 1304117395Skan if (!deps_file) 1305117395Skan deps_file = spec; 1306117395Skan 1307117395Skan deps_append = 1; 1308169699Skan deps_seen = true; 1309117395Skan } 1310117395Skan} 1311117395Skan 1312117395Skan/* Handle deferred command line switches. */ 1313117395Skanstatic void 1314132718Skanhandle_deferred_opts (void) 1315117395Skan{ 1316117395Skan size_t i; 1317169699Skan struct deps *deps; 1318117395Skan 1319169699Skan /* Avoid allocating the deps buffer if we don't need it. 1320169699Skan (This flag may be true without there having been -MT or -MQ 1321169699Skan options, but we'll still need the deps buffer.) */ 1322169699Skan if (!deps_seen) 1323169699Skan return; 1324169699Skan 1325169699Skan deps = cpp_get_deps (parse_in); 1326169699Skan 1327117395Skan for (i = 0; i < deferred_count; i++) 1328117395Skan { 1329117395Skan struct deferred_opt *opt = &deferred_opts[i]; 1330117395Skan 1331132718Skan if (opt->code == OPT_MT || opt->code == OPT_MQ) 1332169699Skan deps_add_target (deps, opt->arg, opt->code == OPT_MQ); 1333117395Skan } 1334117395Skan} 1335117395Skan 1336117395Skan/* These settings are appropriate for GCC, but not necessarily so for 1337117395Skan cpplib as a library. */ 1338117395Skanstatic void 1339132718Skansanitize_cpp_opts (void) 1340117395Skan{ 1341117395Skan /* If we don't know what style of dependencies to output, complain 1342117395Skan if any other dependency switches have been given. */ 1343117395Skan if (deps_seen && cpp_opts->deps.style == DEPS_NONE) 1344117395Skan error ("to generate dependencies you must specify either -M or -MM"); 1345117395Skan 1346117395Skan /* -dM and dependencies suppress normal output; do it here so that 1347117395Skan the last -d[MDN] switch overrides earlier ones. */ 1348132718Skan if (flag_dump_macros == 'M') 1349132718Skan flag_no_output = 1; 1350117395Skan 1351259405Spfg /* By default, -fdirectives-only implies -dD. This allows subsequent phases 1352259405Spfg to perform proper macro expansion. */ 1353259405Spfg if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros) 1354259405Spfg flag_dump_macros = 'D'; 1355259405Spfg 1356117395Skan /* Disable -dD, -dN and -dI if normal output is suppressed. Allow 1357117395Skan -dM since at least glibc relies on -M -dM to work. */ 1358169699Skan /* Also, flag_no_output implies flag_no_line_commands, always. */ 1359132718Skan if (flag_no_output) 1360117395Skan { 1361132718Skan if (flag_dump_macros != 'M') 1362132718Skan flag_dump_macros = 0; 1363132718Skan flag_dump_includes = 0; 1364146908Skan flag_no_line_commands = 1; 1365117395Skan } 1366117395Skan 1367117395Skan cpp_opts->unsigned_char = !flag_signed_char; 1368117395Skan cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS; 1369117395Skan 1370117395Skan /* We want -Wno-long-long to override -pedantic -std=non-c99 1371117395Skan and/or -Wtraditional, whatever the ordering. */ 1372117395Skan cpp_opts->warn_long_long 1373117395Skan = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional); 1374132718Skan 1375169699Skan /* Similarly with -Wno-variadic-macros. No check for c99 here, since 1376169699Skan this also turns off warnings about GCCs extension. */ 1377169699Skan cpp_opts->warn_variadic_macros 1378169699Skan = warn_variadic_macros && (pedantic || warn_traditional); 1379169699Skan 1380132718Skan /* If we're generating preprocessor output, emit current directory 1381132718Skan if explicitly requested or if debugging information is enabled. 1382132718Skan ??? Maybe we should only do it for debugging formats that 1383132718Skan actually output the current directory? */ 1384132718Skan if (flag_working_directory == -1) 1385132718Skan flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE); 1386259405Spfg 1387259405Spfg if (cpp_opts->directives_only) 1388259405Spfg { 1389259405Spfg if (warn_unused_macros) 1390259405Spfg error ("-fdirectives-only is incompatible with -Wunused_macros"); 1391259405Spfg if (cpp_opts->traditional) 1392259405Spfg error ("-fdirectives-only is incompatible with -traditional"); 1393259405Spfg } 1394117395Skan} 1395117395Skan 1396132718Skan/* Add include path with a prefix at the front of its name. */ 1397132718Skanstatic void 1398132718Skanadd_prefixed_path (const char *suffix, size_t chain) 1399132718Skan{ 1400132718Skan char *path; 1401132718Skan const char *prefix; 1402132718Skan size_t prefix_len, suffix_len; 1403132718Skan 1404132718Skan suffix_len = strlen (suffix); 1405132718Skan prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR; 1406132718Skan prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len; 1407132718Skan 1408169699Skan path = (char *) xmalloc (prefix_len + suffix_len + 1); 1409132718Skan memcpy (path, prefix, prefix_len); 1410132718Skan memcpy (path + prefix_len, suffix, suffix_len); 1411132718Skan path[prefix_len + suffix_len] = '\0'; 1412132718Skan 1413169699Skan add_path (path, chain, 0, false); 1414132718Skan} 1415132718Skan 1416132718Skan/* Handle -D, -U, -A, -imacros, and the first -include. */ 1417132718Skanstatic void 1418132718Skanfinish_options (void) 1419132718Skan{ 1420132718Skan if (!cpp_opts->preprocessed) 1421132718Skan { 1422132718Skan size_t i; 1423132718Skan 1424169699Skan cb_file_change (parse_in, 1425169699Skan linemap_add (&line_table, LC_RENAME, 0, 1426169699Skan _("<built-in>"), 0)); 1427169699Skan 1428132718Skan cpp_init_builtins (parse_in, flag_hosted); 1429132718Skan c_cpp_builtins (parse_in); 1430132718Skan 1431132718Skan /* We're about to send user input to cpplib, so make it warn for 1432132718Skan things that we previously (when we sent it internal definitions) 1433132718Skan told it to not warn. 1434132718Skan 1435132718Skan C99 permits implementation-defined characters in identifiers. 1436132718Skan The documented meaning of -std= is to turn off extensions that 1437132718Skan conflict with the specified standard, and since a strictly 1438132718Skan conforming program cannot contain a '$', we do not condition 1439132718Skan their acceptance on the -std= setting. */ 1440132718Skan cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99); 1441132718Skan 1442169699Skan cb_file_change (parse_in, 1443169699Skan linemap_add (&line_table, LC_RENAME, 0, 1444169699Skan _("<command-line>"), 0)); 1445169699Skan 1446132718Skan for (i = 0; i < deferred_count; i++) 1447132718Skan { 1448132718Skan struct deferred_opt *opt = &deferred_opts[i]; 1449132718Skan 1450132718Skan if (opt->code == OPT_D) 1451132718Skan cpp_define (parse_in, opt->arg); 1452132718Skan else if (opt->code == OPT_U) 1453132718Skan cpp_undef (parse_in, opt->arg); 1454132718Skan else if (opt->code == OPT_A) 1455132718Skan { 1456132718Skan if (opt->arg[0] == '-') 1457132718Skan cpp_unassert (parse_in, opt->arg + 1); 1458132718Skan else 1459132718Skan cpp_assert (parse_in, opt->arg); 1460132718Skan } 1461132718Skan } 1462132718Skan 1463132718Skan /* Handle -imacros after -D and -U. */ 1464132718Skan for (i = 0; i < deferred_count; i++) 1465132718Skan { 1466132718Skan struct deferred_opt *opt = &deferred_opts[i]; 1467132718Skan 1468132718Skan if (opt->code == OPT_imacros 1469132718Skan && cpp_push_include (parse_in, opt->arg)) 1470132718Skan { 1471132718Skan /* Disable push_command_line_include callback for now. */ 1472132718Skan include_cursor = deferred_count + 1; 1473132718Skan cpp_scan_nooutput (parse_in); 1474132718Skan } 1475132718Skan } 1476132718Skan } 1477259405Spfg else if (cpp_opts->directives_only) 1478259405Spfg cpp_init_special_builtins (parse_in); 1479132718Skan 1480132718Skan include_cursor = 0; 1481132718Skan push_command_line_include (); 1482132718Skan} 1483132718Skan 1484132718Skan/* Give CPP the next file given by -include, if any. */ 1485132718Skanstatic void 1486132718Skanpush_command_line_include (void) 1487132718Skan{ 1488132718Skan while (include_cursor < deferred_count) 1489132718Skan { 1490132718Skan struct deferred_opt *opt = &deferred_opts[include_cursor++]; 1491132718Skan 1492169699Skan if (!cpp_opts->preprocessed && opt->code == OPT_include 1493132718Skan && cpp_push_include (parse_in, opt->arg)) 1494132718Skan return; 1495132718Skan } 1496132718Skan 1497132718Skan if (include_cursor == deferred_count) 1498132718Skan { 1499132718Skan include_cursor++; 1500132718Skan /* -Wunused-macros should only warn about macros defined hereafter. */ 1501132718Skan cpp_opts->warn_unused_macros = warn_unused_macros; 1502132718Skan /* Restore the line map from <command line>. */ 1503169699Skan if (!cpp_opts->preprocessed) 1504169699Skan cpp_change_file (parse_in, LC_RENAME, this_input_filename); 1505132718Skan 1506132718Skan /* Set this here so the client can change the option if it wishes, 1507132718Skan and after stacking the main file so we don't trace the main file. */ 1508169699Skan line_table.trace_includes = cpp_opts->print_include_names; 1509132718Skan } 1510132718Skan} 1511132718Skan 1512132718Skan/* File change callback. Has to handle -include files. */ 1513132718Skanstatic void 1514169699Skancb_file_change (cpp_reader * ARG_UNUSED (pfile), 1515132718Skan const struct line_map *new_map) 1516132718Skan{ 1517132718Skan if (flag_preprocess_only) 1518132718Skan pp_file_change (new_map); 1519132718Skan else 1520132718Skan fe_file_change (new_map); 1521132718Skan 1522132718Skan if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))) 1523132718Skan push_command_line_include (); 1524132718Skan} 1525132718Skan 1526132718Skanvoid 1527169699Skancb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir) 1528132718Skan{ 1529169699Skan if (!set_src_pwd (dir)) 1530169699Skan warning (0, "too late for # directive to set debug directory"); 1531132718Skan} 1532132718Skan 1533117395Skan/* Set the C 89 standard (with 1994 amendments if C94, without GNU 1534117395Skan extensions if ISO). There is no concept of gnu94. */ 1535117395Skanstatic void 1536132718Skanset_std_c89 (int c94, int iso) 1537117395Skan{ 1538117395Skan cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89); 1539117395Skan flag_iso = iso; 1540117395Skan flag_no_asm = iso; 1541117395Skan flag_no_gnu_keywords = iso; 1542117395Skan flag_no_nonansi_builtin = iso; 1543117395Skan flag_isoc94 = c94; 1544117395Skan flag_isoc99 = 0; 1545117395Skan} 1546117395Skan 1547117395Skan/* Set the C 99 standard (without GNU extensions if ISO). */ 1548117395Skanstatic void 1549132718Skanset_std_c99 (int iso) 1550117395Skan{ 1551117395Skan cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99); 1552117395Skan flag_no_asm = iso; 1553117395Skan flag_no_nonansi_builtin = iso; 1554117395Skan flag_iso = iso; 1555117395Skan flag_isoc99 = 1; 1556117395Skan flag_isoc94 = 1; 1557117395Skan} 1558117395Skan 1559117395Skan/* Set the C++ 98 standard (without GNU extensions if ISO). */ 1560117395Skanstatic void 1561132718Skanset_std_cxx98 (int iso) 1562117395Skan{ 1563117395Skan cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX); 1564117395Skan flag_no_gnu_keywords = iso; 1565117395Skan flag_no_nonansi_builtin = iso; 1566117395Skan flag_iso = iso; 1567117395Skan} 1568117395Skan 1569117395Skan/* Handle setting implicit to ON. */ 1570117395Skanstatic void 1571132718Skanset_Wimplicit (int on) 1572117395Skan{ 1573117395Skan warn_implicit = on; 1574117395Skan warn_implicit_int = on; 1575117395Skan if (on) 1576117395Skan { 1577117395Skan if (mesg_implicit_function_declaration != 2) 1578117395Skan mesg_implicit_function_declaration = 1; 1579117395Skan } 1580117395Skan else 1581117395Skan mesg_implicit_function_declaration = 0; 1582117395Skan} 1583117395Skan 1584117395Skan/* Args to -d specify what to dump. Silently ignore 1585117395Skan unrecognized options; they may be aimed at toplev.c. */ 1586117395Skanstatic void 1587132718Skanhandle_OPT_d (const char *arg) 1588117395Skan{ 1589117395Skan char c; 1590117395Skan 1591117395Skan while ((c = *arg++) != '\0') 1592117395Skan switch (c) 1593117395Skan { 1594132718Skan case 'M': /* Dump macros only. */ 1595132718Skan case 'N': /* Dump names. */ 1596132718Skan case 'D': /* Dump definitions. */ 1597132718Skan flag_dump_macros = c; 1598117395Skan break; 1599117395Skan 1600117395Skan case 'I': 1601132718Skan flag_dump_includes = 1; 1602117395Skan break; 1603117395Skan } 1604117395Skan} 1605