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