(read_braced_string): Check for EOF. If encountered issue an error message.
[official-gcc.git] / gcc / opts.c
blob2712346149f09f1833ab6b6c343bbf059f94d3c7
1 /* Command line option handling.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "ggc.h"
29 #include "output.h"
30 #include "langhooks.h"
31 #include "opts.h"
32 #include "options.h"
33 #include "flags.h"
34 #include "toplev.h"
35 #include "params.h"
36 #include "diagnostic.h"
38 /* Value of the -G xx switch, and whether it was passed or not. */
39 unsigned HOST_WIDE_INT g_switch_value;
40 bool g_switch_set;
42 /* True if we should exit after parsing options. */
43 bool exit_after_options;
45 /* If -version. */
46 bool version_flag;
48 /* Print various extra warnings. -W/-Wextra. */
49 bool extra_warnings;
51 /* Don't print warning messages. -w. */
52 bool inhibit_warnings;
54 /* Treat warnings as errors. -Werror. */
55 bool warnings_are_errors;
57 /* Warn if a function returns an aggregate, since there are often
58 incompatible calling conventions for doing this. */
59 bool warn_aggregate_return;
61 /* Nonzero means warn about pointer casts that increase the required
62 alignment of the target type (and might therefore lead to a crash
63 due to a misaligned access). */
64 bool warn_cast_align;
66 /* Nonzero means warn about uses of __attribute__((deprecated))
67 declarations. */
68 bool warn_deprecated_decl = true;
70 /* Warn when an optimization pass is disabled. */
71 bool warn_disabled_optimization;
73 /* Nonzero means warn if inline function is too large. */
74 bool warn_inline;
76 /* True to warn about any objects definitions whose size is larger
77 than N bytes. Also want about function definitions whose returned
78 values are larger than N bytes, where N is `larger_than_size'. */
79 bool warn_larger_than;
80 HOST_WIDE_INT larger_than_size;
82 /* Warn about functions which might be candidates for attribute noreturn. */
83 bool warn_missing_noreturn;
85 /* True to warn about code which is never reached. */
86 bool warn_notreached;
88 /* Warn if packed attribute on struct is unnecessary and inefficient. */
89 bool warn_packed;
91 /* Warn when gcc pads a structure to an alignment boundary. */
92 bool warn_padded;
94 /* True means warn about all declarations which shadow others. */
95 bool warn_shadow;
97 /* Nonzero means warn about constructs which might not be
98 strict-aliasing safe. */
99 bool warn_strict_aliasing;
101 /* True to warn if a switch on an enum, that does not have a default
102 case, fails to have a case for every enum value. */
103 bool warn_switch;
105 /* Warn if a switch does not have a default case. */
106 bool warn_switch_default;
108 /* Warn if a switch on an enum fails to have a case for every enum
109 value (regardless of the presence or otherwise of a default case). */
110 bool warn_switch_enum;
112 /* Don't suppress warnings from system headers. -Wsystem-headers. */
113 bool warn_system_headers;
115 /* True to warn about variables used before they are initialized. */
116 int warn_uninitialized;
118 /* True to warn about unused variables, functions et.al. */
119 bool warn_unused_function;
120 bool warn_unused_label;
121 bool warn_unused_parameter;
122 bool warn_unused_variable;
123 bool warn_unused_value;
125 /* Hack for cooperation between set_Wunused and set_Wextra. */
126 static bool maybe_warn_unused_parameter;
128 static size_t find_opt (const char *, int);
129 static int common_handle_option (size_t scode, const char *arg, int value);
130 static void handle_param (const char *);
131 static void set_Wextra (int);
133 /* Perform a binary search to find which option the command-line INPUT
134 matches. Returns its index in the option array, and N_OPTS
135 (cl_options_count) on failure.
137 This routine is quite subtle. A normal binary search is not good
138 enough because some options can be suffixed with an argument, and
139 multiple sub-matches can occur, e.g. input of "-pedantic" matching
140 the initial substring of "-pedantic-errors".
142 A more complicated example is -gstabs. It should match "-g" with
143 an argument of "stabs". Suppose, however, that the number and list
144 of switches are such that the binary search tests "-gen-decls"
145 before having tested "-g". This doesn't match, and as "-gen-decls"
146 is less than "-gstabs", it will become the lower bound of the
147 binary search range, and "-g" will never be seen. To resolve this
148 issue, opts.sh makes "-gen-decls" point, via the back_chain member,
149 to "-g" so that failed searches that end between "-gen-decls" and
150 the lexicographically subsequent switch know to go back and see if
151 "-g" causes a match (which it does in this example).
153 This search is done in such a way that the longest match for the
154 front end in question wins. If there is no match for the current
155 front end, the longest match for a different front end is returned
156 (or N_OPTS if none) and the caller emits an error message. */
157 static size_t
158 find_opt (const char *input, int lang_mask)
160 size_t mn, mx, md, opt_len;
161 size_t match_wrong_lang;
162 int comp;
164 mn = 0;
165 mx = cl_options_count;
167 /* Find mn such this lexicographical inequality holds:
168 cl_options[mn] <= input < cl_options[mn + 1]. */
169 while (mx - mn > 1)
171 md = (mn + mx) / 2;
172 opt_len = cl_options[md].opt_len;
173 comp = strncmp (input, cl_options[md].opt_text, opt_len);
175 if (comp < 0)
176 mx = md;
177 else
178 mn = md;
181 /* This is the switch that is the best match but for a different
182 front end, or cl_options_count if there is no match at all. */
183 match_wrong_lang = cl_options_count;
185 /* Backtrace the chain of possible matches, returning the longest
186 one, if any, that fits best. With current GCC switches, this
187 loop executes at most twice. */
190 const struct cl_option *opt = &cl_options[mn];
192 /* Is this switch a prefix of the input? */
193 if (!strncmp (input, opt->opt_text, opt->opt_len))
195 /* If language is OK, and the match is exact or the switch
196 takes a joined argument, return it. */
197 if ((opt->flags & lang_mask)
198 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
199 return mn;
201 /* If we haven't remembered a prior match, remember this
202 one. Any prior match is necessarily better. */
203 if (match_wrong_lang != cl_options_count)
204 match_wrong_lang = mn;
207 /* Try the next possibility. This is cl_options_count if there
208 are no more. */
209 mn = opt->back_chain;
211 while (mn != cl_options_count);
213 /* Return the best wrong match, or cl_options_count if none. */
214 return match_wrong_lang;
217 /* If ARG is a non-negative integer made up solely of digits, return its
218 value, otherwise return -1. */
219 static int
220 integral_argument (const char *arg)
222 const char *p = arg;
224 while (*p && ISDIGIT (*p))
225 p++;
227 if (*p == '\0')
228 return atoi (arg);
230 return -1;
233 /* Handle the switch beginning at ARGV, with ARGC remaining. */
235 handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
237 size_t opt_index;
238 const char *opt, *arg = 0;
239 char *dup = 0;
240 int value = 1;
241 int result = 0;
242 const struct cl_option *option;
244 opt = argv[0];
246 /* Interpret "-" or a non-switch as a file name. */
247 if (opt[0] != '-' || opt[1] == '\0')
249 opt_index = cl_options_count;
250 arg = opt;
251 main_input_filename = opt;
252 result = (*lang_hooks.handle_option) (opt_index, arg, value);
254 else
256 /* Drop the "no-" from negative switches. */
257 if ((opt[1] == 'W' || opt[1] == 'f')
258 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
260 size_t len = strlen (opt) - 3;
262 dup = xmalloc (len + 1);
263 dup[0] = '-';
264 dup[1] = opt[1];
265 memcpy (dup + 2, opt + 5, len - 2 + 1);
266 opt = dup;
267 value = 0;
270 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
271 if (opt_index == cl_options_count)
272 goto done;
274 option = &cl_options[opt_index];
276 /* Reject negative form of switches that don't take negatives. */
277 if (!value && (option->flags & CL_REJECT_NEGATIVE))
278 goto done;
280 /* We've recognized this switch. */
281 result = 1;
283 /* Sort out any argument the switch takes. */
284 if (option->flags & CL_JOINED)
286 /* Have arg point to the original switch. This is because
287 some code, such as disable_builtin_function, expects its
288 argument to be persistent until the program exits. */
289 arg = argv[0] + cl_options[opt_index].opt_len + 1;
290 if (!value)
291 arg += strlen ("no-");
293 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
295 if (option->flags & CL_SEPARATE)
297 arg = argv[1];
298 result = 2;
300 else
301 /* Missing argument. */
302 arg = NULL;
305 else if (option->flags & CL_SEPARATE)
307 arg = argv[1];
308 result = 2;
311 /* If the switch takes an integer, convert it. */
312 if (arg && (option->flags & CL_UINTEGER))
314 value = integral_argument (arg);
315 if (value == -1)
317 error ("argument to \"-%s\" should be a non-negative integer",
318 option->opt_text);
319 goto done;
323 if (option->flags & lang_mask)
324 if ((*lang_hooks.handle_option) (opt_index, arg, value) == 0)
325 result = 0;
327 if (result && (option->flags & CL_COMMON))
328 if (common_handle_option (opt_index, arg, value) == 0)
329 result = 0;
332 done:
333 if (dup)
334 free (dup);
335 return result;
338 /* Handle target- and language-independent options. Return zero to
339 generate an "unknown option" message. */
340 static int
341 common_handle_option (size_t scode, const char *arg,
342 int value ATTRIBUTE_UNUSED)
344 const struct cl_option *option = &cl_options[scode];
345 enum opt_code code = (enum opt_code) scode;
347 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
349 error ("missing argument to \"-%s\"", option->opt_text);
350 return 1;
353 switch (code)
355 default:
356 abort ();
358 case OPT__help:
359 display_help ();
360 exit_after_options = true;
361 break;
363 case OPT__param:
364 handle_param (arg);
365 break;
367 case OPT__target_help:
368 display_target_options ();
369 exit_after_options = true;
370 break;
372 case OPT__version:
373 print_version (stderr, "");
374 exit_after_options = true;
375 break;
377 case OPT_G:
378 g_switch_value = value;
379 g_switch_set = true;
380 break;
382 case OPT_O:
383 case OPT_Os:
384 /* Currently handled in a prescan. */
385 break;
387 case OPT_W:
388 /* For backward compatibility, -W is the same as -Wextra. */
389 set_Wextra (value);
390 break;
392 case OPT_Waggregate_return:
393 warn_aggregate_return = value;
394 break;
396 case OPT_Wcast_align:
397 warn_cast_align = value;
398 break;
400 case OPT_Wdeprecated_declarations:
401 warn_deprecated_decl = value;
403 case OPT_Wdisabled_optimization:
404 warn_disabled_optimization = value;
405 break;
407 case OPT_Werror:
408 warnings_are_errors = value;
409 break;
411 case OPT_Wextra:
412 set_Wextra (value);
413 break;
415 case OPT_Winline:
416 warn_inline = value;
417 break;
419 case OPT_Wlarger_than_:
420 larger_than_size = value;
421 warn_larger_than = value != -1;
422 break;
424 case OPT_Wmissing_noreturn:
425 warn_missing_noreturn = value;
426 break;
428 case OPT_Wpacked:
429 warn_packed = value;
430 break;
432 case OPT_Wpadded:
433 warn_padded = value;
434 break;
436 case OPT_Wshadow:
437 warn_shadow = value;
438 break;
440 case OPT_Wstrict_aliasing:
441 warn_strict_aliasing = value;
442 break;
444 case OPT_Wswitch:
445 warn_switch = value;
446 break;
448 case OPT_Wswitch_default:
449 warn_switch_default = value;
450 break;
452 case OPT_Wswitch_enum:
453 warn_switch_enum = value;
454 break;
456 case OPT_Wsystem_headers:
457 warn_system_headers = value;
458 break;
460 case OPT_Wuninitialized:
461 warn_uninitialized = value;
462 break;
464 case OPT_Wunreachable_code:
465 warn_notreached = value;
466 break;
468 case OPT_Wunused:
469 set_Wunused (value);
470 break;
472 case OPT_Wunused_function:
473 warn_unused_function = value;
474 break;
476 case OPT_Wunused_label:
477 warn_unused_label = value;
478 break;
480 case OPT_Wunused_parameter:
481 warn_unused_parameter = value;
482 break;
484 case OPT_Wunused_value:
485 warn_unused_value = value;
486 break;
488 case OPT_Wunused_variable:
489 warn_unused_variable = value;
490 break;
492 case OPT_aux_info:
493 case OPT_aux_info_:
494 aux_info_file_name = arg;
495 flag_gen_aux_info = 1;
496 break;
498 case OPT_auxbase:
499 aux_base_name = arg;
500 break;
502 case OPT_auxbase_strip:
504 char *tmp = xstrdup (arg);
505 strip_off_ending (tmp, strlen (tmp));
506 if (tmp[0])
507 aux_base_name = tmp;
509 break;
511 case OPT_d:
512 decode_d_option (arg);
513 break;
515 case OPT_dumpbase:
516 dump_base_name = arg;
517 break;
519 case OPT_fPIC:
520 flag_pic = value + value;
521 break;
523 case OPT_fPIE:
524 flag_pie = value + value;
525 break;
527 case OPT_falign_functions:
528 case OPT_falign_functions_:
529 align_functions = value;
530 break;
532 case OPT_falign_jumps:
533 case OPT_falign_jumps_:
534 align_jumps = value;
535 break;
537 case OPT_falign_labels:
538 case OPT_falign_labels_:
539 align_labels = value;
540 break;
542 case OPT_falign_loops:
543 case OPT_falign_loops_:
544 align_loops = value;
545 break;
547 case OPT_fargument_alias:
548 flag_argument_noalias = !value;
549 break;
551 case OPT_fargument_noalias:
552 flag_argument_noalias = value;
553 break;
555 case OPT_fargument_noalias_global:
556 flag_argument_noalias = value + value;
557 break;
559 case OPT_fasynchronous_unwind_tables:
560 flag_asynchronous_unwind_tables = value;
561 break;
563 case OPT_fbounds_check:
564 flag_bounds_check = value;
565 break;
567 case OPT_fbranch_count_reg:
568 flag_branch_on_count_reg = value;
569 break;
571 case OPT_fbranch_probabilities:
572 flag_branch_probabilities = value;
573 break;
575 case OPT_fbranch_target_load_optimize:
576 flag_branch_target_load_optimize = value;
577 break;
579 case OPT_fbranch_target_load_optimize2:
580 flag_branch_target_load_optimize2 = value;
581 break;
583 case OPT_fcall_used_:
584 fix_register (arg, 0, 1);
585 break;
587 case OPT_fcall_saved_:
588 fix_register (arg, 0, 0);
589 break;
591 case OPT_fcaller_saves:
592 flag_caller_saves = value;
593 break;
595 case OPT_fcommon:
596 flag_no_common = !value;
597 break;
599 case OPT_fcprop_registers:
600 flag_cprop_registers = value;
601 break;
603 case OPT_fcrossjumping:
604 flag_crossjumping = value;
605 break;
607 case OPT_fcse_follow_jumps:
608 flag_cse_follow_jumps = value;
609 break;
611 case OPT_fcse_skip_blocks:
612 flag_cse_skip_blocks = value;
613 break;
615 case OPT_fdata_sections:
616 flag_data_sections = value;
617 break;
619 case OPT_fdefer_pop:
620 flag_defer_pop = value;
621 break;
623 case OPT_fdelayed_branch:
624 flag_delayed_branch = value;
625 break;
627 case OPT_fdelete_null_pointer_checks:
628 flag_delete_null_pointer_checks = value;
629 break;
631 case OPT_fdiagnostics_show_location_:
632 if (!strcmp (arg, "once"))
633 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
634 else if (!strcmp (arg, "every-line"))
635 diagnostic_prefixing_rule (global_dc)
636 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
637 else
638 return 0;
639 break;
641 case OPT_fdump_unnumbered:
642 flag_dump_unnumbered = value;
643 break;
645 case OPT_feliminate_dwarf2_dups:
646 flag_eliminate_dwarf2_dups = value;
647 break;
649 case OPT_feliminate_unused_debug_types:
650 flag_eliminate_unused_debug_types = value;
651 break;
653 case OPT_fexceptions:
654 flag_exceptions = value;
655 break;
657 case OPT_fexpensive_optimizations:
658 flag_expensive_optimizations = value;
659 break;
661 case OPT_ffast_math:
662 set_fast_math_flags (value);
663 break;
665 case OPT_ffinite_math_only:
666 flag_finite_math_only = value;
667 break;
669 case OPT_ffixed_:
670 fix_register (arg, 1, 1);
671 break;
673 case OPT_ffunction_cse:
674 flag_no_function_cse = !value;
675 break;
677 case OPT_ffloat_store:
678 flag_float_store = value;
679 break;
681 case OPT_fforce_addr:
682 flag_force_addr = value;
683 break;
685 case OPT_fforce_mem:
686 flag_force_mem = value;
687 break;
689 case OPT_ffunction_sections:
690 flag_function_sections = value;
691 break;
693 case OPT_fgcse:
694 flag_gcse = value;
695 break;
697 case OPT_fgcse_lm:
698 flag_gcse_lm = value;
699 break;
701 case OPT_fgcse_sm:
702 flag_gcse_sm = value;
703 break;
705 case OPT_fgnu_linker:
706 flag_gnu_linker = value;
707 break;
709 case OPT_fguess_branch_probability:
710 flag_guess_branch_prob = value;
711 break;
713 case OPT_fident:
714 flag_no_ident = !value;
715 break;
717 case OPT_fif_conversion:
718 flag_if_conversion = value;
719 break;
721 case OPT_fif_conversion2:
722 flag_if_conversion2 = value;
723 break;
725 case OPT_finhibit_size_directive:
726 flag_inhibit_size_directive = value;
727 break;
729 case OPT_finline:
730 flag_no_inline = !value;
731 break;
733 case OPT_finline_functions:
734 flag_inline_functions = value;
735 break;
737 case OPT_finline_limit_:
738 case OPT_finline_limit_eq:
739 set_param_value ("max-inline-insns", value);
740 set_param_value ("max-inline-insns-single", value / 2);
741 set_param_value ("max-inline-insns-auto", value / 2);
742 set_param_value ("max-inline-insns-rtl", value);
743 if (value / 4 < MIN_INLINE_INSNS)
745 if (value / 4 > 10)
746 set_param_value ("min-inline-insns", value / 4);
747 else
748 set_param_value ("min-inline-insns", 10);
750 break;
752 case OPT_finstrument_functions:
753 flag_instrument_function_entry_exit = value;
754 break;
756 case OPT_fkeep_inline_functions:
757 flag_keep_inline_functions =value;
758 break;
760 case OPT_fkeep_static_consts:
761 flag_keep_static_consts = value;
762 break;
764 case OPT_fleading_underscore:
765 flag_leading_underscore = value;
766 break;
768 case OPT_floop_optimize:
769 flag_loop_optimize = value;
770 break;
772 case OPT_fmath_errno:
773 flag_errno_math = value;
774 break;
776 case OPT_fmem_report:
777 mem_report = value;
778 break;
780 case OPT_fmerge_all_constants:
781 flag_merge_constants = value + value;
782 break;
784 case OPT_fmerge_constants:
785 flag_merge_constants = value;
786 break;
788 case OPT_fmessage_length_:
789 output_set_maximum_length (&global_dc->buffer, value);
790 break;
792 case OPT_fmove_all_movables:
793 flag_move_all_movables = value;
794 break;
796 case OPT_fnew_ra:
797 flag_new_regalloc = value;
798 break;
800 case OPT_fnon_call_exceptions:
801 flag_non_call_exceptions = value;
802 break;
804 case OPT_fold_unroll_all_loops:
805 flag_old_unroll_all_loops = value;
806 break;
808 case OPT_fold_unroll_loops:
809 flag_old_unroll_loops = value;
810 break;
812 case OPT_fomit_frame_pointer:
813 flag_omit_frame_pointer = value;
814 break;
816 case OPT_foptimize_register_move:
817 flag_regmove = value;
818 break;
820 case OPT_foptimize_sibling_calls:
821 flag_optimize_sibling_calls = value;
822 break;
824 case OPT_fpack_struct:
825 flag_pack_struct = value;
826 break;
828 case OPT_fpeel_loops:
829 flag_peel_loops = value;
830 break;
832 case OPT_fpcc_struct_return:
833 flag_pcc_struct_return = value;
834 break;
836 case OPT_fpeephole:
837 flag_no_peephole = !value;
838 break;
840 case OPT_fpeephole2:
841 flag_peephole2 = value;
842 break;
844 case OPT_fpic:
845 flag_pic = value;
846 break;
848 case OPT_fpie:
849 flag_pie = value;
850 break;
852 case OPT_fprefetch_loop_arrays:
853 flag_prefetch_loop_arrays = value;
854 break;
856 case OPT_fprofile:
857 profile_flag = value;
858 break;
860 case OPT_fprofile_arcs:
861 profile_arc_flag = value;
862 break;
864 case OPT_frandom_seed:
865 /* The real switch is -fno-random-seed. */
866 if (value)
867 return 0;
868 flag_random_seed = NULL;
869 break;
871 case OPT_frandom_seed_:
872 flag_random_seed = arg;
873 break;
875 case OPT_freduce_all_givs:
876 flag_reduce_all_givs = value;
877 break;
879 case OPT_freg_struct_return:
880 flag_pcc_struct_return = !value;
881 break;
883 case OPT_fregmove:
884 flag_regmove = value;
885 break;
887 case OPT_frename_registers:
888 flag_rename_registers = value;
889 break;
891 case OPT_freorder_blocks:
892 flag_reorder_blocks = value;
893 break;
895 case OPT_freorder_functions:
896 flag_reorder_functions = value;
897 break;
899 case OPT_frerun_cse_after_loop:
900 flag_rerun_cse_after_loop = value;
901 break;
903 case OPT_frerun_loop_opt:
904 flag_rerun_loop_opt = value;
905 break;
907 case OPT_fsched_interblock:
908 flag_schedule_interblock= value;
909 break;
911 case OPT_fsched_spec:
912 flag_schedule_speculative = value;
913 break;
915 case OPT_fsched_spec_load:
916 flag_schedule_speculative_load = value;
917 break;
919 case OPT_fsched_spec_load_dangerous:
920 flag_schedule_speculative_load_dangerous = value;
921 break;
923 case OPT_fsched_verbose_:
924 #ifdef INSN_SCHEDULING
925 fix_sched_param ("verbose", arg);
926 break;
927 #else
928 return 0;
929 #endif
931 case OPT_fsched2_use_superblocks:
932 flag_sched2_use_superblocks = value;
933 break;
935 case OPT_fsched2_use_traces:
936 flag_sched2_use_traces = value;
937 break;
939 case OPT_fschedule_insns:
940 flag_schedule_insns = value;
941 break;
943 case OPT_fschedule_insns2:
944 flag_schedule_insns_after_reload = value;
945 break;
947 case OPT_fshared_data:
948 flag_shared_data = value;
949 break;
951 case OPT_fsignaling_nans:
952 flag_signaling_nans = value;
953 break;
955 case OPT_fsingle_precision_constant:
956 flag_single_precision_constant = value;
957 break;
959 case OPT_fssa:
960 flag_ssa = value;
961 break;
963 case OPT_fssa_ccp:
964 flag_ssa_ccp = value;
965 break;
967 case OPT_fssa_dce:
968 flag_ssa_dce = value;
969 break;
971 case OPT_fstack_check:
972 flag_stack_check = value;
973 break;
975 case OPT_fstack_limit:
976 /* The real switch is -fno-stack-limit. */
977 if (value)
978 return 0;
979 stack_limit_rtx = NULL_RTX;
980 break;
982 case OPT_fstack_limit_register_:
984 int reg = decode_reg_name (arg);
985 if (reg < 0)
986 error ("unrecognized register name \"%s\"", arg);
987 else
988 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
990 break;
992 case OPT_fstack_limit_symbol_:
993 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
994 break;
996 case OPT_fstrength_reduce:
997 flag_strength_reduce = value;
998 break;
1000 case OPT_fstrict_aliasing:
1001 flag_strict_aliasing = value;
1002 break;
1004 case OPT_fsyntax_only:
1005 flag_syntax_only = value;
1006 break;
1008 case OPT_ftest_coverage:
1009 flag_test_coverage = value;
1010 break;
1012 case OPT_fthread_jumps:
1013 flag_thread_jumps = value;
1014 break;
1016 case OPT_ftime_report:
1017 time_report = value;
1019 case OPT_ftls_model_:
1020 if (!strcmp (arg, "global-dynamic"))
1021 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1022 else if (!strcmp (arg, "local-dynamic"))
1023 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1024 else if (!strcmp (arg, "initial-exec"))
1025 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1026 else if (!strcmp (arg, "local-exec"))
1027 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1028 else
1029 warning ("unknown tls-model \"%s\"", arg);
1030 break;
1032 case OPT_ftracer:
1033 flag_tracer = value;
1034 break;
1036 case OPT_ftrapping_math:
1037 flag_trapping_math = value;
1038 break;
1040 case OPT_ftrapv:
1041 flag_trapv = value;
1042 break;
1044 case OPT_funit_at_a_time:
1045 flag_unit_at_a_time = value;
1046 break;
1048 case OPT_funroll_all_loops:
1049 flag_unroll_all_loops = value;
1050 break;
1052 case OPT_funroll_loops:
1053 flag_unroll_loops = value;
1054 break;
1056 case OPT_funsafe_math_optimizations:
1057 flag_unsafe_math_optimizations = value;
1058 break;
1060 case OPT_funswitch_loops:
1061 flag_unswitch_loops = value;
1062 break;
1064 case OPT_funwind_tables:
1065 flag_unwind_tables = value;
1066 break;
1068 case OPT_fverbose_asm:
1069 flag_verbose_asm = value;
1070 break;
1072 case OPT_fwrapv:
1073 flag_wrapv = value;
1074 break;
1076 case OPT_fwritable_strings:
1077 flag_writable_strings = value;
1078 break;
1080 case OPT_fzero_initialized_in_bss:
1081 flag_zero_initialized_in_bss = value;
1082 break;
1084 case OPT_g:
1085 decode_g_option (arg);
1086 break;
1088 case OPT_m:
1089 set_target_switch (arg);
1090 break;
1092 case OPT_o:
1093 asm_file_name = arg;
1094 break;
1096 case OPT_p:
1097 profile_flag = 1;
1098 break;
1100 case OPT_pedantic:
1101 pedantic = 1;
1102 break;
1104 case OPT_pedantic_errors:
1105 flag_pedantic_errors = pedantic = 1;
1106 break;
1108 case OPT_quiet:
1109 quiet_flag = 1;
1110 break;
1112 case OPT_version:
1113 version_flag = 1;
1114 break;
1116 case OPT_w:
1117 inhibit_warnings = true;
1118 break;
1121 return 1;
1124 /* Handle --param NAME=VALUE. */
1125 static void
1126 handle_param (const char *carg)
1128 char *equal, *arg;
1129 int value;
1131 arg = xstrdup (carg);
1132 equal = strchr (arg, '=');
1133 if (!equal)
1134 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1135 else
1137 value = integral_argument (equal + 1);
1138 if (value == -1)
1139 error ("invalid --param value `%s'", equal + 1);
1140 else
1142 *equal = '\0';
1143 set_param_value (arg, value);
1147 free (arg);
1150 /* Handle -W and -Wextra. */
1151 static void
1152 set_Wextra (int setting)
1154 extra_warnings = setting;
1155 warn_unused_value = setting;
1156 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1158 /* We save the value of warn_uninitialized, since if they put
1159 -Wuninitialized on the command line, we need to generate a
1160 warning about not using it without also specifying -O. */
1161 if (setting == 0)
1162 warn_uninitialized = 0;
1163 else if (warn_uninitialized != 1)
1164 warn_uninitialized = 2;
1167 /* Initialize unused warning flags. */
1168 void
1169 set_Wunused (int setting)
1171 warn_unused_function = setting;
1172 warn_unused_label = setting;
1173 /* Unused function parameter warnings are reported when either
1174 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1175 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1176 otherwise set maybe_warn_extra_parameter, which will be picked up
1177 by set_Wextra. */
1178 maybe_warn_unused_parameter = setting;
1179 warn_unused_parameter = (setting && extra_warnings);
1180 warn_unused_variable = setting;
1181 warn_unused_value = setting;
1184 /* The following routines are useful in setting all the flags that
1185 -ffast-math and -fno-fast-math imply. */
1186 void
1187 set_fast_math_flags (int set)
1189 flag_trapping_math = !set;
1190 flag_unsafe_math_optimizations = set;
1191 flag_finite_math_only = set;
1192 flag_errno_math = !set;
1193 if (set)
1194 flag_signaling_nans = 0;
1197 /* Return true iff flags are set as if -ffast-math. */
1198 bool
1199 fast_math_flags_set_p (void)
1201 return (!flag_trapping_math
1202 && flag_unsafe_math_optimizations
1203 && flag_finite_math_only
1204 && !flag_errno_math);