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