]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/opts.c
c-common.c (flag_abi_version): Default to 2.
[thirdparty/gcc.git] / gcc / opts.c
CommitLineData
2772ef3e
NB
1/* Command line option handling.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
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
9Software Foundation; either version 2, or (at your option) any later
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
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
cf03fd63 24#include "intl.h"
2772ef3e
NB
25#include "coretypes.h"
26#include "tm.h"
27#include "tree.h"
058de654
NB
28#include "rtl.h"
29#include "ggc.h"
30#include "output.h"
2772ef3e
NB
31#include "langhooks.h"
32#include "opts.h"
d7b42618
NB
33#include "options.h"
34#include "flags.h"
35#include "toplev.h"
903caebf 36#include "params.h"
de32c0cb 37#include "diagnostic.h"
9756310a 38#include "tm_p.h" /* For OPTIMIZATION_OPTIONS. */
d6553b54 39#include "insn-attr.h" /* For INSN_SCHEDULING. */
2772ef3e 40
d185d268
NB
41/* Value of the -G xx switch, and whether it was passed or not. */
42unsigned HOST_WIDE_INT g_switch_value;
43bool g_switch_set;
44
45/* True if we should exit after parsing options. */
46bool exit_after_options;
47
48/* If -version. */
49bool version_flag;
50
e01cc6dc
NB
51/* Print various extra warnings. -W/-Wextra. */
52bool extra_warnings;
53
54/* Don't print warning messages. -w. */
55bool inhibit_warnings;
56
57/* Treat warnings as errors. -Werror. */
58bool warnings_are_errors;
59
60/* Warn if a function returns an aggregate, since there are often
61 incompatible calling conventions for doing this. */
62bool warn_aggregate_return;
63
64/* Nonzero means warn about pointer casts that increase the required
65 alignment of the target type (and might therefore lead to a crash
66 due to a misaligned access). */
67bool warn_cast_align;
68
69/* Nonzero means warn about uses of __attribute__((deprecated))
70 declarations. */
71bool warn_deprecated_decl = true;
72
73/* Warn when an optimization pass is disabled. */
74bool warn_disabled_optimization;
75
76/* Nonzero means warn if inline function is too large. */
77bool warn_inline;
78
79/* True to warn about any objects definitions whose size is larger
80 than N bytes. Also want about function definitions whose returned
81 values are larger than N bytes, where N is `larger_than_size'. */
82bool warn_larger_than;
83HOST_WIDE_INT larger_than_size;
84
85/* Warn about functions which might be candidates for attribute noreturn. */
86bool warn_missing_noreturn;
87
88/* True to warn about code which is never reached. */
89bool warn_notreached;
90
91/* Warn if packed attribute on struct is unnecessary and inefficient. */
92bool warn_packed;
93
94/* Warn when gcc pads a structure to an alignment boundary. */
95bool warn_padded;
96
97/* True means warn about all declarations which shadow others. */
98bool warn_shadow;
99
100/* Nonzero means warn about constructs which might not be
101 strict-aliasing safe. */
102bool warn_strict_aliasing;
103
104/* True to warn if a switch on an enum, that does not have a default
105 case, fails to have a case for every enum value. */
106bool warn_switch;
107
108/* Warn if a switch does not have a default case. */
109bool warn_switch_default;
110
111/* Warn if a switch on an enum fails to have a case for every enum
112 value (regardless of the presence or otherwise of a default case). */
113bool warn_switch_enum;
114
115/* Don't suppress warnings from system headers. -Wsystem-headers. */
116bool warn_system_headers;
117
118/* True to warn about variables used before they are initialized. */
119int warn_uninitialized;
120
121/* True to warn about unused variables, functions et.al. */
122bool warn_unused_function;
123bool warn_unused_label;
124bool warn_unused_parameter;
125bool warn_unused_variable;
126bool warn_unused_value;
127
903caebf
NB
128/* Hack for cooperation between set_Wunused and set_Wextra. */
129static bool maybe_warn_unused_parameter;
130
df38ffef
NB
131/* Type(s) of debugging information we are producing (if any). See
132 flags.h for the definitions of the different possible types of
133 debugging information. */
134enum debug_info_type write_symbols = NO_DEBUG;
135
136/* Level of debugging information we are producing. See flags.h for
137 the definitions of the different possible levels. */
138enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
139
140/* Nonzero means use GNU-only extensions in the generated symbolic
141 debugging information. Currently, this only has an effect when
142 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
143bool use_gnu_debug_info_extensions;
144
2cc98056
NB
145/* Columns of --help display. */
146static unsigned int columns = 80;
147
148/* What to print when a switch has no documentation. */
149static const char undocumented_msg[] = N_("This switch lacks documentation");
150
59e4e217 151/* Input file names. */
40e941af
PB
152const char **in_fnames;
153unsigned num_in_fnames;
154
35399bdc 155static size_t find_opt (const char *, int);
d7b42618 156static int common_handle_option (size_t scode, const char *arg, int value);
903caebf
NB
157static void handle_param (const char *);
158static void set_Wextra (int);
b86f6cd9 159static unsigned int handle_option (const char **argv, unsigned int lang_mask);
f18754d6
NB
160static char *write_langs (unsigned int lang_mask);
161static void complain_wrong_lang (const char *, const struct cl_option *,
162 unsigned int lang_mask);
b86f6cd9 163static void handle_options (unsigned int, const char **, unsigned int);
2cc98056 164static void wrap_help (const char *help, const char *item, unsigned int);
cf03fd63 165static void print_help (void);
2cc98056 166static void print_param_help (void);
72de27ea 167static void print_filtered_help (unsigned int flag);
2cc98056 168static unsigned int print_switch (const char *text, unsigned int indent);
df38ffef
NB
169static void set_debug_level (enum debug_info_type type, int extended,
170 const char *arg);
2772ef3e
NB
171
172/* Perform a binary search to find which option the command-line INPUT
9cd23ed2
NB
173 matches. Returns its index in the option array, and N_OPTS
174 (cl_options_count) on failure.
175
176 This routine is quite subtle. A normal binary search is not good
177 enough because some options can be suffixed with an argument, and
178 multiple sub-matches can occur, e.g. input of "-pedantic" matching
179 the initial substring of "-pedantic-errors".
180
181 A more complicated example is -gstabs. It should match "-g" with
182 an argument of "stabs". Suppose, however, that the number and list
183 of switches are such that the binary search tests "-gen-decls"
184 before having tested "-g". This doesn't match, and as "-gen-decls"
185 is less than "-gstabs", it will become the lower bound of the
186 binary search range, and "-g" will never be seen. To resolve this
187 issue, opts.sh makes "-gen-decls" point, via the back_chain member,
188 to "-g" so that failed searches that end between "-gen-decls" and
189 the lexicographically subsequent switch know to go back and see if
190 "-g" causes a match (which it does in this example).
191
192 This search is done in such a way that the longest match for the
193 front end in question wins. If there is no match for the current
194 front end, the longest match for a different front end is returned
195 (or N_OPTS if none) and the caller emits an error message. */
35399bdc 196static size_t
2772ef3e
NB
197find_opt (const char *input, int lang_mask)
198{
9cd23ed2
NB
199 size_t mn, mx, md, opt_len;
200 size_t match_wrong_lang;
2772ef3e
NB
201 int comp;
202
203 mn = 0;
35399bdc 204 mx = cl_options_count;
2772ef3e 205
9cd23ed2
NB
206 /* Find mn such this lexicographical inequality holds:
207 cl_options[mn] <= input < cl_options[mn + 1]. */
208 while (mx - mn > 1)
2772ef3e
NB
209 {
210 md = (mn + mx) / 2;
2772ef3e 211 opt_len = cl_options[md].opt_len;
cf03fd63 212 comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
2772ef3e
NB
213
214 if (comp < 0)
215 mx = md;
2772ef3e 216 else
9cd23ed2
NB
217 mn = md;
218 }
219
220 /* This is the switch that is the best match but for a different
221 front end, or cl_options_count if there is no match at all. */
222 match_wrong_lang = cl_options_count;
223
224 /* Backtrace the chain of possible matches, returning the longest
225 one, if any, that fits best. With current GCC switches, this
226 loop executes at most twice. */
227 do
228 {
229 const struct cl_option *opt = &cl_options[mn];
230
231 /* Is this switch a prefix of the input? */
cf03fd63 232 if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
2772ef3e 233 {
9cd23ed2
NB
234 /* If language is OK, and the match is exact or the switch
235 takes a joined argument, return it. */
236 if ((opt->flags & lang_mask)
237 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
238 return mn;
239
240 /* If we haven't remembered a prior match, remember this
241 one. Any prior match is necessarily better. */
f18754d6 242 if (match_wrong_lang == cl_options_count)
9cd23ed2 243 match_wrong_lang = mn;
2772ef3e 244 }
9cd23ed2
NB
245
246 /* Try the next possibility. This is cl_options_count if there
247 are no more. */
248 mn = opt->back_chain;
2772ef3e 249 }
9cd23ed2 250 while (mn != cl_options_count);
2772ef3e 251
9cd23ed2
NB
252 /* Return the best wrong match, or cl_options_count if none. */
253 return match_wrong_lang;
2772ef3e
NB
254}
255
e01cc6dc 256/* If ARG is a non-negative integer made up solely of digits, return its
7b086b11
NB
257 value, otherwise return -1. */
258static int
259integral_argument (const char *arg)
260{
261 const char *p = arg;
262
263 while (*p && ISDIGIT (*p))
264 p++;
265
266 if (*p == '\0')
267 return atoi (arg);
268
269 return -1;
270}
271
f18754d6
NB
272/* Return a malloced slash-separated list of languages in MASK. */
273static char *
274write_langs (unsigned int mask)
275{
276 unsigned int n = 0, len = 0;
277 const char *lang_name;
278 char *result;
279
280 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
281 if (mask & (1U << n))
282 len += strlen (lang_name) + 1;
283
284 result = xmalloc (len);
285 len = 0;
286 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
287 if (mask & (1U << n))
288 {
289 if (len)
290 result[len++] = '/';
291 strcpy (result + len, lang_name);
292 len += strlen (lang_name);
293 }
294
295 result[len] = 0;
296
297 return result;
298}
299
300/* Complain that switch OPT_INDEX does not apply to this front end. */
301static void
302complain_wrong_lang (const char *text, const struct cl_option *option,
303 unsigned int lang_mask)
304{
305 char *ok_langs, *bad_lang;
306
307 ok_langs = write_langs (option->flags);
308 bad_lang = write_langs (lang_mask);
309
310 /* Eventually this should become a hard error IMO. */
311 warning ("command line option \"%s\" is valid for %s but not for %s",
312 text, ok_langs, bad_lang);
313
314 free (ok_langs);
315 free (bad_lang);
316}
317
318/* Handle the switch beginning at ARGV for the language indicated by
319 LANG_MASK. Returns the number of switches consumed. */
320static unsigned int
b86f6cd9 321handle_option (const char **argv, unsigned int lang_mask)
2772ef3e
NB
322{
323 size_t opt_index;
324 const char *opt, *arg = 0;
325 char *dup = 0;
7b086b11 326 int value = 1;
f18754d6 327 unsigned int result = 0;
2772ef3e
NB
328 const struct cl_option *option;
329
2772ef3e
NB
330 opt = argv[0];
331
cb66e385
NB
332 /* Drop the "no-" from negative switches. */
333 if ((opt[1] == 'W' || opt[1] == 'f')
334 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
2772ef3e 335 {
cb66e385
NB
336 size_t len = strlen (opt) - 3;
337
338 dup = xmalloc (len + 1);
339 dup[0] = '-';
340 dup[1] = opt[1];
341 memcpy (dup + 2, opt + 5, len - 2 + 1);
342 opt = dup;
343 value = 0;
2772ef3e 344 }
2772ef3e 345
cb66e385
NB
346 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
347 if (opt_index == cl_options_count)
348 goto done;
2772ef3e 349
cb66e385 350 option = &cl_options[opt_index];
2772ef3e 351
cb66e385
NB
352 /* Reject negative form of switches that don't take negatives as
353 unrecognized. */
354 if (!value && (option->flags & CL_REJECT_NEGATIVE))
355 goto done;
2772ef3e 356
cb66e385
NB
357 /* We've recognized this switch. */
358 result = 1;
2772ef3e 359
cb66e385
NB
360 /* Sort out any argument the switch takes. */
361 if (option->flags & CL_JOINED)
362 {
363 /* Have arg point to the original switch. This is because
364 some code, such as disable_builtin_function, expects its
365 argument to be persistent until the program exits. */
366 arg = argv[0] + cl_options[opt_index].opt_len + 1;
367 if (!value)
368 arg += strlen ("no-");
369
370 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
2772ef3e 371 {
cb66e385 372 if (option->flags & CL_SEPARATE)
2772ef3e 373 {
cb66e385
NB
374 arg = argv[1];
375 result = 2;
2772ef3e 376 }
cb66e385
NB
377 else
378 /* Missing argument. */
379 arg = NULL;
7b086b11 380 }
cb66e385
NB
381 }
382 else if (option->flags & CL_SEPARATE)
383 {
384 arg = argv[1];
385 result = 2;
386 }
2772ef3e 387
cb66e385
NB
388 /* Now we've swallowed any potential argument, complain if this
389 is a switch for a different front end. */
390 if (!(option->flags & (lang_mask | CL_COMMON)))
391 {
392 complain_wrong_lang (argv[0], option, lang_mask);
393 goto done;
394 }
f18754d6 395
cb66e385
NB
396 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
397 {
398 if (!(*lang_hooks.missing_argument) (opt, opt_index))
399 error ("missing argument to \"%s\"", opt);
400 goto done;
401 }
9eee5e72 402
cb66e385
NB
403 /* If the switch takes an integer, convert it. */
404 if (arg && (option->flags & CL_UINTEGER))
405 {
406 value = integral_argument (arg);
407 if (value == -1)
7b086b11 408 {
cf03fd63 409 error ("argument to \"%s\" should be a non-negative integer",
cb66e385
NB
410 option->opt_text);
411 goto done;
2772ef3e 412 }
cb66e385 413 }
2772ef3e 414
cb66e385
NB
415 if (option->flags & lang_mask)
416 if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
417 result = 0;
d7b42618 418
cb66e385
NB
419 if (result && (option->flags & CL_COMMON))
420 if (common_handle_option (opt_index, arg, value) == 0)
421 result = 0;
2772ef3e
NB
422
423 done:
424 if (dup)
425 free (dup);
426 return result;
427}
d7b42618 428
f18754d6
NB
429/* Decode and handle the vector of command line options. LANG_MASK
430 contains has a single bit set representing the current
431 language. */
9756310a 432static void
b86f6cd9 433handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
f18754d6
NB
434{
435 unsigned int n, i;
436
437 for (i = 1; i < argc; i += n)
438 {
cb66e385
NB
439 const char *opt = argv[i];
440
441 /* Interpret "-" or a non-switch as a file name. */
442 if (opt[0] != '-' || opt[1] == '\0')
443 {
444 main_input_filename = opt;
40e941af 445 add_input_filename (opt);
cb66e385
NB
446 n = 1;
447 continue;
448 }
449
f18754d6
NB
450 n = handle_option (argv + i, lang_mask);
451
452 if (!n)
453 {
454 n = 1;
cb66e385 455 error ("unrecognized command line option \"%s\"", opt);
f18754d6
NB
456 }
457 }
458}
459
40e941af
PB
460/* Handle FILENAME from the command line. */
461void
462add_input_filename (const char *filename)
463{
464 num_in_fnames++;
465 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
466 in_fnames[num_in_fnames - 1] = filename;
467}
468
9756310a
NB
469/* Parse command line options and set default flag values. Do minimal
470 options processing. */
471void
b86f6cd9 472decode_options (unsigned int argc, const char **argv)
9756310a 473{
b86f6cd9 474 unsigned int i, lang_mask;
9756310a
NB
475
476 /* Perform language-specific options initialization. */
b86f6cd9 477 lang_mask = (*lang_hooks.init_options) (argc, argv);
9756310a 478
21ecc5a7
GDR
479 lang_hooks.initialize_diagnostics (global_dc);
480
9756310a
NB
481 /* Scan to see what optimization level has been specified. That will
482 determine the default value of many flags. */
483 for (i = 1; i < argc; i++)
484 {
485 if (!strcmp (argv[i], "-O"))
486 {
487 optimize = 1;
488 optimize_size = 0;
489 }
490 else if (argv[i][0] == '-' && argv[i][1] == 'O')
491 {
492 /* Handle -Os, -O2, -O3, -O69, ... */
b86f6cd9 493 const char *p = &argv[i][2];
9756310a
NB
494
495 if ((p[0] == 's') && (p[1] == 0))
496 {
497 optimize_size = 1;
498
499 /* Optimizing for size forces optimize to be 2. */
500 optimize = 2;
501 }
502 else
503 {
504 const int optimize_val = read_integral_parameter (p, p - 2, -1);
505 if (optimize_val != -1)
506 {
507 optimize = optimize_val;
508 optimize_size = 0;
509 }
510 }
511 }
512 }
513
514 if (!optimize)
515 {
516 flag_merge_constants = 0;
517 }
518
519 if (optimize >= 1)
520 {
521 flag_defer_pop = 1;
522 flag_thread_jumps = 1;
523#ifdef DELAY_SLOTS
524 flag_delayed_branch = 1;
525#endif
526#ifdef CAN_DEBUG_WITHOUT_FP
527 flag_omit_frame_pointer = 1;
528#endif
529 flag_guess_branch_prob = 1;
530 flag_cprop_registers = 1;
531 flag_loop_optimize = 1;
532 flag_crossjumping = 1;
533 flag_if_conversion = 1;
534 flag_if_conversion2 = 1;
535 }
536
537 if (optimize >= 2)
538 {
539 flag_optimize_sibling_calls = 1;
540 flag_cse_follow_jumps = 1;
541 flag_cse_skip_blocks = 1;
542 flag_gcse = 1;
543 flag_expensive_optimizations = 1;
544 flag_strength_reduce = 1;
545 flag_rerun_cse_after_loop = 1;
546 flag_rerun_loop_opt = 1;
547 flag_caller_saves = 1;
548 flag_force_mem = 1;
549 flag_peephole2 = 1;
550#ifdef INSN_SCHEDULING
551 flag_schedule_insns = 1;
552 flag_schedule_insns_after_reload = 1;
553#endif
554 flag_regmove = 1;
555 flag_strict_aliasing = 1;
556 flag_delete_null_pointer_checks = 1;
557 flag_reorder_blocks = 1;
558 flag_reorder_functions = 1;
1f95c733 559 flag_unit_at_a_time = 1;
9756310a
NB
560 }
561
562 if (optimize >= 3)
563 {
564 flag_inline_functions = 1;
565 flag_rename_registers = 1;
566 flag_unswitch_loops = 1;
62551c66 567 flag_web = 1;
9756310a
NB
568 }
569
570 if (optimize < 2 || optimize_size)
571 {
572 align_loops = 1;
573 align_jumps = 1;
574 align_labels = 1;
575 align_functions = 1;
576
577 /* Don't reorder blocks when optimizing for size because extra
578 jump insns may be created; also barrier may create extra padding.
579
580 More correctly we should have a block reordering mode that tried
581 to minimize the combined size of all the jumps. This would more
582 or less automatically remove extra jumps, but would also try to
583 use more short jumps instead of long jumps. */
584 flag_reorder_blocks = 0;
585 }
586
587 /* Initialize whether `char' is signed. */
588 flag_signed_char = DEFAULT_SIGNED_CHAR;
589#ifdef DEFAULT_SHORT_ENUMS
590 /* Initialize how much space enums occupy, by default. */
591 flag_short_enums = DEFAULT_SHORT_ENUMS;
592#endif
593
594 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
595 modify it. */
596 target_flags = 0;
597 set_target_switch ("");
598
599 /* Unwind tables are always present in an ABI-conformant IA-64
600 object file, so the default should be ON. */
601#ifdef IA64_UNWIND_INFO
602 flag_unwind_tables = IA64_UNWIND_INFO;
603#endif
604
605#ifdef OPTIMIZATION_OPTIONS
606 /* Allow default optimizations to be specified on a per-machine basis. */
607 OPTIMIZATION_OPTIONS (optimize, optimize_size);
608#endif
609
610 handle_options (argc, argv, lang_mask);
611
612 if (flag_pie)
613 flag_pic = flag_pie;
614 if (flag_pic && !flag_pie)
615 flag_shlib = 1;
616
617 if (flag_no_inline == 2)
618 flag_no_inline = 0;
619 else
620 flag_really_no_inline = flag_no_inline;
621
622 /* Set flag_no_inline before the post_options () hook. The C front
623 ends use it to determine tree inlining defaults. FIXME: such
624 code should be lang-independent when all front ends use tree
625 inlining, in which case it, and this condition, should be moved
626 to the top of process_options() instead. */
627 if (optimize == 0)
628 {
629 /* Inlining does not work if not optimizing,
630 so force it not to be done. */
631 flag_no_inline = 1;
632 warn_inline = 0;
633
634 /* The c_decode_option function and decode_option hook set
635 this to `2' if -Wall is used, so we can avoid giving out
636 lots of errors for people who don't realize what -Wall does. */
637 if (warn_uninitialized == 1)
638 warning ("-Wuninitialized is not supported without -O");
639 }
640
641 if (flag_really_no_inline == 2)
642 flag_really_no_inline = flag_no_inline;
643}
644
d7b42618
NB
645/* Handle target- and language-independent options. Return zero to
646 generate an "unknown option" message. */
647static int
648common_handle_option (size_t scode, const char *arg,
649 int value ATTRIBUTE_UNUSED)
650{
d7b42618
NB
651 enum opt_code code = (enum opt_code) scode;
652
d7b42618
NB
653 switch (code)
654 {
655 default:
656 abort ();
657
d185d268 658 case OPT__help:
cf03fd63 659 print_help ();
d185d268
NB
660 exit_after_options = true;
661 break;
662
903caebf
NB
663 case OPT__param:
664 handle_param (arg);
665 break;
666
d185d268
NB
667 case OPT__target_help:
668 display_target_options ();
669 exit_after_options = true;
670 break;
671
672 case OPT__version:
673 print_version (stderr, "");
674 exit_after_options = true;
675 break;
676
677 case OPT_G:
7b086b11 678 g_switch_value = value;
d185d268
NB
679 g_switch_set = true;
680 break;
681
903caebf
NB
682 case OPT_O:
683 case OPT_Os:
684 /* Currently handled in a prescan. */
685 break;
686
687 case OPT_W:
688 /* For backward compatibility, -W is the same as -Wextra. */
689 set_Wextra (value);
690 break;
691
e01cc6dc
NB
692 case OPT_Waggregate_return:
693 warn_aggregate_return = value;
694 break;
695
696 case OPT_Wcast_align:
697 warn_cast_align = value;
698 break;
699
700 case OPT_Wdeprecated_declarations:
701 warn_deprecated_decl = value;
0bd95603 702 break;
e01cc6dc
NB
703
704 case OPT_Wdisabled_optimization:
705 warn_disabled_optimization = value;
706 break;
707
708 case OPT_Werror:
709 warnings_are_errors = value;
710 break;
711
903caebf
NB
712 case OPT_Wextra:
713 set_Wextra (value);
714 break;
715
e01cc6dc
NB
716 case OPT_Winline:
717 warn_inline = value;
718 break;
719
720 case OPT_Wlarger_than_:
721 larger_than_size = value;
722 warn_larger_than = value != -1;
723 break;
724
725 case OPT_Wmissing_noreturn:
726 warn_missing_noreturn = value;
727 break;
728
729 case OPT_Wpacked:
730 warn_packed = value;
731 break;
732
733 case OPT_Wpadded:
734 warn_padded = value;
735 break;
736
737 case OPT_Wshadow:
738 warn_shadow = value;
739 break;
740
741 case OPT_Wstrict_aliasing:
742 warn_strict_aliasing = value;
743 break;
744
745 case OPT_Wswitch:
746 warn_switch = value;
747 break;
748
749 case OPT_Wswitch_default:
750 warn_switch_default = value;
751 break;
752
753 case OPT_Wswitch_enum:
754 warn_switch_enum = value;
755 break;
756
757 case OPT_Wsystem_headers:
758 warn_system_headers = value;
759 break;
760
761 case OPT_Wuninitialized:
762 warn_uninitialized = value;
763 break;
764
765 case OPT_Wunreachable_code:
766 warn_notreached = value;
767 break;
768
903caebf
NB
769 case OPT_Wunused:
770 set_Wunused (value);
771 break;
772
e01cc6dc
NB
773 case OPT_Wunused_function:
774 warn_unused_function = value;
775 break;
776
777 case OPT_Wunused_label:
778 warn_unused_label = value;
779 break;
780
781 case OPT_Wunused_parameter:
782 warn_unused_parameter = value;
783 break;
784
785 case OPT_Wunused_value:
786 warn_unused_value = value;
787 break;
788
789 case OPT_Wunused_variable:
790 warn_unused_variable = value;
791 break;
792
d185d268
NB
793 case OPT_aux_info:
794 case OPT_aux_info_:
795 aux_info_file_name = arg;
796 flag_gen_aux_info = 1;
797 break;
798
799 case OPT_auxbase:
800 aux_base_name = arg;
801 break;
802
803 case OPT_auxbase_strip:
804 {
805 char *tmp = xstrdup (arg);
806 strip_off_ending (tmp, strlen (tmp));
807 if (tmp[0])
808 aux_base_name = tmp;
809 }
810 break;
811
812 case OPT_d:
813 decode_d_option (arg);
814 break;
815
816 case OPT_dumpbase:
817 dump_base_name = arg;
818 break;
819
6ff3a151
NB
820 case OPT_fPIC:
821 flag_pic = value + value;
822 break;
823
824 case OPT_fPIE:
825 flag_pie = value + value;
826 break;
827
828 case OPT_falign_functions:
5e14ae7e 829 align_functions = !value;
058de654
NB
830 break;
831
0fcd5dda
NB
832 case OPT_falign_functions_:
833 align_functions = value;
834 break;
835
6ff3a151 836 case OPT_falign_jumps:
5e14ae7e 837 align_jumps = !value;
058de654
NB
838 break;
839
0fcd5dda
NB
840 case OPT_falign_jumps_:
841 align_jumps = value;
842 break;
843
6ff3a151 844 case OPT_falign_labels:
5e14ae7e 845 align_labels = !value;
058de654
NB
846 break;
847
0fcd5dda
NB
848 case OPT_falign_labels_:
849 align_labels = value;
850 break;
851
6ff3a151 852 case OPT_falign_loops:
5e14ae7e 853 align_loops = !value;
058de654
NB
854 break;
855
0fcd5dda
NB
856 case OPT_falign_loops_:
857 align_loops = value;
858 break;
859
6ff3a151
NB
860 case OPT_fargument_alias:
861 flag_argument_noalias = !value;
862 break;
863
864 case OPT_fargument_noalias:
865 flag_argument_noalias = value;
866 break;
867
868 case OPT_fargument_noalias_global:
869 flag_argument_noalias = value + value;
870 break;
871
872 case OPT_fasynchronous_unwind_tables:
873 flag_asynchronous_unwind_tables = value;
874 break;
875
876 case OPT_fbounds_check:
877 flag_bounds_check = value;
878 break;
879
880 case OPT_fbranch_count_reg:
881 flag_branch_on_count_reg = value;
882 break;
883
884 case OPT_fbranch_probabilities:
885 flag_branch_probabilities = value;
886 break;
887
de32c0cb
NB
888 case OPT_fbranch_target_load_optimize:
889 flag_branch_target_load_optimize = value;
890 break;
891
892 case OPT_fbranch_target_load_optimize2:
893 flag_branch_target_load_optimize2 = value;
894 break;
895
058de654
NB
896 case OPT_fcall_used_:
897 fix_register (arg, 0, 1);
898 break;
899
900 case OPT_fcall_saved_:
901 fix_register (arg, 0, 0);
902 break;
903
de32c0cb
NB
904 case OPT_fcaller_saves:
905 flag_caller_saves = value;
906 break;
907
6ff3a151
NB
908 case OPT_fcommon:
909 flag_no_common = !value;
910 break;
911
912 case OPT_fcprop_registers:
913 flag_cprop_registers = value;
914 break;
915
de32c0cb
NB
916 case OPT_fcrossjumping:
917 flag_crossjumping = value;
918 break;
919
920 case OPT_fcse_follow_jumps:
921 flag_cse_follow_jumps = value;
922 break;
923
924 case OPT_fcse_skip_blocks:
925 flag_cse_skip_blocks = value;
926 break;
927
6ff3a151
NB
928 case OPT_fdata_sections:
929 flag_data_sections = value;
930 break;
931
de32c0cb
NB
932 case OPT_fdefer_pop:
933 flag_defer_pop = value;
934 break;
935
936 case OPT_fdelayed_branch:
937 flag_delayed_branch = value;
938 break;
939
940 case OPT_fdelete_null_pointer_checks:
941 flag_delete_null_pointer_checks = value;
942 break;
943
944 case OPT_fdiagnostics_show_location_:
945 if (!strcmp (arg, "once"))
946 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
947 else if (!strcmp (arg, "every-line"))
948 diagnostic_prefixing_rule (global_dc)
949 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
950 else
951 return 0;
952 break;
953
6ff3a151
NB
954 case OPT_fdump_unnumbered:
955 flag_dump_unnumbered = value;
956 break;
957
de32c0cb
NB
958 case OPT_feliminate_dwarf2_dups:
959 flag_eliminate_dwarf2_dups = value;
960 break;
961
962 case OPT_feliminate_unused_debug_types:
963 flag_eliminate_unused_debug_types = value;
964 break;
965
6a08f7b3
DP
966 case OPT_feliminate_unused_debug_symbols:
967 flag_debug_only_used_symbols = value;
968 break;
969
6ff3a151
NB
970 case OPT_fexceptions:
971 flag_exceptions = value;
972 break;
973
de32c0cb
NB
974 case OPT_fexpensive_optimizations:
975 flag_expensive_optimizations = value;
976 break;
977
058de654
NB
978 case OPT_ffast_math:
979 set_fast_math_flags (value);
980 break;
981
6ff3a151
NB
982 case OPT_ffinite_math_only:
983 flag_finite_math_only = value;
984 break;
985
058de654
NB
986 case OPT_ffixed_:
987 fix_register (arg, 1, 1);
988 break;
989
de32c0cb
NB
990 case OPT_ffunction_cse:
991 flag_no_function_cse = !value;
992 break;
993
994 case OPT_ffloat_store:
995 flag_float_store = value;
996 break;
997
998 case OPT_fforce_addr:
999 flag_force_addr = value;
1000 break;
1001
1002 case OPT_fforce_mem:
1003 flag_force_mem = value;
1004 break;
1005
6ff3a151
NB
1006 case OPT_ffunction_sections:
1007 flag_function_sections = value;
1008 break;
1009
de32c0cb
NB
1010 case OPT_fgcse:
1011 flag_gcse = value;
1012 break;
1013
1014 case OPT_fgcse_lm:
1015 flag_gcse_lm = value;
1016 break;
1017
1018 case OPT_fgcse_sm:
1019 flag_gcse_sm = value;
1020 break;
1021
f5f2e3cd
MH
1022 case OPT_fgcse_las:
1023 flag_gcse_las = value;
1024 break;
1025
6ff3a151
NB
1026 case OPT_fguess_branch_probability:
1027 flag_guess_branch_prob = value;
1028 break;
1029
1030 case OPT_fident:
1031 flag_no_ident = !value;
1032 break;
1033
de32c0cb
NB
1034 case OPT_fif_conversion:
1035 flag_if_conversion = value;
1036 break;
1037
1038 case OPT_fif_conversion2:
1039 flag_if_conversion2 = value;
1040 break;
1041
6ff3a151
NB
1042 case OPT_finhibit_size_directive:
1043 flag_inhibit_size_directive = value;
1044 break;
1045
de32c0cb
NB
1046 case OPT_finline:
1047 flag_no_inline = !value;
1048 break;
1049
1050 case OPT_finline_functions:
1051 flag_inline_functions = value;
1052 break;
1053
d302c9d6
NB
1054 case OPT_finline_limit_:
1055 case OPT_finline_limit_eq:
d302c9d6
NB
1056 set_param_value ("max-inline-insns-single", value / 2);
1057 set_param_value ("max-inline-insns-auto", value / 2);
1058 set_param_value ("max-inline-insns-rtl", value);
d302c9d6
NB
1059 break;
1060
6ff3a151
NB
1061 case OPT_finstrument_functions:
1062 flag_instrument_function_entry_exit = value;
1063 break;
1064
de32c0cb
NB
1065 case OPT_fkeep_inline_functions:
1066 flag_keep_inline_functions =value;
1067 break;
1068
1069 case OPT_fkeep_static_consts:
1070 flag_keep_static_consts = value;
1071 break;
1072
6ff3a151
NB
1073 case OPT_fleading_underscore:
1074 flag_leading_underscore = value;
1075 break;
1076
de32c0cb
NB
1077 case OPT_floop_optimize:
1078 flag_loop_optimize = value;
1079 break;
1080
6ff3a151
NB
1081 case OPT_fmath_errno:
1082 flag_errno_math = value;
1083 break;
1084
1085 case OPT_fmem_report:
1086 mem_report = value;
1087 break;
1088
1089 case OPT_fmerge_all_constants:
1090 flag_merge_constants = value + value;
1091 break;
1092
1093 case OPT_fmerge_constants:
1094 flag_merge_constants = value;
1095 break;
1096
de32c0cb 1097 case OPT_fmessage_length_:
b6fe0bb8 1098 pp_set_line_maximum_length (global_dc->printer, value);
de32c0cb
NB
1099 break;
1100
1101 case OPT_fmove_all_movables:
1102 flag_move_all_movables = value;
1103 break;
1104
6ff3a151
NB
1105 case OPT_fnew_ra:
1106 flag_new_regalloc = value;
1107 break;
1108
1109 case OPT_fnon_call_exceptions:
1110 flag_non_call_exceptions = value;
1111 break;
1112
de32c0cb
NB
1113 case OPT_fold_unroll_all_loops:
1114 flag_old_unroll_all_loops = value;
1115 break;
1116
1117 case OPT_fold_unroll_loops:
1118 flag_old_unroll_loops = value;
1119 break;
1120
1121 case OPT_fomit_frame_pointer:
1122 flag_omit_frame_pointer = value;
1123 break;
1124
6ff3a151
NB
1125 case OPT_foptimize_register_move:
1126 flag_regmove = value;
1127 break;
1128
de32c0cb
NB
1129 case OPT_foptimize_sibling_calls:
1130 flag_optimize_sibling_calls = value;
1131 break;
1132
6ff3a151
NB
1133 case OPT_fpack_struct:
1134 flag_pack_struct = value;
1135 break;
1136
de32c0cb
NB
1137 case OPT_fpeel_loops:
1138 flag_peel_loops = value;
1139 break;
1140
1141 case OPT_fpcc_struct_return:
1142 flag_pcc_struct_return = value;
1143 break;
1144
1145 case OPT_fpeephole:
1146 flag_no_peephole = !value;
1147 break;
1148
6ff3a151
NB
1149 case OPT_fpeephole2:
1150 flag_peephole2 = value;
1151 break;
1152
1153 case OPT_fpic:
1154 flag_pic = value;
1155 break;
1156
1157 case OPT_fpie:
1158 flag_pie = value;
1159 break;
1160
de32c0cb
NB
1161 case OPT_fprefetch_loop_arrays:
1162 flag_prefetch_loop_arrays = value;
1163 break;
1164
6ff3a151
NB
1165 case OPT_fprofile:
1166 profile_flag = value;
1167 break;
1168
1169 case OPT_fprofile_arcs:
1170 profile_arc_flag = value;
1171 break;
1172
fca9dc00
ZD
1173 case OPT_fprofile_values:
1174 flag_profile_values = value;
1175 break;
1176
1177 case OPT_fvpt:
1178 flag_value_profile_transformations = value;
1179 break;
1180
de32c0cb
NB
1181 case OPT_frandom_seed:
1182 /* The real switch is -fno-random-seed. */
1183 if (value)
1184 return 0;
1185 flag_random_seed = NULL;
1186 break;
1187
1188 case OPT_frandom_seed_:
1189 flag_random_seed = arg;
1190 break;
1191
1192 case OPT_freduce_all_givs:
1193 flag_reduce_all_givs = value;
1194 break;
1195
1196 case OPT_freg_struct_return:
1197 flag_pcc_struct_return = !value;
1198 break;
1199
6ff3a151
NB
1200 case OPT_fregmove:
1201 flag_regmove = value;
1202 break;
1203
1204 case OPT_frename_registers:
1205 flag_rename_registers = value;
1206 break;
1207
1208 case OPT_freorder_blocks:
1209 flag_reorder_blocks = value;
1210 break;
1211
1212 case OPT_freorder_functions:
1213 flag_reorder_functions = value;
1214 break;
1215
de32c0cb
NB
1216 case OPT_frerun_cse_after_loop:
1217 flag_rerun_cse_after_loop = value;
1218 break;
1219
1220 case OPT_frerun_loop_opt:
1221 flag_rerun_loop_opt = value;
1222 break;
1223
039c3d42
RS
1224 case OPT_frounding_math:
1225 flag_rounding_math = value;
1226 break;
1227
6ff3a151 1228 case OPT_fsched_interblock:
039c3d42 1229 flag_schedule_interblock = value;
6ff3a151
NB
1230 break;
1231
1232 case OPT_fsched_spec:
1233 flag_schedule_speculative = value;
1234 break;
1235
1236 case OPT_fsched_spec_load:
1237 flag_schedule_speculative_load = value;
1238 break;
1239
1240 case OPT_fsched_spec_load_dangerous:
1241 flag_schedule_speculative_load_dangerous = value;
1242 break;
1243
de32c0cb
NB
1244 case OPT_fsched_verbose_:
1245#ifdef INSN_SCHEDULING
1246 fix_sched_param ("verbose", arg);
1247 break;
1248#else
1249 return 0;
1250#endif
1251
6ff3a151
NB
1252 case OPT_fsched2_use_superblocks:
1253 flag_sched2_use_superblocks = value;
1254 break;
1255
1256 case OPT_fsched2_use_traces:
1257 flag_sched2_use_traces = value;
1258 break;
1259
de32c0cb
NB
1260 case OPT_fschedule_insns:
1261 flag_schedule_insns = value;
1262 break;
1263
1264 case OPT_fschedule_insns2:
1265 flag_schedule_insns_after_reload = value;
1266 break;
1267
569fa502
DN
1268 case OPT_fsched_stalled_insns:
1269 flag_sched_stalled_insns = value;
1270 break;
1271
1272 case OPT_fsched_stalled_insns_:
1273 flag_sched_stalled_insns = value;
1274 if (flag_sched_stalled_insns == 0)
1275 flag_sched_stalled_insns = -1;
1276 break;
1277
1278 case OPT_fsched_stalled_insns_dep:
1279 flag_sched_stalled_insns_dep = 1;
1280 break;
1281
1282 case OPT_fsched_stalled_insns_dep_:
1283 flag_sched_stalled_insns_dep = value;
1284 break;
1285
de32c0cb
NB
1286 case OPT_fshared_data:
1287 flag_shared_data = value;
1288 break;
1289
6ff3a151
NB
1290 case OPT_fsignaling_nans:
1291 flag_signaling_nans = value;
1292 break;
1293
1294 case OPT_fsingle_precision_constant:
1295 flag_single_precision_constant = value;
1296 break;
1297
6ff3a151
NB
1298 case OPT_fstack_check:
1299 flag_stack_check = value;
1300 break;
1301
de32c0cb
NB
1302 case OPT_fstack_limit:
1303 /* The real switch is -fno-stack-limit. */
1304 if (value)
1305 return 0;
1306 stack_limit_rtx = NULL_RTX;
1307 break;
1308
058de654
NB
1309 case OPT_fstack_limit_register_:
1310 {
1311 int reg = decode_reg_name (arg);
1312 if (reg < 0)
1313 error ("unrecognized register name \"%s\"", arg);
1314 else
1315 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1316 }
1317 break;
1318
1319 case OPT_fstack_limit_symbol_:
1320 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1321 break;
1322
de32c0cb
NB
1323 case OPT_fstrength_reduce:
1324 flag_strength_reduce = value;
1325 break;
1326
6ff3a151
NB
1327 case OPT_fstrict_aliasing:
1328 flag_strict_aliasing = value;
1329 break;
1330
de32c0cb
NB
1331 case OPT_fsyntax_only:
1332 flag_syntax_only = value;
1333 break;
1334
6ff3a151
NB
1335 case OPT_ftest_coverage:
1336 flag_test_coverage = value;
1337 break;
1338
de32c0cb
NB
1339 case OPT_fthread_jumps:
1340 flag_thread_jumps = value;
1341 break;
1342
6ff3a151
NB
1343 case OPT_ftime_report:
1344 time_report = value;
0bd95603 1345 break;
6ff3a151 1346
058de654
NB
1347 case OPT_ftls_model_:
1348 if (!strcmp (arg, "global-dynamic"))
1349 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1350 else if (!strcmp (arg, "local-dynamic"))
1351 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1352 else if (!strcmp (arg, "initial-exec"))
1353 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1354 else if (!strcmp (arg, "local-exec"))
1355 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1356 else
1357 warning ("unknown tls-model \"%s\"", arg);
1358 break;
1359
de32c0cb
NB
1360 case OPT_ftracer:
1361 flag_tracer = value;
1362 break;
1363
6ff3a151
NB
1364 case OPT_ftrapping_math:
1365 flag_trapping_math = value;
1366 break;
1367
1368 case OPT_ftrapv:
1369 flag_trapv = value;
1370 break;
1371
de32c0cb
NB
1372 case OPT_funit_at_a_time:
1373 flag_unit_at_a_time = value;
1374 break;
1375
1376 case OPT_funroll_all_loops:
1377 flag_unroll_all_loops = value;
1378 break;
1379
1380 case OPT_funroll_loops:
1381 flag_unroll_loops = value;
1382 break;
1383
6ff3a151
NB
1384 case OPT_funsafe_math_optimizations:
1385 flag_unsafe_math_optimizations = value;
1386 break;
1387
de32c0cb
NB
1388 case OPT_funswitch_loops:
1389 flag_unswitch_loops = value;
1390 break;
1391
6ff3a151
NB
1392 case OPT_funwind_tables:
1393 flag_unwind_tables = value;
1394 break;
1395
1396 case OPT_fverbose_asm:
1397 flag_verbose_asm = value;
1398 break;
7260e9a0
JH
1399
1400 case OPT_fweb:
1401 flag_web = value;
1402 break;
6ff3a151
NB
1403
1404 case OPT_fwrapv:
1405 flag_wrapv = value;
1406 break;
1407
de32c0cb
NB
1408 case OPT_fwritable_strings:
1409 flag_writable_strings = value;
1410 break;
1411
6ff3a151
NB
1412 case OPT_fzero_initialized_in_bss:
1413 flag_zero_initialized_in_bss = value;
1414 break;
1415
e01cc6dc 1416 case OPT_g:
df38ffef
NB
1417 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1418 break;
1419
1420 case OPT_gcoff:
1421 set_debug_level (SDB_DEBUG, false, arg);
1422 break;
1423
1424 case OPT_gdwarf:
1425 if (*arg)
1426 {
1427 error ("use -gdwarf -gN for DWARF v1 level N, "
1428 "and -gdwarf-2 for DWARF v2" );
1429 break;
1430 }
1431
1432 /* Fall through. */
1433 case OPT_gdwarf_:
1434 set_debug_level (DWARF_DEBUG, code == OPT_gdwarf_, arg);
1435 break;
1436
1437 case OPT_gdwarf_2:
1438 set_debug_level (DWARF2_DEBUG, false, arg);
1439 break;
1440
1441 case OPT_ggdb:
1442 set_debug_level (NO_DEBUG, 2, arg);
1443 break;
1444
1445 case OPT_gstabs:
1446 case OPT_gstabs_:
1447 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1448 break;
1449
1450 case OPT_gvms:
1451 set_debug_level (VMS_DEBUG, false, arg);
1452 break;
1453
1454 case OPT_gxcoff:
1455 case OPT_gxcoff_:
1456 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
e01cc6dc
NB
1457 break;
1458
903caebf
NB
1459 case OPT_m:
1460 set_target_switch (arg);
1461 break;
1462
d185d268
NB
1463 case OPT_o:
1464 asm_file_name = arg;
1465 break;
1466
1467 case OPT_p:
1468 profile_flag = 1;
1469 break;
1470
1471 case OPT_pedantic:
1472 pedantic = 1;
1473 break;
1474
1475 case OPT_pedantic_errors:
1476 flag_pedantic_errors = pedantic = 1;
1477 break;
1478
d7b42618
NB
1479 case OPT_quiet:
1480 quiet_flag = 1;
1481 break;
d185d268
NB
1482
1483 case OPT_version:
1484 version_flag = 1;
1485 break;
1486
1487 case OPT_w:
e01cc6dc 1488 inhibit_warnings = true;
d185d268 1489 break;
d7b42618
NB
1490 }
1491
1492 return 1;
1493}
903caebf
NB
1494
1495/* Handle --param NAME=VALUE. */
1496static void
1497handle_param (const char *carg)
1498{
1499 char *equal, *arg;
1500 int value;
1501
1502 arg = xstrdup (carg);
1503 equal = strchr (arg, '=');
1504 if (!equal)
1505 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1506 else
1507 {
1508 value = integral_argument (equal + 1);
1509 if (value == -1)
1510 error ("invalid --param value `%s'", equal + 1);
1511 else
1512 {
1513 *equal = '\0';
1514 set_param_value (arg, value);
1515 }
1516 }
1517
1518 free (arg);
1519}
1520
1521/* Handle -W and -Wextra. */
1522static void
1523set_Wextra (int setting)
1524{
1525 extra_warnings = setting;
1526 warn_unused_value = setting;
1527 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1528
1529 /* We save the value of warn_uninitialized, since if they put
1530 -Wuninitialized on the command line, we need to generate a
1531 warning about not using it without also specifying -O. */
1532 if (setting == 0)
1533 warn_uninitialized = 0;
1534 else if (warn_uninitialized != 1)
1535 warn_uninitialized = 2;
1536}
1537
1538/* Initialize unused warning flags. */
1539void
1540set_Wunused (int setting)
1541{
1542 warn_unused_function = setting;
1543 warn_unused_label = setting;
1544 /* Unused function parameter warnings are reported when either
1545 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1546 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1547 otherwise set maybe_warn_extra_parameter, which will be picked up
1548 by set_Wextra. */
1549 maybe_warn_unused_parameter = setting;
1550 warn_unused_parameter = (setting && extra_warnings);
1551 warn_unused_variable = setting;
1552 warn_unused_value = setting;
1553}
058de654
NB
1554
1555/* The following routines are useful in setting all the flags that
1556 -ffast-math and -fno-fast-math imply. */
1557void
1558set_fast_math_flags (int set)
1559{
1560 flag_trapping_math = !set;
1561 flag_unsafe_math_optimizations = set;
1562 flag_finite_math_only = set;
1563 flag_errno_math = !set;
1564 if (set)
039c3d42
RS
1565 {
1566 flag_signaling_nans = 0;
1567 flag_rounding_math = 0;
1568 }
058de654
NB
1569}
1570
1571/* Return true iff flags are set as if -ffast-math. */
1572bool
1573fast_math_flags_set_p (void)
1574{
1575 return (!flag_trapping_math
1576 && flag_unsafe_math_optimizations
1577 && flag_finite_math_only
1578 && !flag_errno_math);
1579}
cf03fd63 1580
df38ffef
NB
1581/* Handle a debug output -g switch. EXTENDED is true or false to support
1582 extended output (2 is special and means "-ggdb" was given). */
1583static void
1584set_debug_level (enum debug_info_type type, int extended, const char *arg)
1585{
1586 static bool type_explicit;
1587
1588 use_gnu_debug_info_extensions = extended;
1589
1590 if (type == NO_DEBUG)
1591 {
1592 if (write_symbols == NO_DEBUG)
1593 {
1594 write_symbols = PREFERRED_DEBUGGING_TYPE;
1595
1596 if (extended == 2)
1597 {
1598#ifdef DWARF2_DEBUGGING_INFO
1599 write_symbols = DWARF2_DEBUG;
1600#elif defined DBX_DEBUGGING_INFO
1601 write_symbols = DBX_DEBUG;
1602#endif
1603 }
1604
1605 if (write_symbols == NO_DEBUG)
1606 warning ("target system does not support debug output");
1607 }
1608 }
1609 else
1610 {
1611 /* Does it conflict with an already selected type? */
1612 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1613 error ("debug format \"%s\" conflicts with prior selection",
1614 debug_type_names[type]);
1615 write_symbols = type;
1616 type_explicit = true;
1617 }
1618
1619 /* A debug flag without a level defaults to level 2. */
1620 if (*arg == '\0')
1621 {
1622 if (!debug_info_level)
1623 debug_info_level = 2;
1624 }
1625 else
1626 {
1627 debug_info_level = integral_argument (arg);
1628 if (debug_info_level == (unsigned int) -1)
1629 error ("unrecognised debug output level \"%s\"", arg);
1630 else if (debug_info_level > 3)
1631 error ("debug output level %s is too high", arg);
1632 }
1633}
1634
cf03fd63
NB
1635/* Output --help text. */
1636static void
1637print_help (void)
72de27ea
NB
1638{
1639 size_t i;
2cc98056
NB
1640 const char *p;
1641
1642 GET_ENVIRONMENT (p, "COLUMNS");
1643 if (p)
1644 {
1645 int value = atoi (p);
1646 if (value > 0)
1647 columns = value;
1648 }
72de27ea
NB
1649
1650 puts (_("The following options are language-independent:\n"));
1651
1652 print_filtered_help (CL_COMMON);
2cc98056 1653 print_param_help ();
72de27ea
NB
1654
1655 for (i = 0; lang_names[i]; i++)
1656 {
2cc98056 1657 printf (_("The %s front end recognizes the following options:\n\n"),
72de27ea
NB
1658 lang_names[i]);
1659 print_filtered_help (1U << i);
1660 }
1661
df38ffef 1662 display_target_options ();
72de27ea
NB
1663}
1664
2cc98056
NB
1665/* Print the help for --param. */
1666static void
1667print_param_help (void)
1668{
1669 size_t i;
1670
1671 puts (_("The --param option recognizes the following as parameters:\n"));
1672
1673 for (i = 0; i < LAST_PARAM; i++)
1674 {
1675 const char *help = compiler_params[i].help;
1676 const char *param = compiler_params[i].option;
1677
1678 if (help == NULL || *help == '\0')
1679 help = undocumented_msg;
1680
1681 /* Get the translation. */
1682 help = _(help);
1683
1684 wrap_help (help, param, strlen (param));
1685 }
1686
1687 putchar ('\n');
1688}
1689
72de27ea
NB
1690/* Print help for a specific front-end, etc. */
1691static void
1692print_filtered_help (unsigned int flag)
cf03fd63 1693{
2cc98056
NB
1694 unsigned int i, len, filter, indent = 0;
1695 bool duplicates = false;
1696 const char *help, *opt, *tab;
1697 static char *printed;
1698
1699 if (flag == CL_COMMON)
1700 {
1701 filter = flag;
1702 if (!printed)
1703 printed = xmalloc (cl_options_count);
1704 memset (printed, 0, cl_options_count);
1705 }
1706 else
1707 {
1708 /* Don't print COMMON options twice. */
1709 filter = flag | CL_COMMON;
cf03fd63 1710
2cc98056
NB
1711 for (i = 0; i < cl_options_count; i++)
1712 {
1713 if ((cl_options[i].flags & filter) != flag)
1714 continue;
1715
1716 /* Skip help for internal switches. */
1717 if (cl_options[i].flags & CL_UNDOCUMENTED)
1718 continue;
1719
1720 /* Skip switches that have already been printed, mark them to be
1721 listed later. */
1722 if (printed[i])
1723 {
1724 duplicates = true;
1725 indent = print_switch (cl_options[i].opt_text, indent);
1726 }
1727 }
1728
1729 if (duplicates)
1730 {
1731 putchar ('\n');
1732 putchar ('\n');
1733 }
1734 }
cf03fd63
NB
1735
1736 for (i = 0; i < cl_options_count; i++)
1737 {
72de27ea
NB
1738 if ((cl_options[i].flags & filter) != flag)
1739 continue;
1740
f2ac9964
NB
1741 /* Skip help for internal switches. */
1742 if (cl_options[i].flags & CL_UNDOCUMENTED)
1743 continue;
1744
2cc98056
NB
1745 /* Skip switches that have already been printed. */
1746 if (printed[i])
1747 continue;
1748
1749 printed[i] = true;
1750
72de27ea 1751 help = cl_options[i].help;
cf03fd63 1752 if (!help)
2cc98056 1753 help = undocumented_msg;
cf03fd63
NB
1754
1755 /* Get the translation. */
1756 help = _(help);
1757
1758 tab = strchr (help, '\t');
1759 if (tab)
1760 {
1761 len = tab - help;
1762 opt = help;
1763 help = tab + 1;
1764 }
1765 else
1766 {
1767 opt = cl_options[i].opt_text;
1768 len = strlen (opt);
1769 }
1770
1771 wrap_help (help, opt, len);
1772 }
2cc98056
NB
1773
1774 putchar ('\n');
1775}
1776
1777/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1778 word-wrapped HELP in a second column. */
1779static unsigned int
1780print_switch (const char *text, unsigned int indent)
1781{
1782 unsigned int len = strlen (text) + 1; /* trailing comma */
1783
1784 if (indent)
1785 {
1786 putchar (',');
1787 if (indent + len > columns)
1788 {
1789 putchar ('\n');
1790 putchar (' ');
1791 indent = 1;
1792 }
1793 }
1794 else
1795 putchar (' ');
1796
1797 putchar (' ');
1798 fputs (text, stdout);
1799
1800 return indent + len + 1;
cf03fd63
NB
1801}
1802
1803/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1804 word-wrapped HELP in a second column. */
1805static void
2cc98056 1806wrap_help (const char *help, const char *item, unsigned int item_width)
cf03fd63 1807{
2cc98056 1808 unsigned int col_width = 27;
21789816 1809 unsigned int remaining, room, len;
cf03fd63
NB
1810
1811 remaining = strlen (help);
1812
1813 do
1814 {
1815 room = columns - 3 - MAX (col_width, item_width);
2cc98056
NB
1816 if (room > columns)
1817 room = 0;
cf03fd63
NB
1818 len = remaining;
1819
1820 if (room < len)
1821 {
21789816 1822 unsigned int i;
cf03fd63
NB
1823
1824 for (i = 0; help[i]; i++)
1825 {
1826 if (i >= room && len != remaining)
1827 break;
1828 if (help[i] == ' ')
1829 len = i;
2cc98056
NB
1830 else if ((help[i] == '-' || help[i] == '/')
1831 && help[i + 1] != ' '
b50d9339 1832 && i > 0 && ISALPHA (help[i - 1]))
cf03fd63
NB
1833 len = i + 1;
1834 }
1835 }
1836
1837 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
1838 item_width = 0;
1839 while (help[len] == ' ')
1840 len++;
1841 help += len;
1842 remaining -= len;
1843 }
1844 while (remaining);
1845}