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