Collections.java (UnmodifiableMap.toArray): Imported changes from Classpath.
[gcc.git] / gcc / opts.c
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Neil Booth.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "intl.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "rtl.h"
30 #include "ggc.h"
31 #include "output.h"
32 #include "langhooks.h"
33 #include "opts.h"
34 #include "options.h"
35 #include "flags.h"
36 #include "toplev.h"
37 #include "params.h"
38 #include "diagnostic.h"
39 #include "tm_p.h" /* For OPTIMIZATION_OPTIONS. */
40 #include "insn-attr.h" /* For INSN_SCHEDULING. */
41 #include "target.h"
42 #include "tree-pass.h"
43
44 /* Value of the -G xx switch, and whether it was passed or not. */
45 unsigned HOST_WIDE_INT g_switch_value;
46 bool g_switch_set;
47
48 /* True if we should exit after parsing options. */
49 bool exit_after_options;
50
51 /* Print various extra warnings. -W/-Wextra. */
52 bool extra_warnings;
53
54 /* True to warn about any objects definitions whose size is larger
55 than N bytes. Also want about function definitions whose returned
56 values are larger than N bytes, where N is `larger_than_size'. */
57 bool warn_larger_than;
58 HOST_WIDE_INT larger_than_size;
59
60 /* Nonzero means warn about constructs which might not be
61 strict-aliasing safe. */
62 int warn_strict_aliasing;
63
64 /* Hack for cooperation between set_Wunused and set_Wextra. */
65 static bool maybe_warn_unused_parameter;
66
67 /* Type(s) of debugging information we are producing (if any). See
68 flags.h for the definitions of the different possible types of
69 debugging information. */
70 enum debug_info_type write_symbols = NO_DEBUG;
71
72 /* Level of debugging information we are producing. See flags.h for
73 the definitions of the different possible levels. */
74 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
75
76 /* Nonzero means use GNU-only extensions in the generated symbolic
77 debugging information. Currently, this only has an effect when
78 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
79 bool use_gnu_debug_info_extensions;
80
81 /* The default visibility for all symbols (unless overridden) */
82 enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
83
84 /* Disable unit-at-a-time for frontends that might be still broken in this
85 respect. */
86
87 bool no_unit_at_a_time_default;
88
89 /* Global visibility options. */
90 struct visibility_flags visibility_options;
91
92 /* What to print when a switch has no documentation. */
93 static const char undocumented_msg[] = N_("This switch lacks documentation");
94
95 /* Used for bookkeeping on whether user set these flags so
96 -fprofile-use/-fprofile-generate does not use them. */
97 static bool profile_arc_flag_set, flag_profile_values_set;
98 static bool flag_unroll_loops_set, flag_tracer_set;
99 static bool flag_value_profile_transformations_set;
100 static bool flag_peel_loops_set, flag_branch_probabilities_set;
101
102 /* Input file names. */
103 const char **in_fnames;
104 unsigned num_in_fnames;
105
106 static int common_handle_option (size_t scode, const char *arg, int value,
107 unsigned int lang_mask);
108 static void handle_param (const char *);
109 static void set_Wextra (int);
110 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
111 static char *write_langs (unsigned int lang_mask);
112 static void complain_wrong_lang (const char *, const struct cl_option *,
113 unsigned int lang_mask);
114 static void handle_options (unsigned int, const char **, unsigned int);
115 static void set_debug_level (enum debug_info_type type, int extended,
116 const char *arg);
117
118 /* If ARG is a non-negative integer made up solely of digits, return its
119 value, otherwise return -1. */
120 static int
121 integral_argument (const char *arg)
122 {
123 const char *p = arg;
124
125 while (*p && ISDIGIT (*p))
126 p++;
127
128 if (*p == '\0')
129 return atoi (arg);
130
131 return -1;
132 }
133
134 /* Return a malloced slash-separated list of languages in MASK. */
135 static char *
136 write_langs (unsigned int mask)
137 {
138 unsigned int n = 0, len = 0;
139 const char *lang_name;
140 char *result;
141
142 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
143 if (mask & (1U << n))
144 len += strlen (lang_name) + 1;
145
146 result = XNEWVEC (char, len);
147 len = 0;
148 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
149 if (mask & (1U << n))
150 {
151 if (len)
152 result[len++] = '/';
153 strcpy (result + len, lang_name);
154 len += strlen (lang_name);
155 }
156
157 result[len] = 0;
158
159 return result;
160 }
161
162 /* Complain that switch OPT_INDEX does not apply to this front end. */
163 static void
164 complain_wrong_lang (const char *text, const struct cl_option *option,
165 unsigned int lang_mask)
166 {
167 char *ok_langs, *bad_lang;
168
169 ok_langs = write_langs (option->flags);
170 bad_lang = write_langs (lang_mask);
171
172 /* Eventually this should become a hard error IMO. */
173 warning (0, "command line option \"%s\" is valid for %s but not for %s",
174 text, ok_langs, bad_lang);
175
176 free (ok_langs);
177 free (bad_lang);
178 }
179
180 /* Handle the switch beginning at ARGV for the language indicated by
181 LANG_MASK. Returns the number of switches consumed. */
182 static unsigned int
183 handle_option (const char **argv, unsigned int lang_mask)
184 {
185 size_t opt_index;
186 const char *opt, *arg = 0;
187 char *dup = 0;
188 int value = 1;
189 unsigned int result = 0;
190 const struct cl_option *option;
191
192 opt = argv[0];
193
194 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
195 if (opt_index == cl_options_count
196 && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
197 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
198 {
199 /* Drop the "no-" from negative switches. */
200 size_t len = strlen (opt) - 3;
201
202 dup = XNEWVEC (char, len + 1);
203 dup[0] = '-';
204 dup[1] = opt[1];
205 memcpy (dup + 2, opt + 5, len - 2 + 1);
206 opt = dup;
207 value = 0;
208 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
209 }
210
211 if (opt_index == cl_options_count)
212 goto done;
213
214 option = &cl_options[opt_index];
215
216 /* Reject negative form of switches that don't take negatives as
217 unrecognized. */
218 if (!value && (option->flags & CL_REJECT_NEGATIVE))
219 goto done;
220
221 /* We've recognized this switch. */
222 result = 1;
223
224 /* Check to see if the option is disabled for this configuration. */
225 if (option->flags & CL_DISABLED)
226 {
227 error ("command line option %qs"
228 " is not supported by this configuration", opt);
229 goto done;
230 }
231
232 /* Sort out any argument the switch takes. */
233 if (option->flags & CL_JOINED)
234 {
235 /* Have arg point to the original switch. This is because
236 some code, such as disable_builtin_function, expects its
237 argument to be persistent until the program exits. */
238 arg = argv[0] + cl_options[opt_index].opt_len + 1;
239 if (!value)
240 arg += strlen ("no-");
241
242 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
243 {
244 if (option->flags & CL_SEPARATE)
245 {
246 arg = argv[1];
247 result = 2;
248 }
249 else
250 /* Missing argument. */
251 arg = NULL;
252 }
253 }
254 else if (option->flags & CL_SEPARATE)
255 {
256 arg = argv[1];
257 result = 2;
258 }
259
260 /* Now we've swallowed any potential argument, complain if this
261 is a switch for a different front end. */
262 if (!(option->flags & (lang_mask | CL_COMMON | CL_TARGET)))
263 {
264 complain_wrong_lang (argv[0], option, lang_mask);
265 goto done;
266 }
267
268 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
269 {
270 if (!lang_hooks.missing_argument (opt, opt_index))
271 error ("missing argument to \"%s\"", opt);
272 goto done;
273 }
274
275 /* If the switch takes an integer, convert it. */
276 if (arg && (option->flags & CL_UINTEGER))
277 {
278 value = integral_argument (arg);
279 if (value == -1)
280 {
281 error ("argument to \"%s\" should be a non-negative integer",
282 option->opt_text);
283 goto done;
284 }
285 }
286
287 if (option->flag_var)
288 switch (option->var_type)
289 {
290 case CLVC_BOOLEAN:
291 *(int *) option->flag_var = value;
292 break;
293
294 case CLVC_EQUAL:
295 *(int *) option->flag_var = (value
296 ? option->var_value
297 : !option->var_value);
298 break;
299
300 case CLVC_BIT_CLEAR:
301 case CLVC_BIT_SET:
302 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
303 *(int *) option->flag_var |= option->var_value;
304 else
305 *(int *) option->flag_var &= ~option->var_value;
306 if (option->flag_var == &target_flags)
307 target_flags_explicit |= option->var_value;
308 break;
309
310 case CLVC_STRING:
311 *(const char **) option->flag_var = arg;
312 break;
313 }
314
315 if (option->flags & lang_mask)
316 if (lang_hooks.handle_option (opt_index, arg, value) == 0)
317 result = 0;
318
319 if (result && (option->flags & CL_COMMON))
320 if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
321 result = 0;
322
323 if (result && (option->flags & CL_TARGET))
324 if (!targetm.handle_option (opt_index, arg, value))
325 result = 0;
326
327 done:
328 if (dup)
329 free (dup);
330 return result;
331 }
332
333 /* Handle FILENAME from the command line. */
334 static void
335 add_input_filename (const char *filename)
336 {
337 num_in_fnames++;
338 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
339 in_fnames[num_in_fnames - 1] = filename;
340 }
341
342 /* Decode and handle the vector of command line options. LANG_MASK
343 contains has a single bit set representing the current
344 language. */
345 static void
346 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
347 {
348 unsigned int n, i;
349
350 for (i = 1; i < argc; i += n)
351 {
352 const char *opt = argv[i];
353
354 /* Interpret "-" or a non-switch as a file name. */
355 if (opt[0] != '-' || opt[1] == '\0')
356 {
357 if (main_input_filename == NULL)
358 main_input_filename = opt;
359 add_input_filename (opt);
360 n = 1;
361 continue;
362 }
363
364 n = handle_option (argv + i, lang_mask);
365
366 if (!n)
367 {
368 n = 1;
369 error ("unrecognized command line option \"%s\"", opt);
370 }
371 }
372 }
373
374 /* Parse command line options and set default flag values. Do minimal
375 options processing. */
376 void
377 decode_options (unsigned int argc, const char **argv)
378 {
379 unsigned int i, lang_mask;
380
381 /* Perform language-specific options initialization. */
382 lang_mask = lang_hooks.init_options (argc, argv);
383
384 lang_hooks.initialize_diagnostics (global_dc);
385
386 /* Scan to see what optimization level has been specified. That will
387 determine the default value of many flags. */
388 for (i = 1; i < argc; i++)
389 {
390 if (!strcmp (argv[i], "-O"))
391 {
392 optimize = 1;
393 optimize_size = 0;
394 }
395 else if (argv[i][0] == '-' && argv[i][1] == 'O')
396 {
397 /* Handle -Os, -O2, -O3, -O69, ... */
398 const char *p = &argv[i][2];
399
400 if ((p[0] == 's') && (p[1] == 0))
401 {
402 optimize_size = 1;
403
404 /* Optimizing for size forces optimize to be 2. */
405 optimize = 2;
406 }
407 else
408 {
409 const int optimize_val = read_integral_parameter (p, p - 2, -1);
410 if (optimize_val != -1)
411 {
412 optimize = optimize_val;
413 optimize_size = 0;
414 }
415 }
416 }
417 }
418
419 if (!optimize)
420 {
421 flag_merge_constants = 0;
422 }
423
424 if (optimize >= 1)
425 {
426 flag_defer_pop = 1;
427 #ifdef DELAY_SLOTS
428 flag_delayed_branch = 1;
429 #endif
430 #ifdef CAN_DEBUG_WITHOUT_FP
431 flag_omit_frame_pointer = 1;
432 #endif
433 flag_guess_branch_prob = 1;
434 flag_cprop_registers = 1;
435 flag_if_conversion = 1;
436 flag_if_conversion2 = 1;
437 flag_ipa_pure_const = 1;
438 flag_ipa_reference = 1;
439 flag_split_wide_types = 1;
440 flag_tree_ccp = 1;
441 flag_tree_dce = 1;
442 flag_tree_dom = 1;
443 flag_tree_dse = 1;
444 flag_tree_ter = 1;
445 flag_tree_sra = 1;
446 flag_tree_copyrename = 1;
447 flag_tree_fre = 1;
448 flag_tree_copy_prop = 1;
449 flag_tree_sink = 1;
450 flag_tree_salias = 1;
451 if (!no_unit_at_a_time_default)
452 flag_unit_at_a_time = 1;
453
454 if (!optimize_size)
455 {
456 /* Loop header copying usually increases size of the code. This used
457 not to be true, since quite often it is possible to verify that
458 the condition is satisfied in the first iteration and therefore
459 to eliminate it. Jump threading handles these cases now. */
460 flag_tree_ch = 1;
461 }
462 }
463
464 if (optimize >= 2)
465 {
466 flag_thread_jumps = 1;
467 flag_crossjumping = 1;
468 flag_optimize_sibling_calls = 1;
469 flag_forward_propagate = 1;
470 flag_cse_follow_jumps = 1;
471 flag_gcse = 1;
472 flag_expensive_optimizations = 1;
473 flag_ipa_type_escape = 1;
474 flag_rerun_cse_after_loop = 1;
475 flag_caller_saves = 1;
476 flag_peephole2 = 1;
477 #ifdef INSN_SCHEDULING
478 flag_schedule_insns = 1;
479 flag_schedule_insns_after_reload = 1;
480 #endif
481 flag_regmove = 1;
482 flag_strict_aliasing = 1;
483 flag_strict_overflow = 1;
484 flag_delete_null_pointer_checks = 1;
485 flag_reorder_blocks = 1;
486 flag_reorder_functions = 1;
487 flag_tree_store_ccp = 1;
488 flag_tree_store_copy_prop = 1;
489 flag_tree_vrp = 1;
490
491 if (!optimize_size)
492 {
493 /* PRE tends to generate bigger code. */
494 flag_tree_pre = 1;
495 }
496 }
497
498 if (optimize >= 3)
499 {
500 flag_inline_functions = 1;
501 flag_unswitch_loops = 1;
502 flag_gcse_after_reload = 1;
503 }
504
505 if (optimize < 2 || optimize_size)
506 {
507 align_loops = 1;
508 align_jumps = 1;
509 align_labels = 1;
510 align_functions = 1;
511
512 /* Don't reorder blocks when optimizing for size because extra
513 jump insns may be created; also barrier may create extra padding.
514
515 More correctly we should have a block reordering mode that tried
516 to minimize the combined size of all the jumps. This would more
517 or less automatically remove extra jumps, but would also try to
518 use more short jumps instead of long jumps. */
519 flag_reorder_blocks = 0;
520 flag_reorder_blocks_and_partition = 0;
521 }
522
523 if (optimize_size)
524 {
525 /* Inlining of very small functions usually reduces total size. */
526 set_param_value ("max-inline-insns-single", 5);
527 set_param_value ("max-inline-insns-auto", 5);
528 flag_inline_functions = 1;
529
530 /* We want to crossjump as much as possible. */
531 set_param_value ("min-crossjump-insns", 1);
532 }
533
534 /* Initialize whether `char' is signed. */
535 flag_signed_char = DEFAULT_SIGNED_CHAR;
536 /* Set this to a special "uninitialized" value. The actual default is set
537 after target options have been processed. */
538 flag_short_enums = 2;
539
540 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
541 modify it. */
542 target_flags = targetm.default_target_flags;
543
544 /* Some tagets have ABI-specified unwind tables. */
545 flag_unwind_tables = targetm.unwind_tables_default;
546
547 #ifdef OPTIMIZATION_OPTIONS
548 /* Allow default optimizations to be specified on a per-machine basis. */
549 OPTIMIZATION_OPTIONS (optimize, optimize_size);
550 #endif
551
552 handle_options (argc, argv, lang_mask);
553
554 if (flag_pie)
555 flag_pic = flag_pie;
556 if (flag_pic && !flag_pie)
557 flag_shlib = 1;
558
559 if (flag_no_inline == 2)
560 flag_no_inline = 0;
561 else
562 flag_really_no_inline = flag_no_inline;
563
564 /* Set flag_no_inline before the post_options () hook. The C front
565 ends use it to determine tree inlining defaults. FIXME: such
566 code should be lang-independent when all front ends use tree
567 inlining, in which case it, and this condition, should be moved
568 to the top of process_options() instead. */
569 if (optimize == 0)
570 {
571 /* Inlining does not work if not optimizing,
572 so force it not to be done. */
573 flag_no_inline = 1;
574 warn_inline = 0;
575
576 /* The c_decode_option function and decode_option hook set
577 this to `2' if -Wall is used, so we can avoid giving out
578 lots of errors for people who don't realize what -Wall does. */
579 if (warn_uninitialized == 1)
580 warning (OPT_Wuninitialized,
581 "-Wuninitialized is not supported without -O");
582 }
583
584 if (flag_really_no_inline == 2)
585 flag_really_no_inline = flag_no_inline;
586
587 /* The optimization to partition hot and cold basic blocks into separate
588 sections of the .o and executable files does not work (currently)
589 with exception handling. This is because there is no support for
590 generating unwind info. If flag_exceptions is turned on we need to
591 turn off the partitioning optimization. */
592
593 if (flag_exceptions && flag_reorder_blocks_and_partition)
594 {
595 inform
596 ("-freorder-blocks-and-partition does not work with exceptions");
597 flag_reorder_blocks_and_partition = 0;
598 flag_reorder_blocks = 1;
599 }
600
601 /* If user requested unwind info, then turn off the partitioning
602 optimization. */
603
604 if (flag_unwind_tables && ! targetm.unwind_tables_default
605 && flag_reorder_blocks_and_partition)
606 {
607 inform ("-freorder-blocks-and-partition does not support unwind info");
608 flag_reorder_blocks_and_partition = 0;
609 flag_reorder_blocks = 1;
610 }
611
612 /* If the target requested unwind info, then turn off the partitioning
613 optimization with a different message. Likewise, if the target does not
614 support named sections. */
615
616 if (flag_reorder_blocks_and_partition
617 && (!targetm.have_named_sections
618 || (flag_unwind_tables && targetm.unwind_tables_default)))
619 {
620 inform
621 ("-freorder-blocks-and-partition does not work on this architecture");
622 flag_reorder_blocks_and_partition = 0;
623 flag_reorder_blocks = 1;
624 }
625 }
626
627 #define LEFT_COLUMN 27
628
629 /* Output ITEM, of length ITEM_WIDTH, in the left column,
630 followed by word-wrapped HELP in a second column. */
631 static void
632 wrap_help (const char *help,
633 const char *item,
634 unsigned int item_width,
635 unsigned int columns)
636 {
637 unsigned int col_width = LEFT_COLUMN;
638 unsigned int remaining, room, len;
639
640 remaining = strlen (help);
641
642 do
643 {
644 room = columns - 3 - MAX (col_width, item_width);
645 if (room > columns)
646 room = 0;
647 len = remaining;
648
649 if (room < len)
650 {
651 unsigned int i;
652
653 for (i = 0; help[i]; i++)
654 {
655 if (i >= room && len != remaining)
656 break;
657 if (help[i] == ' ')
658 len = i;
659 else if ((help[i] == '-' || help[i] == '/')
660 && help[i + 1] != ' '
661 && i > 0 && ISALPHA (help[i - 1]))
662 len = i + 1;
663 }
664 }
665
666 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
667 item_width = 0;
668 while (help[len] == ' ')
669 len++;
670 help += len;
671 remaining -= len;
672 }
673 while (remaining);
674 }
675
676 /* Print help for a specific front-end, etc. */
677 static void
678 print_filtered_help (unsigned int include_flags,
679 unsigned int exclude_flags,
680 unsigned int any_flags,
681 unsigned int columns)
682 {
683 unsigned int i;
684 const char *help;
685 static char *printed = NULL;
686 bool found = false;
687 bool displayed = false;
688
689 if (include_flags == CL_PARAMS)
690 {
691 for (i = 0; i < LAST_PARAM; i++)
692 {
693 const char *param = compiler_params[i].option;
694
695 help = compiler_params[i].help;
696 if (help == NULL || *help == '\0')
697 {
698 if (exclude_flags & CL_UNDOCUMENTED)
699 continue;
700 help = undocumented_msg;
701 }
702
703 /* Get the translation. */
704 help = _(help);
705
706 wrap_help (help, param, strlen (param), columns);
707 }
708 putchar ('\n');
709 return;
710 }
711
712 if (!printed)
713 printed = xcalloc (1, cl_options_count);
714
715 for (i = 0; i < cl_options_count; i++)
716 {
717 static char new_help[128];
718 const struct cl_option *option = cl_options + i;
719 unsigned int len;
720 const char *opt;
721 const char *tab;
722
723 if (include_flags == 0
724 || ((option->flags & include_flags) != include_flags))
725 {
726 if ((option->flags & any_flags) == 0)
727 continue;
728 }
729
730 /* Skip unwanted switches. */
731 if ((option->flags & exclude_flags) != 0)
732 continue;
733
734 found = true;
735 /* Skip switches that have already been printed. */
736 if (printed[i])
737 continue;
738
739 printed[i] = true;
740
741 help = option->help;
742 if (help == NULL)
743 {
744 if (exclude_flags & CL_UNDOCUMENTED)
745 continue;
746 help = undocumented_msg;
747 }
748
749 /* Get the translation. */
750 help = _(help);
751
752 /* Find the gap between the name of the
753 option and its descriptive text. */
754 tab = strchr (help, '\t');
755 if (tab)
756 {
757 len = tab - help;
758 opt = help;
759 help = tab + 1;
760 }
761 else
762 {
763 opt = option->opt_text;
764 len = strlen (opt);
765 }
766
767 /* With the -Q option enabled we change the descriptive text associated
768 with an option to be an indication of its current setting. */
769 if (!quiet_flag)
770 {
771 if (len < (LEFT_COLUMN + 2))
772 strcpy (new_help, "\t\t");
773 else
774 strcpy (new_help, "\t");
775
776 if (option->flag_var != NULL)
777 {
778 if (option->flags & CL_JOINED)
779 {
780 if (option->var_type == CLVC_STRING)
781 {
782 if (* (const char **) option->flag_var != NULL)
783 snprintf (new_help + strlen (new_help),
784 sizeof (new_help) - strlen (new_help),
785 * (const char **) option->flag_var);
786 }
787 else
788 sprintf (new_help + strlen (new_help),
789 "%#x", * (int *) option->flag_var);
790 }
791 else
792 strcat (new_help, option_enabled (i)
793 ? _("[enabled]") : _("[disabled]"));
794 }
795
796 help = new_help;
797 }
798
799 wrap_help (help, opt, len, columns);
800 displayed = true;
801 }
802
803 if (! found)
804 printf (_(" No options with the desired characteristics were found\n"));
805 else if (! displayed)
806 printf (_(" All options with the desired characteristics have already been displayed\n"));
807
808 putchar ('\n');
809 }
810
811 /* Display help for a specified type of option.
812 The options must have ALL of the INCLUDE_FLAGS set
813 ANY of the flags in the ANY_FLAGS set
814 and NONE of the EXCLUDE_FLAGS set. */
815 static void
816 print_specific_help (unsigned int include_flags,
817 unsigned int exclude_flags,
818 unsigned int any_flags)
819 {
820 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
821 const char * description = NULL;
822 const char * descrip_extra = "";
823 size_t i;
824 unsigned int flag;
825 static unsigned int columns = 0;
826
827 /* Sanity check: Make sure that we do not have more
828 languages than we have bits available to enumerate them. */
829 gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
830
831 /* If we have not done so already, obtain
832 the desired maximum width of the output. */
833 if (columns == 0)
834 {
835 const char *p;
836
837 GET_ENVIRONMENT (p, "COLUMNS");
838 if (p != NULL)
839 {
840 int value = atoi (p);
841
842 if (value > 0)
843 columns = value;
844 }
845
846 if (columns == 0)
847 /* Use a reasonable default. */
848 columns = 80;
849 }
850
851 /* Decide upon the title for the options that we are going to display. */
852 for (i = 0, flag = 1; flag <= CL_MAX_OPTION_CLASS; flag <<= 1, i ++)
853 {
854 switch (flag & include_flags)
855 {
856 case 0:
857 break;
858
859 case CL_TARGET:
860 description = _("The following options are target specific");
861 break;
862 case CL_WARNING:
863 description = _("The following options control compiler warning messages");
864 break;
865 case CL_OPTIMIZATION:
866 description = _("The following options control optimizations");
867 break;
868 case CL_COMMON:
869 description = _("The following options are language-independent");
870 break;
871 case CL_PARAMS:
872 description = _("The --param option recognizes the following as parameters");
873 break;
874 default:
875 if (i >= cl_lang_count)
876 break;
877 if ((exclude_flags & ((1U << cl_lang_count) - 1)) != 0)
878 {
879 description = _("The following options are specific to the language ");
880 descrip_extra = lang_names [i];
881 }
882 else
883 description = _("The following options are supported by, amoung others, the language ");
884 break;
885 }
886 }
887
888 if (description == NULL)
889 {
890 if (any_flags == 0)
891 {
892 if (include_flags == CL_UNDOCUMENTED)
893 description = _("The following options are not documented");
894 else
895 {
896 internal_error ("unrecognized include_flags 0x%x passed to print_specific_help",
897 include_flags);
898 return;
899 }
900 }
901 else
902 {
903 if (any_flags & all_langs_mask)
904 description = _("The following options are language-related");
905 else
906 description = _("The following options are language-independent");
907 }
908 }
909
910 printf ("%s%s:\n", description, descrip_extra);
911 print_filtered_help (include_flags, exclude_flags, any_flags, columns);
912 }
913
914 /* Handle target- and language-independent options. Return zero to
915 generate an "unknown option" message. Only options that need
916 extra handling need to be listed here; if you simply want
917 VALUE assigned to a variable, it happens automatically. */
918
919 static int
920 common_handle_option (size_t scode, const char *arg, int value,
921 unsigned int lang_mask)
922 {
923 enum opt_code code = (enum opt_code) scode;
924
925 switch (code)
926 {
927 case OPT__param:
928 handle_param (arg);
929 break;
930
931 case OPT_fhelp:
932 case OPT__help:
933 {
934 unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
935 unsigned int undoc_mask;
936 unsigned int i;
937
938 undoc_mask = extra_warnings ? 0 : CL_UNDOCUMENTED;
939 /* First display any single language specific options. */
940 for (i = 0; i < cl_lang_count; i++)
941 print_specific_help
942 (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
943 /* Next display any multi language specific options. */
944 print_specific_help (0, undoc_mask, all_langs_mask);
945 /* Then display any remaining, non-language options. */
946 for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
947 print_specific_help (i, undoc_mask, 0);
948 exit_after_options = true;
949 break;
950 }
951
952 case OPT_ftarget_help:
953 case OPT__target_help:
954 print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
955 exit_after_options = true;
956 break;
957
958 case OPT_fhelp_:
959 case OPT__help_:
960 {
961 const char * a = arg;
962 unsigned int include_flags = 0;
963 /* Note - by default we include undocumented options when listing
964 specific classes. If you only want to see documented options
965 then add ",^undocumented" to the --help= option. e.g.:
966
967 --help=target,^undocumented */
968 unsigned int exclude_flags = 0;
969
970 /* Walk along the argument string, parsing each word in turn.
971 The format is:
972 arg = [^]{word}[,{arg}]
973 word = {optimizers|target|warnings|undocumented|params} */
974 while (* a != 0)
975 {
976 static struct
977 {
978 const char * string;
979 unsigned int flag;
980 }
981 specifics[] =
982 {
983 { "optimizers", CL_OPTIMIZATION },
984 { "target", CL_TARGET },
985 { "warnings", CL_WARNING },
986 { "undocumented", CL_UNDOCUMENTED },
987 { "params", CL_PARAMS },
988 { "joined", CL_JOINED },
989 { "separate", CL_SEPARATE },
990 { NULL, 0 }
991 };
992 unsigned int * pflags;
993 char * comma;
994 unsigned int len;
995 unsigned int i;
996
997 if (* a == '^')
998 {
999 ++ a;
1000 pflags = & exclude_flags;
1001 }
1002 else
1003 pflags = & include_flags;
1004
1005 comma = strchr (a, ',');
1006 if (comma == NULL)
1007 len = strlen (a);
1008 else
1009 len = comma - a;
1010
1011 for (i = 0; specifics[i].string != NULL; i++)
1012 if (strncasecmp (a, specifics[i].string, len) == 0)
1013 {
1014 * pflags |= specifics[i].flag;
1015 break;
1016 }
1017
1018 if (specifics[i].string == NULL)
1019 {
1020 /* Check to see if the string matches a language name. */
1021 for (i = 0; i < cl_lang_count; i++)
1022 if (strncasecmp (a, lang_names[i], len) == 0)
1023 {
1024 * pflags |= 1U << i;
1025 break;
1026 }
1027
1028 if (i == cl_lang_count)
1029 fnotice (stderr,
1030 "warning: unrecognized argument to --help= switch: %.*s\n",
1031 len, a);
1032 }
1033
1034 if (comma == NULL)
1035 break;
1036 a = comma + 1;
1037 }
1038
1039 if (include_flags)
1040 print_specific_help (include_flags, exclude_flags, 0);
1041 exit_after_options = true;
1042 break;
1043 }
1044
1045 case OPT__version:
1046 print_version (stderr, "");
1047 exit_after_options = true;
1048 break;
1049
1050 case OPT_G:
1051 g_switch_value = value;
1052 g_switch_set = true;
1053 break;
1054
1055 case OPT_O:
1056 case OPT_Os:
1057 /* Currently handled in a prescan. */
1058 break;
1059
1060 case OPT_W:
1061 /* For backward compatibility, -W is the same as -Wextra. */
1062 set_Wextra (value);
1063 break;
1064
1065 case OPT_Werror_:
1066 {
1067 char *new_option;
1068 int option_index;
1069
1070 new_option = XNEWVEC (char, strlen (arg) + 2);
1071 new_option[0] = 'W';
1072 strcpy (new_option+1, arg);
1073 option_index = find_opt (new_option, lang_mask);
1074 if (option_index == N_OPTS)
1075 {
1076 error ("-Werror-%s: No option -%s", arg, new_option);
1077 }
1078 else
1079 {
1080 int kind = value ? DK_ERROR : DK_WARNING;
1081 diagnostic_classify_diagnostic (global_dc, option_index, kind);
1082
1083 /* -Werror=foo implies -Wfoo. */
1084 if (cl_options[option_index].var_type == CLVC_BOOLEAN
1085 && cl_options[option_index].flag_var
1086 && kind == DK_ERROR)
1087 *(int *) cl_options[option_index].flag_var = 1;
1088 free (new_option);
1089 }
1090 }
1091 break;
1092
1093 case OPT_Wextra:
1094 set_Wextra (value);
1095 break;
1096
1097 case OPT_Wlarger_than_:
1098 larger_than_size = value;
1099 warn_larger_than = value != -1;
1100 break;
1101
1102 case OPT_Wstrict_aliasing:
1103 case OPT_Wstrict_aliasing_:
1104 warn_strict_aliasing = value;
1105 break;
1106
1107 case OPT_Wunused:
1108 set_Wunused (value);
1109 break;
1110
1111 case OPT_aux_info:
1112 case OPT_aux_info_:
1113 aux_info_file_name = arg;
1114 flag_gen_aux_info = 1;
1115 break;
1116
1117 case OPT_auxbase:
1118 aux_base_name = arg;
1119 break;
1120
1121 case OPT_auxbase_strip:
1122 {
1123 char *tmp = xstrdup (arg);
1124 strip_off_ending (tmp, strlen (tmp));
1125 if (tmp[0])
1126 aux_base_name = tmp;
1127 }
1128 break;
1129
1130 case OPT_d:
1131 decode_d_option (arg);
1132 break;
1133
1134 case OPT_dumpbase:
1135 dump_base_name = arg;
1136 break;
1137
1138 case OPT_falign_functions_:
1139 align_functions = value;
1140 break;
1141
1142 case OPT_falign_jumps_:
1143 align_jumps = value;
1144 break;
1145
1146 case OPT_falign_labels_:
1147 align_labels = value;
1148 break;
1149
1150 case OPT_falign_loops_:
1151 align_loops = value;
1152 break;
1153
1154 case OPT_fbranch_probabilities:
1155 flag_branch_probabilities_set = true;
1156 break;
1157
1158 case OPT_fcall_used_:
1159 fix_register (arg, 0, 1);
1160 break;
1161
1162 case OPT_fcall_saved_:
1163 fix_register (arg, 0, 0);
1164 break;
1165
1166 case OPT_fdiagnostics_show_location_:
1167 if (!strcmp (arg, "once"))
1168 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1169 else if (!strcmp (arg, "every-line"))
1170 diagnostic_prefixing_rule (global_dc)
1171 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1172 else
1173 return 0;
1174 break;
1175
1176 case OPT_fdiagnostics_show_option:
1177 global_dc->show_option_requested = true;
1178 break;
1179
1180 case OPT_fdump_:
1181 if (!dump_switch_p (arg))
1182 return 0;
1183 break;
1184
1185 case OPT_ffast_math:
1186 set_fast_math_flags (value);
1187 break;
1188
1189 case OPT_ffixed_:
1190 fix_register (arg, 1, 1);
1191 break;
1192
1193 case OPT_finline_limit_:
1194 case OPT_finline_limit_eq:
1195 set_param_value ("max-inline-insns-single", value / 2);
1196 set_param_value ("max-inline-insns-auto", value / 2);
1197 break;
1198
1199 case OPT_fmessage_length_:
1200 pp_set_line_maximum_length (global_dc->printer, value);
1201 break;
1202
1203 case OPT_fpack_struct_:
1204 if (value <= 0 || (value & (value - 1)) || value > 16)
1205 error ("structure alignment must be a small power of two, not %d", value);
1206 else
1207 {
1208 initial_max_fld_align = value;
1209 maximum_field_alignment = value * BITS_PER_UNIT;
1210 }
1211 break;
1212
1213 case OPT_fpeel_loops:
1214 flag_peel_loops_set = true;
1215 break;
1216
1217 case OPT_fprofile_arcs:
1218 profile_arc_flag_set = true;
1219 break;
1220
1221 case OPT_fprofile_use:
1222 if (!flag_branch_probabilities_set)
1223 flag_branch_probabilities = value;
1224 if (!flag_profile_values_set)
1225 flag_profile_values = value;
1226 if (!flag_unroll_loops_set)
1227 flag_unroll_loops = value;
1228 if (!flag_peel_loops_set)
1229 flag_peel_loops = value;
1230 if (!flag_tracer_set)
1231 flag_tracer = value;
1232 if (!flag_value_profile_transformations_set)
1233 flag_value_profile_transformations = value;
1234 break;
1235
1236 case OPT_fprofile_generate:
1237 if (!profile_arc_flag_set)
1238 profile_arc_flag = value;
1239 if (!flag_profile_values_set)
1240 flag_profile_values = value;
1241 if (!flag_value_profile_transformations_set)
1242 flag_value_profile_transformations = value;
1243 break;
1244
1245 case OPT_fprofile_values:
1246 flag_profile_values_set = true;
1247 break;
1248
1249 case OPT_fvisibility_:
1250 {
1251 if (!strcmp(arg, "default"))
1252 default_visibility = VISIBILITY_DEFAULT;
1253 else if (!strcmp(arg, "internal"))
1254 default_visibility = VISIBILITY_INTERNAL;
1255 else if (!strcmp(arg, "hidden"))
1256 default_visibility = VISIBILITY_HIDDEN;
1257 else if (!strcmp(arg, "protected"))
1258 default_visibility = VISIBILITY_PROTECTED;
1259 else
1260 error ("unrecognized visibility value \"%s\"", arg);
1261 }
1262 break;
1263
1264 case OPT_fvpt:
1265 flag_value_profile_transformations_set = true;
1266 break;
1267
1268 case OPT_frandom_seed:
1269 /* The real switch is -fno-random-seed. */
1270 if (value)
1271 return 0;
1272 flag_random_seed = NULL;
1273 break;
1274
1275 case OPT_frandom_seed_:
1276 flag_random_seed = arg;
1277 break;
1278
1279 case OPT_fsched_verbose_:
1280 #ifdef INSN_SCHEDULING
1281 fix_sched_param ("verbose", arg);
1282 break;
1283 #else
1284 return 0;
1285 #endif
1286
1287 case OPT_fsched_stalled_insns_:
1288 flag_sched_stalled_insns = value;
1289 if (flag_sched_stalled_insns == 0)
1290 flag_sched_stalled_insns = -1;
1291 break;
1292
1293 case OPT_fsched_stalled_insns_dep_:
1294 flag_sched_stalled_insns_dep = value;
1295 break;
1296
1297 case OPT_fstack_limit:
1298 /* The real switch is -fno-stack-limit. */
1299 if (value)
1300 return 0;
1301 stack_limit_rtx = NULL_RTX;
1302 break;
1303
1304 case OPT_fstack_limit_register_:
1305 {
1306 int reg = decode_reg_name (arg);
1307 if (reg < 0)
1308 error ("unrecognized register name \"%s\"", arg);
1309 else
1310 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1311 }
1312 break;
1313
1314 case OPT_fstack_limit_symbol_:
1315 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1316 break;
1317
1318 case OPT_ftree_vectorizer_verbose_:
1319 vect_set_verbosity_level (arg);
1320 break;
1321
1322 case OPT_ftls_model_:
1323 if (!strcmp (arg, "global-dynamic"))
1324 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1325 else if (!strcmp (arg, "local-dynamic"))
1326 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1327 else if (!strcmp (arg, "initial-exec"))
1328 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1329 else if (!strcmp (arg, "local-exec"))
1330 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1331 else
1332 warning (0, "unknown tls-model \"%s\"", arg);
1333 break;
1334
1335 case OPT_ftracer:
1336 flag_tracer_set = true;
1337 break;
1338
1339 case OPT_funroll_loops:
1340 flag_unroll_loops_set = true;
1341 break;
1342
1343 case OPT_g:
1344 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1345 break;
1346
1347 case OPT_gcoff:
1348 set_debug_level (SDB_DEBUG, false, arg);
1349 break;
1350
1351 case OPT_gdwarf_2:
1352 set_debug_level (DWARF2_DEBUG, false, arg);
1353 break;
1354
1355 case OPT_ggdb:
1356 set_debug_level (NO_DEBUG, 2, arg);
1357 break;
1358
1359 case OPT_gstabs:
1360 case OPT_gstabs_:
1361 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1362 break;
1363
1364 case OPT_gvms:
1365 set_debug_level (VMS_DEBUG, false, arg);
1366 break;
1367
1368 case OPT_gxcoff:
1369 case OPT_gxcoff_:
1370 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1371 break;
1372
1373 case OPT_o:
1374 asm_file_name = arg;
1375 break;
1376
1377 case OPT_pedantic_errors:
1378 flag_pedantic_errors = pedantic = 1;
1379 break;
1380
1381 case OPT_floop_optimize:
1382 case OPT_frerun_loop_opt:
1383 case OPT_fstrength_reduce:
1384 /* These are no-ops, preserved for backward compatibility. */
1385 break;
1386
1387 default:
1388 /* If the flag was handled in a standard way, assume the lack of
1389 processing here is intentional. */
1390 gcc_assert (cl_options[scode].flag_var);
1391 break;
1392 }
1393
1394 return 1;
1395 }
1396
1397 /* Handle --param NAME=VALUE. */
1398 static void
1399 handle_param (const char *carg)
1400 {
1401 char *equal, *arg;
1402 int value;
1403
1404 arg = xstrdup (carg);
1405 equal = strchr (arg, '=');
1406 if (!equal)
1407 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1408 else
1409 {
1410 value = integral_argument (equal + 1);
1411 if (value == -1)
1412 error ("invalid --param value %qs", equal + 1);
1413 else
1414 {
1415 *equal = '\0';
1416 set_param_value (arg, value);
1417 }
1418 }
1419
1420 free (arg);
1421 }
1422
1423 /* Handle -W and -Wextra. */
1424 static void
1425 set_Wextra (int setting)
1426 {
1427 extra_warnings = setting;
1428 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1429
1430 /* We save the value of warn_uninitialized, since if they put
1431 -Wuninitialized on the command line, we need to generate a
1432 warning about not using it without also specifying -O. */
1433 if (setting == 0)
1434 warn_uninitialized = 0;
1435 else if (warn_uninitialized != 1)
1436 warn_uninitialized = 2;
1437 }
1438
1439 /* Initialize unused warning flags. */
1440 void
1441 set_Wunused (int setting)
1442 {
1443 warn_unused_function = setting;
1444 warn_unused_label = setting;
1445 /* Unused function parameter warnings are reported when either
1446 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1447 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1448 otherwise set maybe_warn_extra_parameter, which will be picked up
1449 by set_Wextra. */
1450 maybe_warn_unused_parameter = setting;
1451 warn_unused_parameter = (setting && extra_warnings);
1452 warn_unused_variable = setting;
1453 warn_unused_value = setting;
1454 }
1455
1456 /* The following routines are useful in setting all the flags that
1457 -ffast-math and -fno-fast-math imply. */
1458 void
1459 set_fast_math_flags (int set)
1460 {
1461 flag_trapping_math = !set;
1462 flag_unsafe_math_optimizations = set;
1463 flag_finite_math_only = set;
1464 flag_signed_zeros = !set;
1465 flag_errno_math = !set;
1466 if (set)
1467 {
1468 flag_signaling_nans = 0;
1469 flag_rounding_math = 0;
1470 flag_cx_limited_range = 1;
1471 }
1472 }
1473
1474 /* Return true iff flags are set as if -ffast-math. */
1475 bool
1476 fast_math_flags_set_p (void)
1477 {
1478 return (!flag_trapping_math
1479 && flag_unsafe_math_optimizations
1480 && flag_finite_math_only
1481 && !flag_signed_zeros
1482 && !flag_errno_math);
1483 }
1484
1485 /* Handle a debug output -g switch. EXTENDED is true or false to support
1486 extended output (2 is special and means "-ggdb" was given). */
1487 static void
1488 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1489 {
1490 static bool type_explicit;
1491
1492 use_gnu_debug_info_extensions = extended;
1493
1494 if (type == NO_DEBUG)
1495 {
1496 if (write_symbols == NO_DEBUG)
1497 {
1498 write_symbols = PREFERRED_DEBUGGING_TYPE;
1499
1500 if (extended == 2)
1501 {
1502 #ifdef DWARF2_DEBUGGING_INFO
1503 write_symbols = DWARF2_DEBUG;
1504 #elif defined DBX_DEBUGGING_INFO
1505 write_symbols = DBX_DEBUG;
1506 #endif
1507 }
1508
1509 if (write_symbols == NO_DEBUG)
1510 warning (0, "target system does not support debug output");
1511 }
1512 }
1513 else
1514 {
1515 /* Does it conflict with an already selected type? */
1516 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1517 error ("debug format \"%s\" conflicts with prior selection",
1518 debug_type_names[type]);
1519 write_symbols = type;
1520 type_explicit = true;
1521 }
1522
1523 /* A debug flag without a level defaults to level 2. */
1524 if (*arg == '\0')
1525 {
1526 if (!debug_info_level)
1527 debug_info_level = 2;
1528 }
1529 else
1530 {
1531 debug_info_level = integral_argument (arg);
1532 if (debug_info_level == (unsigned int) -1)
1533 error ("unrecognised debug output level \"%s\"", arg);
1534 else if (debug_info_level > 3)
1535 error ("debug output level %s is too high", arg);
1536 }
1537 }
1538
1539 /* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
1540 a simple on-off switch. */
1541
1542 int
1543 option_enabled (int opt_idx)
1544 {
1545 const struct cl_option *option = &(cl_options[opt_idx]);
1546
1547 if (option->flag_var)
1548 switch (option->var_type)
1549 {
1550 case CLVC_BOOLEAN:
1551 return *(int *) option->flag_var != 0;
1552
1553 case CLVC_EQUAL:
1554 return *(int *) option->flag_var == option->var_value;
1555
1556 case CLVC_BIT_CLEAR:
1557 return (*(int *) option->flag_var & option->var_value) == 0;
1558
1559 case CLVC_BIT_SET:
1560 return (*(int *) option->flag_var & option->var_value) != 0;
1561
1562 case CLVC_STRING:
1563 break;
1564 }
1565 return -1;
1566 }
1567
1568 /* Fill STATE with the current state of option OPTION. Return true if
1569 there is some state to store. */
1570
1571 bool
1572 get_option_state (int option, struct cl_option_state *state)
1573 {
1574 if (cl_options[option].flag_var == 0)
1575 return false;
1576
1577 switch (cl_options[option].var_type)
1578 {
1579 case CLVC_BOOLEAN:
1580 case CLVC_EQUAL:
1581 state->data = cl_options[option].flag_var;
1582 state->size = sizeof (int);
1583 break;
1584
1585 case CLVC_BIT_CLEAR:
1586 case CLVC_BIT_SET:
1587 state->ch = option_enabled (option);
1588 state->data = &state->ch;
1589 state->size = 1;
1590 break;
1591
1592 case CLVC_STRING:
1593 state->data = *(const char **) cl_options[option].flag_var;
1594 if (state->data == 0)
1595 state->data = "";
1596 state->size = strlen (state->data) + 1;
1597 break;
1598 }
1599 return true;
1600 }