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