comparison gcc/opts-common.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Command line option handling. 1 /* Command line option handling.
2 Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc. 2 Copyright (C) 2006-2017 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
20 #include "config.h" 20 #include "config.h"
21 #include "system.h" 21 #include "system.h"
22 #include "intl.h" 22 #include "intl.h"
23 #include "coretypes.h" 23 #include "coretypes.h"
24 #include "opts.h" 24 #include "opts.h"
25 #include "flags.h" 25 #include "options.h"
26 #include "diagnostic.h" 26 #include "diagnostic.h"
27 #include "spellcheck.h"
27 28
28 static void prune_options (struct cl_decoded_option **, unsigned int *); 29 static void prune_options (struct cl_decoded_option **, unsigned int *);
30
31 /* An option that is undocumented, that takes a joined argument, and
32 that doesn't fit any of the classes of uses (language/common,
33 driver, target) is assumed to be a prefix used to catch
34 e.g. negated options, and stop them from being further shortened to
35 a prefix that could use the negated option as an argument. For
36 example, we want -gno-statement-frontiers to be taken as a negation
37 of -gstatement-frontiers, but without catching the gno- prefix and
38 signaling it's to be used for option remapping, it would end up
39 backtracked to g with no-statemnet-frontiers as the debug level. */
40
41 static bool
42 remapping_prefix_p (const struct cl_option *opt)
43 {
44 return opt->flags & CL_UNDOCUMENTED
45 && opt->flags & CL_JOINED
46 && !(opt->flags & (CL_DRIVER | CL_TARGET | CL_COMMON | CL_LANG_ALL));
47 }
29 48
30 /* Perform a binary search to find which option the command-line INPUT 49 /* Perform a binary search to find which option the command-line INPUT
31 matches. Returns its index in the option array, and 50 matches. Returns its index in the option array, and
32 OPT_SPECIAL_unknown on failure. 51 OPT_SPECIAL_unknown on failure.
33 52
50 This search is done in such a way that the longest match for the 69 This search is done in such a way that the longest match for the
51 front end in question wins. If there is no match for the current 70 front end in question wins. If there is no match for the current
52 front end, the longest match for a different front end is returned 71 front end, the longest match for a different front end is returned
53 (or N_OPTS if none) and the caller emits an error message. */ 72 (or N_OPTS if none) and the caller emits an error message. */
54 size_t 73 size_t
55 find_opt (const char *input, int lang_mask) 74 find_opt (const char *input, unsigned int lang_mask)
56 { 75 {
57 size_t mn, mn_orig, mx, md, opt_len; 76 size_t mn, mn_orig, mx, md, opt_len;
58 size_t match_wrong_lang; 77 size_t match_wrong_lang;
59 int comp; 78 int comp;
60 79
94 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED))) 113 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
95 { 114 {
96 /* If language is OK, return it. */ 115 /* If language is OK, return it. */
97 if (opt->flags & lang_mask) 116 if (opt->flags & lang_mask)
98 return mn; 117 return mn;
118
119 if (remapping_prefix_p (opt))
120 return OPT_SPECIAL_unknown;
99 121
100 /* If we haven't remembered a prior match, remember this 122 /* If we haven't remembered a prior match, remember this
101 one. Any prior match is necessarily better. */ 123 one. Any prior match is necessarily better. */
102 if (match_wrong_lang == OPT_SPECIAL_unknown) 124 if (match_wrong_lang == OPT_SPECIAL_unknown)
103 match_wrong_lang = mn; 125 match_wrong_lang = mn;
145 167
146 /* Return the best wrong match, or OPT_SPECIAL_unknown if none. */ 168 /* Return the best wrong match, or OPT_SPECIAL_unknown if none. */
147 return match_wrong_lang; 169 return match_wrong_lang;
148 } 170 }
149 171
150 /* If ARG is a non-negative integer made up solely of digits, return its 172 /* If ARG is a non-negative decimal or hexadecimal integer, return its
151 value, otherwise return -1. */ 173 value, otherwise return -1. */
152 174
153 int 175 int
154 integral_argument (const char *arg) 176 integral_argument (const char *arg)
155 { 177 {
158 while (*p && ISDIGIT (*p)) 180 while (*p && ISDIGIT (*p))
159 p++; 181 p++;
160 182
161 if (*p == '\0') 183 if (*p == '\0')
162 return atoi (arg); 184 return atoi (arg);
185
186 /* It wasn't a decimal number - try hexadecimal. */
187 if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'))
188 {
189 p = arg + 2;
190 while (*p && ISXDIGIT (*p))
191 p++;
192
193 if (p != arg + 2 && *p == '\0')
194 return strtol (arg, NULL, 16);
195 }
163 196
164 return -1; 197 return -1;
165 } 198 }
166 199
167 /* Return whether OPTION is OK for the language given by 200 /* Return whether OPTION is OK for the language given by
210 } 243 }
211 244
212 return false; 245 return false;
213 } 246 }
214 247
248 /* Look up ARG in the enum used by option OPT_INDEX for language
249 LANG_MASK, returning true and storing the value in *VALUE if found,
250 and returning false without modifying *VALUE if not found. */
251
252 bool
253 opt_enum_arg_to_value (size_t opt_index, const char *arg, int *value,
254 unsigned int lang_mask)
255 {
256 const struct cl_option *option = &cl_options[opt_index];
257
258 gcc_assert (option->var_type == CLVC_ENUM);
259
260 return enum_arg_to_value (cl_enums[option->var_enum].values, arg,
261 value, lang_mask);
262 }
263
215 /* Look of VALUE in ENUM_ARGS for language LANG_MASK and store the 264 /* Look of VALUE in ENUM_ARGS for language LANG_MASK and store the
216 corresponding string in *ARGP, returning true if the found string 265 corresponding string in *ARGP, returning true if the found string
217 was marked as canonical, false otherwise. If VALUE is not found 266 was marked as canonical, false otherwise. If VALUE is not found
218 (which may be the case for uninitialized values if the relevant 267 (which may be the case for uninitialized values if the relevant
219 option has not been passed), set *ARGP to NULL and return 268 option has not been passed), set *ARGP to NULL and return
255 { 304 {
256 const struct cl_option *option = &cl_options[opt_index]; 305 const struct cl_option *option = &cl_options[opt_index];
257 const char *opt_text = option->opt_text; 306 const char *opt_text = option->opt_text;
258 307
259 if (value == 0 308 if (value == 0
260 && !(option->flags & CL_REJECT_NEGATIVE) 309 && !option->cl_reject_negative
261 && (opt_text[1] == 'W' || opt_text[1] == 'f' || opt_text[1] == 'm')) 310 && (opt_text[1] == 'W' || opt_text[1] == 'f'
262 { 311 || opt_text[1] == 'g' || opt_text[1] == 'm'))
263 char *t = XNEWVEC (char, option->opt_len + 5); 312 {
313 char *t = XOBNEWVEC (&opts_obstack, char, option->opt_len + 5);
264 t[0] = '-'; 314 t[0] = '-';
265 t[1] = opt_text[1]; 315 t[1] = opt_text[1];
266 t[2] = 'n'; 316 t[2] = 'n';
267 t[3] = 'o'; 317 t[3] = 'o';
268 t[4] = '-'; 318 t[4] = '-';
274 decoded->canonical_option[3] = NULL; 324 decoded->canonical_option[3] = NULL;
275 325
276 if (arg) 326 if (arg)
277 { 327 {
278 if ((option->flags & CL_SEPARATE) 328 if ((option->flags & CL_SEPARATE)
279 && !(option->flags & CL_SEPARATE_ALIAS)) 329 && !option->cl_separate_alias)
280 { 330 {
281 decoded->canonical_option[0] = opt_text; 331 decoded->canonical_option[0] = opt_text;
282 decoded->canonical_option[1] = arg; 332 decoded->canonical_option[1] = arg;
283 decoded->canonical_option_num_elements = 2; 333 decoded->canonical_option_num_elements = 2;
284 } 334 }
285 else 335 else
286 { 336 {
287 gcc_assert (option->flags & CL_JOINED); 337 gcc_assert (option->flags & CL_JOINED);
288 decoded->canonical_option[0] = concat (opt_text, arg, NULL); 338 decoded->canonical_option[0] = opts_concat (opt_text, arg, NULL);
289 decoded->canonical_option[1] = NULL; 339 decoded->canonical_option[1] = NULL;
290 decoded->canonical_option_num_elements = 1; 340 decoded->canonical_option_num_elements = 1;
291 } 341 }
292 } 342 }
293 else 343 else
319 }; 369 };
320 static const struct option_map option_map[] = 370 static const struct option_map option_map[] =
321 { 371 {
322 { "-Wno-", NULL, "-W", false, true }, 372 { "-Wno-", NULL, "-W", false, true },
323 { "-fno-", NULL, "-f", false, true }, 373 { "-fno-", NULL, "-f", false, true },
374 { "-gno-", NULL, "-g", false, true },
324 { "-mno-", NULL, "-m", false, true }, 375 { "-mno-", NULL, "-m", false, true },
325 { "--debug=", NULL, "-g", false, false }, 376 { "--debug=", NULL, "-g", false, false },
326 { "--machine-", NULL, "-m", true, false }, 377 { "--machine-", NULL, "-m", true, false },
327 { "--machine-no-", NULL, "-m", false, true }, 378 { "--machine-no-", NULL, "-m", false, true },
328 { "--machine=", NULL, "-m", false, false }, 379 { "--machine=", NULL, "-m", false, false },
336 { "--warn-no-", NULL, "-W", false, true }, 387 { "--warn-no-", NULL, "-W", false, true },
337 { "--", NULL, "-f", true, false }, 388 { "--", NULL, "-f", true, false },
338 { "--no-", NULL, "-f", false, true } 389 { "--no-", NULL, "-f", false, true }
339 }; 390 };
340 391
392 /* Helper function for gcc.c's driver::suggest_option, for populating the
393 vec of suggestions for misspelled options.
394
395 option_map above provides various prefixes for spelling command-line
396 options, which decode_cmdline_option uses to map spellings of options
397 to specific options. We want to do the reverse: to find all the ways
398 that a user could validly spell an option.
399
400 Given valid OPT_TEXT (with a leading dash) for OPTION, add it and all
401 of its valid variant spellings to CANDIDATES, each without a leading
402 dash.
403
404 For example, given "-Wabi-tag", the following are added to CANDIDATES:
405 "Wabi-tag"
406 "Wno-abi-tag"
407 "-warn-abi-tag"
408 "-warn-no-abi-tag".
409
410 The added strings must be freed using free. */
411
412 void
413 add_misspelling_candidates (auto_vec<char *> *candidates,
414 const struct cl_option *option,
415 const char *opt_text)
416 {
417 gcc_assert (candidates);
418 gcc_assert (option);
419 gcc_assert (opt_text);
420 if (remapping_prefix_p (option))
421 return;
422 candidates->safe_push (xstrdup (opt_text + 1));
423 for (unsigned i = 0; i < ARRAY_SIZE (option_map); i++)
424 {
425 const char *opt0 = option_map[i].opt0;
426 const char *new_prefix = option_map[i].new_prefix;
427 size_t new_prefix_len = strlen (new_prefix);
428
429 if (option->cl_reject_negative && option_map[i].negated)
430 continue;
431
432 if (strncmp (opt_text, new_prefix, new_prefix_len) == 0)
433 {
434 char *alternative = concat (opt0 + 1, opt_text + new_prefix_len,
435 NULL);
436 candidates->safe_push (alternative);
437 }
438 }
439 }
440
341 /* Decode the switch beginning at ARGV for the language indicated by 441 /* Decode the switch beginning at ARGV for the language indicated by
342 LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into 442 LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into
343 the structure *DECODED. Returns the number of switches 443 the structure *DECODED. Returns the number of switches
344 consumed. */ 444 consumed. */
345 445
410 510
411 option = &cl_options[opt_index]; 511 option = &cl_options[opt_index];
412 512
413 /* Reject negative form of switches that don't take negatives as 513 /* Reject negative form of switches that don't take negatives as
414 unrecognized. */ 514 unrecognized. */
415 if (!value && (option->flags & CL_REJECT_NEGATIVE)) 515 if (!value && option->cl_reject_negative)
416 { 516 {
417 opt_index = OPT_SPECIAL_unknown; 517 opt_index = OPT_SPECIAL_unknown;
418 errors |= CL_ERR_NEGATIVE; 518 errors |= CL_ERR_NEGATIVE;
419 arg = argv[0]; 519 arg = argv[0];
420 goto done; 520 goto done;
422 522
423 result = extra_args + 1; 523 result = extra_args + 1;
424 warn_message = option->warn_message; 524 warn_message = option->warn_message;
425 525
426 /* Check to see if the option is disabled for this configuration. */ 526 /* Check to see if the option is disabled for this configuration. */
427 if (option->flags & CL_DISABLED) 527 if (option->cl_disabled)
428 errors |= CL_ERR_DISABLED; 528 errors |= CL_ERR_DISABLED;
429 529
430 /* Determine whether there may be a separate argument based on 530 /* Determine whether there may be a separate argument based on
431 whether this option is being processed for the driver, and, if 531 whether this option is being processed for the driver, and, if
432 so, how many such arguments. */ 532 so, how many such arguments. */
433 separate_arg_flag = ((option->flags & CL_SEPARATE) 533 separate_arg_flag = ((option->flags & CL_SEPARATE)
434 && !((option->flags & CL_NO_DRIVER_ARG) 534 && !(option->cl_no_driver_arg
435 && (lang_mask & CL_DRIVER))); 535 && (lang_mask & CL_DRIVER)));
436 separate_args = (separate_arg_flag 536 separate_args = (separate_arg_flag
437 ? ((option->flags & CL_SEPARATE_NARGS_MASK) 537 ? option->cl_separate_nargs + 1
438 >> CL_SEPARATE_NARGS_SHIFT) + 1
439 : 0); 538 : 0);
440 joined_arg_flag = (option->flags & CL_JOINED) != 0; 539 joined_arg_flag = (option->flags & CL_JOINED) != 0;
441 540
442 /* Sort out any argument the switch takes. */ 541 /* Sort out any argument the switch takes. */
443 if (joined_arg_flag) 542 if (joined_arg_flag)
445 /* Have arg point to the original switch. This is because 544 /* Have arg point to the original switch. This is because
446 some code, such as disable_builtin_function, expects its 545 some code, such as disable_builtin_function, expects its
447 argument to be persistent until the program exits. */ 546 argument to be persistent until the program exits. */
448 arg = argv[extra_args] + cl_options[opt_index].opt_len + 1 + adjust_len; 547 arg = argv[extra_args] + cl_options[opt_index].opt_len + 1 + adjust_len;
449 548
450 if (*arg == '\0' && !(option->flags & CL_MISSING_OK)) 549 if (*arg == '\0' && !option->cl_missing_ok)
451 { 550 {
452 if (separate_arg_flag) 551 if (separate_arg_flag)
453 { 552 {
454 arg = argv[extra_args + 1]; 553 arg = argv[extra_args + 1];
455 result = extra_args + 2; 554 result = extra_args + 2;
481 errors |= CL_ERR_MISSING_ARG; 580 errors |= CL_ERR_MISSING_ARG;
482 581
483 /* Is this option an alias (or an ignored option, marked as an alias 582 /* Is this option an alias (or an ignored option, marked as an alias
484 of OPT_SPECIAL_ignore)? */ 583 of OPT_SPECIAL_ignore)? */
485 if (option->alias_target != N_OPTS 584 if (option->alias_target != N_OPTS
486 && (!(option->flags & CL_SEPARATE_ALIAS) || have_separate_arg)) 585 && (!option->cl_separate_alias || have_separate_arg))
487 { 586 {
488 size_t new_opt_index = option->alias_target; 587 size_t new_opt_index = option->alias_target;
489 588
490 if (new_opt_index == OPT_SPECIAL_ignore) 589 if (new_opt_index == OPT_SPECIAL_ignore)
491 { 590 {
499 { 598 {
500 const struct cl_option *new_option = &cl_options[new_opt_index]; 599 const struct cl_option *new_option = &cl_options[new_opt_index];
501 600
502 /* The new option must not be an alias itself. */ 601 /* The new option must not be an alias itself. */
503 gcc_assert (new_option->alias_target == N_OPTS 602 gcc_assert (new_option->alias_target == N_OPTS
504 || (new_option->flags & CL_SEPARATE_ALIAS)); 603 || new_option->cl_separate_alias);
505 604
506 if (option->neg_alias_arg) 605 if (option->neg_alias_arg)
507 { 606 {
508 gcc_assert (option->alias_arg != NULL); 607 gcc_assert (option->alias_arg != NULL);
509 gcc_assert (arg == NULL); 608 gcc_assert (arg == NULL);
609 gcc_assert (!option->cl_negative_alias);
510 if (value) 610 if (value)
511 arg = option->alias_arg; 611 arg = option->alias_arg;
512 else 612 else
513 arg = option->neg_alias_arg; 613 arg = option->neg_alias_arg;
514 value = 1; 614 value = 1;
515 } 615 }
516 else if (option->alias_arg) 616 else if (option->alias_arg)
517 { 617 {
518 gcc_assert (value == 1); 618 gcc_assert (value == 1);
519 gcc_assert (arg == NULL); 619 gcc_assert (arg == NULL);
620 gcc_assert (!option->cl_negative_alias);
520 arg = option->alias_arg; 621 arg = option->alias_arg;
521 } 622 }
522 623
624 if (option->cl_negative_alias)
625 value = !value;
626
523 opt_index = new_opt_index; 627 opt_index = new_opt_index;
524 option = new_option; 628 option = new_option;
525 629
526 if (value == 0) 630 if (value == 0)
527 gcc_assert (!(option->flags & CL_REJECT_NEGATIVE)); 631 gcc_assert (!option->cl_reject_negative);
528 632
529 /* Recompute what arguments are allowed. */ 633 /* Recompute what arguments are allowed. */
530 separate_arg_flag = ((option->flags & CL_SEPARATE) 634 separate_arg_flag = ((option->flags & CL_SEPARATE)
531 && !((option->flags & CL_NO_DRIVER_ARG) 635 && !(option->cl_no_driver_arg
532 && (lang_mask & CL_DRIVER))); 636 && (lang_mask & CL_DRIVER)));
533 joined_arg_flag = (option->flags & CL_JOINED) != 0; 637 joined_arg_flag = (option->flags & CL_JOINED) != 0;
534 638
535 if (separate_args > 1 || (option->flags & CL_SEPARATE_NARGS_MASK)) 639 if (separate_args > 1 || option->cl_separate_nargs)
536 gcc_assert (separate_args 640 gcc_assert (separate_args
537 == ((option->flags & CL_SEPARATE_NARGS_MASK) 641 == (unsigned int) option->cl_separate_nargs + 1);
538 >> CL_SEPARATE_NARGS_SHIFT) + 1);
539 642
540 if (!(errors & CL_ERR_MISSING_ARG)) 643 if (!(errors & CL_ERR_MISSING_ARG))
541 { 644 {
542 if (separate_arg_flag || joined_arg_flag) 645 if (separate_arg_flag || joined_arg_flag)
543 { 646 {
544 if ((option->flags & CL_MISSING_OK) && arg == NULL) 647 if (option->cl_missing_ok && arg == NULL)
545 arg = ""; 648 arg = "";
546 gcc_assert (arg != NULL); 649 gcc_assert (arg != NULL);
547 } 650 }
548 else 651 else
549 gcc_assert (arg == NULL); 652 gcc_assert (arg == NULL);
553 if (option->warn_message) 656 if (option->warn_message)
554 { 657 {
555 gcc_assert (warn_message == NULL); 658 gcc_assert (warn_message == NULL);
556 warn_message = option->warn_message; 659 warn_message = option->warn_message;
557 } 660 }
558 if (option->flags & CL_DISABLED) 661 if (option->cl_disabled)
559 errors |= CL_ERR_DISABLED; 662 errors |= CL_ERR_DISABLED;
560 } 663 }
561 } 664 }
562 665
563 /* Check if this is a switch for a different front end. */ 666 /* Check if this is a switch for a different front end. */
564 if (!option_ok_for_language (option, lang_mask)) 667 if (!option_ok_for_language (option, lang_mask))
565 errors |= CL_ERR_WRONG_LANG; 668 errors |= CL_ERR_WRONG_LANG;
566 669
670 /* Convert the argument to lowercase if appropriate. */
671 if (arg && option->cl_tolower)
672 {
673 size_t j;
674 size_t len = strlen (arg);
675 char *arg_lower = XOBNEWVEC (&opts_obstack, char, len + 1);
676
677 for (j = 0; j < len; j++)
678 arg_lower[j] = TOLOWER ((unsigned char) arg[j]);
679 arg_lower[len] = 0;
680 arg = arg_lower;
681 }
682
567 /* If the switch takes an integer, convert it. */ 683 /* If the switch takes an integer, convert it. */
568 if (arg && (option->flags & CL_UINTEGER)) 684 if (arg && option->cl_uinteger)
569 { 685 {
570 value = integral_argument (arg); 686 value = integral_argument (arg);
571 if (value == -1) 687 if (value == -1)
572 errors |= CL_ERR_UINT_ARG; 688 errors |= CL_ERR_UINT_ARG;
689
690 /* Reject value out of a range. */
691 if (option->range_max != -1
692 && (value < option->range_min || value > option->range_max))
693 errors |= CL_ERR_INT_RANGE_ARG;
573 } 694 }
574 695
575 /* If the switch takes an enumerated argument, convert it. */ 696 /* If the switch takes an enumerated argument, convert it. */
576 if (arg && (option->var_type == CLVC_ENUM)) 697 if (arg && (option->var_type == CLVC_ENUM))
577 { 698 {
634 } 755 }
635 gcc_assert (result == 1 + i); 756 gcc_assert (result == 1 + i);
636 decoded->canonical_option_num_elements = result; 757 decoded->canonical_option_num_elements = result;
637 } 758 }
638 } 759 }
639 decoded->orig_option_with_args_text = p = XNEWVEC (char, total_len); 760 decoded->orig_option_with_args_text
761 = p = XOBNEWVEC (&opts_obstack, char, total_len);
640 for (i = 0; i < result; i++) 762 for (i = 0; i < result; i++)
641 { 763 {
642 size_t len = strlen (argv[i]); 764 size_t len = strlen (argv[i]);
643 765
644 /* Print the empty string verbally. */ 766 /* Print the empty string verbally. */
655 else 777 else
656 *p++ = ' '; 778 *p++ = ' ';
657 } 779 }
658 780
659 return result; 781 return result;
782 }
783
784 /* Obstack for option strings. */
785
786 struct obstack opts_obstack;
787
788 /* Like libiberty concat, but allocate using opts_obstack. */
789
790 char *
791 opts_concat (const char *first, ...)
792 {
793 char *newstr, *end;
794 size_t length = 0;
795 const char *arg;
796 va_list ap;
797
798 /* First compute the size of the result and get sufficient memory. */
799 va_start (ap, first);
800 for (arg = first; arg; arg = va_arg (ap, const char *))
801 length += strlen (arg);
802 newstr = XOBNEWVEC (&opts_obstack, char, length + 1);
803 va_end (ap);
804
805 /* Now copy the individual pieces to the result string. */
806 va_start (ap, first);
807 for (arg = first, end = newstr; arg; arg = va_arg (ap, const char *))
808 {
809 length = strlen (arg);
810 memcpy (end, arg, length);
811 end += length;
812 }
813 *end = '\0';
814 va_end (ap);
815 return newstr;
660 } 816 }
661 817
662 /* Decode command-line options (ARGC and ARGV being the arguments of 818 /* Decode command-line options (ARGC and ARGV being the arguments of
663 main) into an array, setting *DECODED_OPTIONS to a pointer to that 819 main) into an array, setting *DECODED_OPTIONS to a pointer to that
664 array and *DECODED_OPTIONS_COUNT to the number of entries in the 820 array and *DECODED_OPTIONS_COUNT to the number of entries in the
675 unsigned int *decoded_options_count) 831 unsigned int *decoded_options_count)
676 { 832 {
677 unsigned int n, i; 833 unsigned int n, i;
678 struct cl_decoded_option *opt_array; 834 struct cl_decoded_option *opt_array;
679 unsigned int num_decoded_options; 835 unsigned int num_decoded_options;
680 bool argv_copied = false;
681 836
682 opt_array = XNEWVEC (struct cl_decoded_option, argc); 837 opt_array = XNEWVEC (struct cl_decoded_option, argc);
683 838
684 opt_array[0].opt_index = OPT_SPECIAL_program_name; 839 opt_array[0].opt_index = OPT_SPECIAL_program_name;
685 opt_array[0].warn_message = NULL; 840 opt_array[0].warn_message = NULL;
710 n = decode_cmdline_option (argv + i, lang_mask, 865 n = decode_cmdline_option (argv + i, lang_mask,
711 &opt_array[num_decoded_options]); 866 &opt_array[num_decoded_options]);
712 num_decoded_options++; 867 num_decoded_options++;
713 } 868 }
714 869
715 if (argv_copied)
716 free (argv);
717 *decoded_options = opt_array; 870 *decoded_options = opt_array;
718 *decoded_options_count = num_decoded_options; 871 *decoded_options_count = num_decoded_options;
719 prune_options (decoded_options, decoded_options_count); 872 prune_options (decoded_options, decoded_options_count);
720 } 873 }
721 874
748 unsigned int new_decoded_options_count; 901 unsigned int new_decoded_options_count;
749 struct cl_decoded_option *new_decoded_options 902 struct cl_decoded_option *new_decoded_options
750 = XNEWVEC (struct cl_decoded_option, old_decoded_options_count); 903 = XNEWVEC (struct cl_decoded_option, old_decoded_options_count);
751 unsigned int i; 904 unsigned int i;
752 const struct cl_option *option; 905 const struct cl_option *option;
906 unsigned int fdiagnostics_color_idx = 0;
753 907
754 /* Remove arguments which are negated by others after them. */ 908 /* Remove arguments which are negated by others after them. */
755 new_decoded_options_count = 0; 909 new_decoded_options_count = 0;
756 for (i = 0; i < old_decoded_options_count; i++) 910 for (i = 0; i < old_decoded_options_count; i++)
757 { 911 {
766 case OPT_SPECIAL_unknown: 920 case OPT_SPECIAL_unknown:
767 case OPT_SPECIAL_ignore: 921 case OPT_SPECIAL_ignore:
768 case OPT_SPECIAL_program_name: 922 case OPT_SPECIAL_program_name:
769 case OPT_SPECIAL_input_file: 923 case OPT_SPECIAL_input_file:
770 goto keep; 924 goto keep;
925
926 /* Do not save OPT_fdiagnostics_color_, just remember the last one. */
927 case OPT_fdiagnostics_color_:
928 fdiagnostics_color_idx = i;
929 continue;
771 930
772 default: 931 default:
773 gcc_assert (opt_idx < cl_options_count); 932 gcc_assert (opt_idx < cl_options_count);
774 option = &cl_options[opt_idx]; 933 option = &cl_options[opt_idx];
775 if (option->neg_index < 0) 934 if (option->neg_index < 0)
802 } 961 }
803 break; 962 break;
804 } 963 }
805 } 964 }
806 965
966 if (fdiagnostics_color_idx >= 1)
967 {
968 /* We put the last -fdiagnostics-color= at the first position
969 after argv[0] so it can take effect immediately. */
970 memmove (new_decoded_options + 2, new_decoded_options + 1,
971 sizeof (struct cl_decoded_option)
972 * (new_decoded_options_count - 1));
973 new_decoded_options[1] = old_decoded_options[fdiagnostics_color_idx];
974 new_decoded_options_count++;
975 }
976
807 free (old_decoded_options); 977 free (old_decoded_options);
808 new_decoded_options = XRESIZEVEC (struct cl_decoded_option, 978 new_decoded_options = XRESIZEVEC (struct cl_decoded_option,
809 new_decoded_options, 979 new_decoded_options,
810 new_decoded_options_count); 980 new_decoded_options_count);
811 *decoded_options = new_decoded_options; 981 *decoded_options = new_decoded_options;
817 OPTS_SET. KIND is the diagnostic_t if this is a diagnostics 987 OPTS_SET. KIND is the diagnostic_t if this is a diagnostics
818 option, DK_UNSPECIFIED otherwise, and LOC is the location of the 988 option, DK_UNSPECIFIED otherwise, and LOC is the location of the
819 option for options from the source file, UNKNOWN_LOCATION 989 option for options from the source file, UNKNOWN_LOCATION
820 otherwise. GENERATED_P is true for an option generated as part of 990 otherwise. GENERATED_P is true for an option generated as part of
821 processing another option or otherwise generated internally, false 991 processing another option or otherwise generated internally, false
822 for one explicitly passed by the user. Returns false if the switch 992 for one explicitly passed by the user. control_warning_option
823 was invalid. DC is the diagnostic context for options affecting 993 generated options are considered explicitly passed by the user.
824 diagnostics state, or NULL. */ 994 Returns false if the switch was invalid. DC is the diagnostic
995 context for options affecting diagnostics state, or NULL. */
825 996
826 static bool 997 static bool
827 handle_option (struct gcc_options *opts, 998 handle_option (struct gcc_options *opts,
828 struct gcc_options *opts_set, 999 struct gcc_options *opts_set,
829 const struct cl_decoded_option *decoded, 1000 const struct cl_decoded_option *decoded,
845 for (i = 0; i < handlers->num_handlers; i++) 1016 for (i = 0; i < handlers->num_handlers; i++)
846 if (option->flags & handlers->handlers[i].mask) 1017 if (option->flags & handlers->handlers[i].mask)
847 { 1018 {
848 if (!handlers->handlers[i].handler (opts, opts_set, decoded, 1019 if (!handlers->handlers[i].handler (opts, opts_set, decoded,
849 lang_mask, kind, loc, 1020 lang_mask, kind, loc,
850 handlers, dc)) 1021 handlers, dc,
1022 handlers->target_option_override_hook))
851 return false; 1023 return false;
852 else
853 handlers->post_handling_callback (decoded,
854 handlers->handlers[i].mask);
855 } 1024 }
856 1025
857 return true; 1026 return true;
858 } 1027 }
859 1028
866 handle_generated_option (struct gcc_options *opts, 1035 handle_generated_option (struct gcc_options *opts,
867 struct gcc_options *opts_set, 1036 struct gcc_options *opts_set,
868 size_t opt_index, const char *arg, int value, 1037 size_t opt_index, const char *arg, int value,
869 unsigned int lang_mask, int kind, location_t loc, 1038 unsigned int lang_mask, int kind, location_t loc,
870 const struct cl_option_handlers *handlers, 1039 const struct cl_option_handlers *handlers,
871 diagnostic_context *dc) 1040 bool generated_p, diagnostic_context *dc)
872 { 1041 {
873 struct cl_decoded_option decoded; 1042 struct cl_decoded_option decoded;
874 1043
875 generate_option (opt_index, arg, value, lang_mask, &decoded); 1044 generate_option (opt_index, arg, value, lang_mask, &decoded);
876 return handle_option (opts, opts_set, &decoded, lang_mask, kind, loc, 1045 return handle_option (opts, opts_set, &decoded, lang_mask, kind, loc,
877 handlers, true, dc); 1046 handlers, generated_p, dc);
878 } 1047 }
879 1048
880 /* Fill in *DECODED with an option described by OPT_INDEX, ARG and 1049 /* Fill in *DECODED with an option described by OPT_INDEX, ARG and
881 VALUE for a front end using LANG_MASK. This is used when the 1050 VALUE for a front end using LANG_MASK. This is used when the
882 compiler generates options internally. */ 1051 compiler generates options internally. */
902 decoded->orig_option_with_args_text = decoded->canonical_option[0]; 1071 decoded->orig_option_with_args_text = decoded->canonical_option[0];
903 break; 1072 break;
904 1073
905 case 2: 1074 case 2:
906 decoded->orig_option_with_args_text 1075 decoded->orig_option_with_args_text
907 = concat (decoded->canonical_option[0], " ", 1076 = opts_concat (decoded->canonical_option[0], " ",
908 decoded->canonical_option[1], NULL); 1077 decoded->canonical_option[1], NULL);
909 break; 1078 break;
910 1079
911 default: 1080 default:
912 gcc_unreachable (); 1081 gcc_unreachable ();
913 } 1082 }
930 decoded->canonical_option[3] = NULL; 1099 decoded->canonical_option[3] = NULL;
931 decoded->value = 1; 1100 decoded->value = 1;
932 decoded->errors = 0; 1101 decoded->errors = 0;
933 } 1102 }
934 1103
1104 /* Helper function for listing valid choices and hint for misspelled
1105 value. CANDIDATES is a vector containing all valid strings,
1106 STR is set to a heap allocated string that contains all those
1107 strings concatenated, separated by spaces, and the return value
1108 is the closest string from those to ARG, or NULL if nothing is
1109 close enough. Callers should XDELETEVEC (STR) after using it
1110 to avoid memory leaks. */
1111
1112 const char *
1113 candidates_list_and_hint (const char *arg, char *&str,
1114 const auto_vec <const char *> &candidates)
1115 {
1116 size_t len = 0;
1117 int i;
1118 const char *candidate;
1119 char *p;
1120
1121 FOR_EACH_VEC_ELT (candidates, i, candidate)
1122 len += strlen (candidate) + 1;
1123
1124 str = p = XNEWVEC (char, len);
1125 FOR_EACH_VEC_ELT (candidates, i, candidate)
1126 {
1127 len = strlen (candidate);
1128 memcpy (p, candidate, len);
1129 p[len] = ' ';
1130 p += len + 1;
1131 }
1132 p[-1] = '\0';
1133 return find_closest_string (arg, &candidates);
1134 }
1135
1136 /* Perform diagnostics for read_cmdline_option and control_warning_option
1137 functions. Returns true if an error has been diagnosed.
1138 LOC and LANG_MASK arguments like in read_cmdline_option.
1139 OPTION is the option to report diagnostics for, OPT the name
1140 of the option as text, ARG the argument of the option (for joined
1141 options), ERRORS is bitmask of CL_ERR_* values. */
1142
1143 static bool
1144 cmdline_handle_error (location_t loc, const struct cl_option *option,
1145 const char *opt, const char *arg, int errors,
1146 unsigned int lang_mask)
1147 {
1148 if (errors & CL_ERR_DISABLED)
1149 {
1150 error_at (loc, "command line option %qs"
1151 " is not supported by this configuration", opt);
1152 return true;
1153 }
1154
1155 if (errors & CL_ERR_MISSING_ARG)
1156 {
1157 if (option->missing_argument_error)
1158 error_at (loc, option->missing_argument_error, opt);
1159 else
1160 error_at (loc, "missing argument to %qs", opt);
1161 return true;
1162 }
1163
1164 if (errors & CL_ERR_UINT_ARG)
1165 {
1166 error_at (loc, "argument to %qs should be a non-negative integer",
1167 option->opt_text);
1168 return true;
1169 }
1170
1171 if (errors & CL_ERR_INT_RANGE_ARG)
1172 {
1173 error_at (loc, "argument to %qs is not between %d and %d",
1174 option->opt_text, option->range_min, option->range_max);
1175 return true;
1176 }
1177
1178 if (errors & CL_ERR_ENUM_ARG)
1179 {
1180 const struct cl_enum *e = &cl_enums[option->var_enum];
1181 unsigned int i;
1182 char *s;
1183
1184 if (e->unknown_error)
1185 error_at (loc, e->unknown_error, arg);
1186 else
1187 error_at (loc, "unrecognized argument in option %qs", opt);
1188
1189 auto_vec <const char *> candidates;
1190 for (i = 0; e->values[i].arg != NULL; i++)
1191 {
1192 if (!enum_arg_ok_for_language (&e->values[i], lang_mask))
1193 continue;
1194 candidates.safe_push (e->values[i].arg);
1195 }
1196 const char *hint = candidates_list_and_hint (arg, s, candidates);
1197 if (hint)
1198 inform (loc, "valid arguments to %qs are: %s; did you mean %qs?",
1199 option->opt_text, s, hint);
1200 else
1201 inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
1202 XDELETEVEC (s);
1203
1204 return true;
1205 }
1206
1207 return false;
1208 }
1209
935 /* Handle the switch DECODED (location LOC) for the language indicated 1210 /* Handle the switch DECODED (location LOC) for the language indicated
936 by LANG_MASK, using the handlers in *HANDLERS and setting fields in 1211 by LANG_MASK, using the handlers in *HANDLERS and setting fields in
937 OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for 1212 OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
938 diagnostic options. */ 1213 diagnostic options. */
939 1214
962 if (decoded->opt_index == OPT_SPECIAL_ignore) 1237 if (decoded->opt_index == OPT_SPECIAL_ignore)
963 return; 1238 return;
964 1239
965 option = &cl_options[decoded->opt_index]; 1240 option = &cl_options[decoded->opt_index];
966 1241
967 if (decoded->errors & CL_ERR_DISABLED) 1242 if (decoded->errors
968 { 1243 && cmdline_handle_error (loc, option, opt, decoded->arg,
969 error_at (loc, "command line option %qs" 1244 decoded->errors, lang_mask))
970 " is not supported by this configuration", opt); 1245 return;
971 return;
972 }
973
974 if (decoded->errors & CL_ERR_MISSING_ARG)
975 {
976 if (option->missing_argument_error)
977 error_at (loc, option->missing_argument_error, opt);
978 else
979 error_at (loc, "missing argument to %qs", opt);
980 return;
981 }
982
983 if (decoded->errors & CL_ERR_UINT_ARG)
984 {
985 error_at (loc, "argument to %qs should be a non-negative integer",
986 option->opt_text);
987 return;
988 }
989
990 if (decoded->errors & CL_ERR_ENUM_ARG)
991 {
992 const struct cl_enum *e = &cl_enums[option->var_enum];
993 unsigned int i;
994 size_t len;
995 char *s, *p;
996
997 if (e->unknown_error)
998 error_at (loc, e->unknown_error, decoded->arg);
999 else
1000 error_at (loc, "unrecognized argument in option %qs", opt);
1001
1002 len = 0;
1003 for (i = 0; e->values[i].arg != NULL; i++)
1004 len += strlen (e->values[i].arg) + 1;
1005
1006 s = XALLOCAVEC (char, len);
1007 p = s;
1008 for (i = 0; e->values[i].arg != NULL; i++)
1009 {
1010 size_t arglen = strlen (e->values[i].arg);
1011 memcpy (p, e->values[i].arg, arglen);
1012 p[arglen] = ' ';
1013 p += arglen + 1;
1014 }
1015 p[-1] = 0;
1016 inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
1017 return;
1018 }
1019 1246
1020 if (decoded->errors & CL_ERR_WRONG_LANG) 1247 if (decoded->errors & CL_ERR_WRONG_LANG)
1021 { 1248 {
1022 handlers->wrong_lang_callback (decoded, lang_mask); 1249 handlers->wrong_lang_callback (decoded, lang_mask);
1023 return; 1250 return;
1044 void *flag_var = option_flag_var (opt_index, opts); 1271 void *flag_var = option_flag_var (opt_index, opts);
1045 void *set_flag_var = NULL; 1272 void *set_flag_var = NULL;
1046 1273
1047 if (!flag_var) 1274 if (!flag_var)
1048 return; 1275 return;
1276
1277 if ((diagnostic_t) kind != DK_UNSPECIFIED && dc != NULL)
1278 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
1049 1279
1050 if (opts_set != NULL) 1280 if (opts_set != NULL)
1051 set_flag_var = option_flag_var (opt_index, opts_set); 1281 set_flag_var = option_flag_var (opt_index, opts_set);
1052 1282
1053 switch (option->var_type) 1283 switch (option->var_type)
1057 if (set_flag_var) 1287 if (set_flag_var)
1058 *(int *) set_flag_var = 1; 1288 *(int *) set_flag_var = 1;
1059 break; 1289 break;
1060 1290
1061 case CLVC_EQUAL: 1291 case CLVC_EQUAL:
1062 *(int *) flag_var = (value 1292 if (option->cl_host_wide_int)
1063 ? option->var_value 1293 *(HOST_WIDE_INT *) flag_var = (value
1064 : !option->var_value); 1294 ? option->var_value
1295 : !option->var_value);
1296 else
1297 *(int *) flag_var = (value
1298 ? option->var_value
1299 : !option->var_value);
1065 if (set_flag_var) 1300 if (set_flag_var)
1066 *(int *) set_flag_var = 1; 1301 *(int *) set_flag_var = 1;
1067 break; 1302 break;
1068 1303
1069 case CLVC_BIT_CLEAR: 1304 case CLVC_BIT_CLEAR:
1070 case CLVC_BIT_SET: 1305 case CLVC_BIT_SET:
1071 if ((value != 0) == (option->var_type == CLVC_BIT_SET)) 1306 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
1072 *(int *) flag_var |= option->var_value; 1307 {
1308 if (option->cl_host_wide_int)
1309 *(HOST_WIDE_INT *) flag_var |= option->var_value;
1310 else
1311 *(int *) flag_var |= option->var_value;
1312 }
1073 else 1313 else
1074 *(int *) flag_var &= ~option->var_value; 1314 {
1315 if (option->cl_host_wide_int)
1316 *(HOST_WIDE_INT *) flag_var &= ~option->var_value;
1317 else
1318 *(int *) flag_var &= ~option->var_value;
1319 }
1075 if (set_flag_var) 1320 if (set_flag_var)
1076 *(int *) set_flag_var |= option->var_value; 1321 {
1322 if (option->cl_host_wide_int)
1323 *(HOST_WIDE_INT *) set_flag_var |= option->var_value;
1324 else
1325 *(int *) set_flag_var |= option->var_value;
1326 }
1077 break; 1327 break;
1078 1328
1079 case CLVC_STRING: 1329 case CLVC_STRING:
1080 *(const char **) flag_var = arg; 1330 *(const char **) flag_var = arg;
1081 if (set_flag_var) 1331 if (set_flag_var)
1092 } 1342 }
1093 break; 1343 break;
1094 1344
1095 case CLVC_DEFER: 1345 case CLVC_DEFER:
1096 { 1346 {
1097 VEC(cl_deferred_option,heap) *vec 1347 vec<cl_deferred_option> *v
1098 = (VEC(cl_deferred_option,heap) *) *(void **) flag_var; 1348 = (vec<cl_deferred_option> *) *(void **) flag_var;
1099 cl_deferred_option *p; 1349 cl_deferred_option p = {opt_index, arg, value};
1100 1350 if (!v)
1101 p = VEC_safe_push (cl_deferred_option, heap, vec, NULL); 1351 v = XCNEW (vec<cl_deferred_option>);
1102 p->opt_index = opt_index; 1352 v->safe_push (p);
1103 p->arg = arg; 1353 *(void **) flag_var = v;
1104 p->value = value;
1105 *(void **) flag_var = vec;
1106 if (set_flag_var) 1354 if (set_flag_var)
1107 *(void **) set_flag_var = vec; 1355 *(void **) set_flag_var = v;
1108 } 1356 }
1109 break; 1357 break;
1110 } 1358 }
1111
1112 if ((diagnostic_t) kind != DK_UNSPECIFIED
1113 && dc != NULL)
1114 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
1115 } 1359 }
1116 1360
1117 /* Return the address of the flag variable for option OPT_INDEX in 1361 /* Return the address of the flag variable for option OPT_INDEX in
1118 options structure OPTS, or NULL if there is no flag variable. */ 1362 options structure OPTS, or NULL if there is no flag variable. */
1119 1363
1142 { 1386 {
1143 case CLVC_BOOLEAN: 1387 case CLVC_BOOLEAN:
1144 return *(int *) flag_var != 0; 1388 return *(int *) flag_var != 0;
1145 1389
1146 case CLVC_EQUAL: 1390 case CLVC_EQUAL:
1147 return *(int *) flag_var == option->var_value; 1391 if (option->cl_host_wide_int)
1392 return *(HOST_WIDE_INT *) flag_var == option->var_value;
1393 else
1394 return *(int *) flag_var == option->var_value;
1148 1395
1149 case CLVC_BIT_CLEAR: 1396 case CLVC_BIT_CLEAR:
1150 return (*(int *) flag_var & option->var_value) == 0; 1397 if (option->cl_host_wide_int)
1398 return (*(HOST_WIDE_INT *) flag_var & option->var_value) == 0;
1399 else
1400 return (*(int *) flag_var & option->var_value) == 0;
1151 1401
1152 case CLVC_BIT_SET: 1402 case CLVC_BIT_SET:
1153 return (*(int *) flag_var & option->var_value) != 0; 1403 if (option->cl_host_wide_int)
1404 return (*(HOST_WIDE_INT *) flag_var & option->var_value) != 0;
1405 else
1406 return (*(int *) flag_var & option->var_value) != 0;
1154 1407
1155 case CLVC_STRING: 1408 case CLVC_STRING:
1156 case CLVC_ENUM: 1409 case CLVC_ENUM:
1157 case CLVC_DEFER: 1410 case CLVC_DEFER:
1158 break; 1411 break;
1175 switch (cl_options[option].var_type) 1428 switch (cl_options[option].var_type)
1176 { 1429 {
1177 case CLVC_BOOLEAN: 1430 case CLVC_BOOLEAN:
1178 case CLVC_EQUAL: 1431 case CLVC_EQUAL:
1179 state->data = flag_var; 1432 state->data = flag_var;
1180 state->size = sizeof (int); 1433 state->size = (cl_options[option].cl_host_wide_int
1434 ? sizeof (HOST_WIDE_INT)
1435 : sizeof (int));
1181 break; 1436 break;
1182 1437
1183 case CLVC_BIT_CLEAR: 1438 case CLVC_BIT_CLEAR:
1184 case CLVC_BIT_SET: 1439 case CLVC_BIT_SET:
1185 state->ch = option_enabled (option, opts); 1440 state->ch = option_enabled (option, opts);
1206 } 1461 }
1207 1462
1208 /* Set a warning option OPT_INDEX (language mask LANG_MASK, option 1463 /* Set a warning option OPT_INDEX (language mask LANG_MASK, option
1209 handlers HANDLERS) to have diagnostic kind KIND for option 1464 handlers HANDLERS) to have diagnostic kind KIND for option
1210 structures OPTS and OPTS_SET and diagnostic context DC (possibly 1465 structures OPTS and OPTS_SET and diagnostic context DC (possibly
1211 NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). If IMPLY, 1466 NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). ARG is the
1467 argument of the option for joined options, or NULL otherwise. If IMPLY,
1212 the warning option in question is implied at this point. This is 1468 the warning option in question is implied at this point. This is
1213 used by -Werror= and #pragma GCC diagnostic. */ 1469 used by -Werror= and #pragma GCC diagnostic. */
1214 1470
1215 void 1471 void
1216 control_warning_option (unsigned int opt_index, int kind, bool imply, 1472 control_warning_option (unsigned int opt_index, int kind, const char *arg,
1217 location_t loc, unsigned int lang_mask, 1473 bool imply, location_t loc, unsigned int lang_mask,
1218 const struct cl_option_handlers *handlers, 1474 const struct cl_option_handlers *handlers,
1219 struct gcc_options *opts, 1475 struct gcc_options *opts,
1220 struct gcc_options *opts_set, 1476 struct gcc_options *opts_set,
1221 diagnostic_context *dc) 1477 diagnostic_context *dc)
1222 { 1478 {
1223 if (cl_options[opt_index].alias_target != N_OPTS) 1479 if (cl_options[opt_index].alias_target != N_OPTS)
1224 opt_index = cl_options[opt_index].alias_target; 1480 {
1481 gcc_assert (!cl_options[opt_index].cl_separate_alias
1482 && !cl_options[opt_index].cl_negative_alias);
1483 if (cl_options[opt_index].alias_arg)
1484 arg = cl_options[opt_index].alias_arg;
1485 opt_index = cl_options[opt_index].alias_target;
1486 }
1225 if (opt_index == OPT_SPECIAL_ignore) 1487 if (opt_index == OPT_SPECIAL_ignore)
1226 return; 1488 return;
1227 if (dc) 1489 if (dc)
1228 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc); 1490 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
1229 if (imply) 1491 if (imply)
1230 { 1492 {
1493 const struct cl_option *option = &cl_options[opt_index];
1494
1231 /* -Werror=foo implies -Wfoo. */ 1495 /* -Werror=foo implies -Wfoo. */
1232 if (cl_options[opt_index].var_type == CLVC_BOOLEAN) 1496 if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
1233 handle_generated_option (opts, opts_set, 1497 {
1234 opt_index, NULL, 1, lang_mask, 1498 int value = 1;
1235 kind, loc, handlers, dc); 1499
1236 } 1500 if (arg && *arg == '\0' && !option->cl_missing_ok)
1237 } 1501 arg = NULL;
1502
1503 if ((option->flags & CL_JOINED) && arg == NULL)
1504 {
1505 cmdline_handle_error (loc, option, option->opt_text, arg,
1506 CL_ERR_MISSING_ARG, lang_mask);
1507 return;
1508 }
1509
1510 /* If the switch takes an integer, convert it. */
1511 if (arg && option->cl_uinteger)
1512 {
1513 value = integral_argument (arg);
1514 if (value == -1)
1515 {
1516 cmdline_handle_error (loc, option, option->opt_text, arg,
1517 CL_ERR_UINT_ARG, lang_mask);
1518 return;
1519 }
1520 }
1521
1522 /* If the switch takes an enumerated argument, convert it. */
1523 if (arg && option->var_type == CLVC_ENUM)
1524 {
1525 const struct cl_enum *e = &cl_enums[option->var_enum];
1526
1527 if (enum_arg_to_value (e->values, arg, &value, lang_mask))
1528 {
1529 const char *carg = NULL;
1530
1531 if (enum_value_to_arg (e->values, &carg, value, lang_mask))
1532 arg = carg;
1533 gcc_assert (carg != NULL);
1534 }
1535 else
1536 {
1537 cmdline_handle_error (loc, option, option->opt_text, arg,
1538 CL_ERR_ENUM_ARG, lang_mask);
1539 return;
1540 }
1541 }
1542
1543 handle_generated_option (opts, opts_set,
1544 opt_index, arg, value, lang_mask,
1545 kind, loc, handlers, false, dc);
1546 }
1547 }
1548 }