]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/opts-common.c
Update copyright years.
[thirdparty/gcc.git] / gcc / opts-common.c
1 /* Command line option handling.
2 Copyright (C) 2006-2016 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "intl.h"
23 #include "coretypes.h"
24 #include "opts.h"
25 #include "options.h"
26 #include "diagnostic.h"
27
28 static void prune_options (struct cl_decoded_option **, unsigned int *);
29
30 /* Perform a binary search to find which option the command-line INPUT
31 matches. Returns its index in the option array, and
32 OPT_SPECIAL_unknown on failure.
33
34 This routine is quite subtle. A normal binary search is not good
35 enough because some options can be suffixed with an argument, and
36 multiple sub-matches can occur, e.g. input of "-pedantic" matching
37 the initial substring of "-pedantic-errors".
38
39 A more complicated example is -gstabs. It should match "-g" with
40 an argument of "stabs". Suppose, however, that the number and list
41 of switches are such that the binary search tests "-gen-decls"
42 before having tested "-g". This doesn't match, and as "-gen-decls"
43 is less than "-gstabs", it will become the lower bound of the
44 binary search range, and "-g" will never be seen. To resolve this
45 issue, 'optc-gen.awk' makes "-gen-decls" point, via the back_chain member,
46 to "-g" so that failed searches that end between "-gen-decls" and
47 the lexicographically subsequent switch know to go back and see if
48 "-g" causes a match (which it does in this example).
49
50 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
52 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. */
54 size_t
55 find_opt (const char *input, unsigned int lang_mask)
56 {
57 size_t mn, mn_orig, mx, md, opt_len;
58 size_t match_wrong_lang;
59 int comp;
60
61 mn = 0;
62 mx = cl_options_count;
63
64 /* Find mn such this lexicographical inequality holds:
65 cl_options[mn] <= input < cl_options[mn + 1]. */
66 while (mx - mn > 1)
67 {
68 md = (mn + mx) / 2;
69 opt_len = cl_options[md].opt_len;
70 comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
71
72 if (comp < 0)
73 mx = md;
74 else
75 mn = md;
76 }
77
78 mn_orig = mn;
79
80 /* This is the switch that is the best match but for a different
81 front end, or OPT_SPECIAL_unknown if there is no match at all. */
82 match_wrong_lang = OPT_SPECIAL_unknown;
83
84 /* Backtrace the chain of possible matches, returning the longest
85 one, if any, that fits best. With current GCC switches, this
86 loop executes at most twice. */
87 do
88 {
89 const struct cl_option *opt = &cl_options[mn];
90
91 /* Is the input either an exact match or a prefix that takes a
92 joined argument? */
93 if (!strncmp (input, opt->opt_text + 1, opt->opt_len)
94 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
95 {
96 /* If language is OK, return it. */
97 if (opt->flags & lang_mask)
98 return mn;
99
100 /* If we haven't remembered a prior match, remember this
101 one. Any prior match is necessarily better. */
102 if (match_wrong_lang == OPT_SPECIAL_unknown)
103 match_wrong_lang = mn;
104 }
105
106 /* Try the next possibility. This is cl_options_count if there
107 are no more. */
108 mn = opt->back_chain;
109 }
110 while (mn != cl_options_count);
111
112 if (match_wrong_lang == OPT_SPECIAL_unknown && input[0] == '-')
113 {
114 /* Long options, starting "--", may be abbreviated if the
115 abbreviation is unambiguous. This only applies to options
116 not taking a joined argument, and abbreviations of "--option"
117 are permitted even if there is a variant "--option=". */
118 size_t mnc = mn_orig + 1;
119 size_t cmp_len = strlen (input);
120 while (mnc < cl_options_count
121 && strncmp (input, cl_options[mnc].opt_text + 1, cmp_len) == 0)
122 {
123 /* Option matching this abbreviation. OK if it is the first
124 match and that does not take a joined argument, or the
125 second match, taking a joined argument and with only '='
126 added to the first match; otherwise considered
127 ambiguous. */
128 if (mnc == mn_orig + 1
129 && !(cl_options[mnc].flags & CL_JOINED))
130 match_wrong_lang = mnc;
131 else if (mnc == mn_orig + 2
132 && match_wrong_lang == mn_orig + 1
133 && (cl_options[mnc].flags & CL_JOINED)
134 && (cl_options[mnc].opt_len
135 == cl_options[mn_orig + 1].opt_len + 1)
136 && strncmp (cl_options[mnc].opt_text + 1,
137 cl_options[mn_orig + 1].opt_text + 1,
138 cl_options[mn_orig + 1].opt_len) == 0)
139 ; /* OK, as long as there are no more matches. */
140 else
141 return OPT_SPECIAL_unknown;
142 mnc++;
143 }
144 }
145
146 /* Return the best wrong match, or OPT_SPECIAL_unknown if none. */
147 return match_wrong_lang;
148 }
149
150 /* If ARG is a non-negative decimal or hexadecimal integer, return its
151 value, otherwise return -1. */
152
153 int
154 integral_argument (const char *arg)
155 {
156 const char *p = arg;
157
158 while (*p && ISDIGIT (*p))
159 p++;
160
161 if (*p == '\0')
162 return atoi (arg);
163
164 /* It wasn't a decimal number - try hexadecimal. */
165 if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'))
166 {
167 p = arg + 2;
168 while (*p && ISXDIGIT (*p))
169 p++;
170
171 if (p != arg + 2 && *p == '\0')
172 return strtol (arg, NULL, 16);
173 }
174
175 return -1;
176 }
177
178 /* Return whether OPTION is OK for the language given by
179 LANG_MASK. */
180 static bool
181 option_ok_for_language (const struct cl_option *option,
182 unsigned int lang_mask)
183 {
184 if (!(option->flags & lang_mask))
185 return false;
186 else if ((option->flags & CL_TARGET)
187 && (option->flags & (CL_LANG_ALL | CL_DRIVER))
188 && !(option->flags & (lang_mask & ~CL_COMMON & ~CL_TARGET)))
189 /* Complain for target flag language mismatches if any languages
190 are specified. */
191 return false;
192 return true;
193 }
194
195 /* Return whether ENUM_ARG is OK for the language given by
196 LANG_MASK. */
197
198 static bool
199 enum_arg_ok_for_language (const struct cl_enum_arg *enum_arg,
200 unsigned int lang_mask)
201 {
202 return (lang_mask & CL_DRIVER) || !(enum_arg->flags & CL_ENUM_DRIVER_ONLY);
203 }
204
205 /* Look up ARG in ENUM_ARGS for language LANG_MASK, returning true and
206 storing the value in *VALUE if found, and returning false without
207 modifying *VALUE if not found. */
208
209 static bool
210 enum_arg_to_value (const struct cl_enum_arg *enum_args,
211 const char *arg, int *value, unsigned int lang_mask)
212 {
213 unsigned int i;
214
215 for (i = 0; enum_args[i].arg != NULL; i++)
216 if (strcmp (arg, enum_args[i].arg) == 0
217 && enum_arg_ok_for_language (&enum_args[i], lang_mask))
218 {
219 *value = enum_args[i].value;
220 return true;
221 }
222
223 return false;
224 }
225
226 /* Look up ARG in the enum used by option OPT_INDEX for language
227 LANG_MASK, returning true and storing the value in *VALUE if found,
228 and returning false without modifying *VALUE if not found. */
229
230 bool
231 opt_enum_arg_to_value (size_t opt_index, const char *arg, int *value,
232 unsigned int lang_mask)
233 {
234 const struct cl_option *option = &cl_options[opt_index];
235
236 gcc_assert (option->var_type == CLVC_ENUM);
237
238 return enum_arg_to_value (cl_enums[option->var_enum].values, arg,
239 value, lang_mask);
240 }
241
242 /* Look of VALUE in ENUM_ARGS for language LANG_MASK and store the
243 corresponding string in *ARGP, returning true if the found string
244 was marked as canonical, false otherwise. If VALUE is not found
245 (which may be the case for uninitialized values if the relevant
246 option has not been passed), set *ARGP to NULL and return
247 false. */
248
249 bool
250 enum_value_to_arg (const struct cl_enum_arg *enum_args,
251 const char **argp, int value, unsigned int lang_mask)
252 {
253 unsigned int i;
254
255 for (i = 0; enum_args[i].arg != NULL; i++)
256 if (enum_args[i].value == value
257 && (enum_args[i].flags & CL_ENUM_CANONICAL)
258 && enum_arg_ok_for_language (&enum_args[i], lang_mask))
259 {
260 *argp = enum_args[i].arg;
261 return true;
262 }
263
264 for (i = 0; enum_args[i].arg != NULL; i++)
265 if (enum_args[i].value == value
266 && enum_arg_ok_for_language (&enum_args[i], lang_mask))
267 {
268 *argp = enum_args[i].arg;
269 return false;
270 }
271
272 *argp = NULL;
273 return false;
274 }
275
276 /* Fill in the canonical option part of *DECODED with an option
277 described by OPT_INDEX, ARG and VALUE. */
278
279 static void
280 generate_canonical_option (size_t opt_index, const char *arg, int value,
281 struct cl_decoded_option *decoded)
282 {
283 const struct cl_option *option = &cl_options[opt_index];
284 const char *opt_text = option->opt_text;
285
286 if (value == 0
287 && !option->cl_reject_negative
288 && (opt_text[1] == 'W' || opt_text[1] == 'f' || opt_text[1] == 'm'))
289 {
290 char *t = XOBNEWVEC (&opts_obstack, char, option->opt_len + 5);
291 t[0] = '-';
292 t[1] = opt_text[1];
293 t[2] = 'n';
294 t[3] = 'o';
295 t[4] = '-';
296 memcpy (t + 5, opt_text + 2, option->opt_len);
297 opt_text = t;
298 }
299
300 decoded->canonical_option[2] = NULL;
301 decoded->canonical_option[3] = NULL;
302
303 if (arg)
304 {
305 if ((option->flags & CL_SEPARATE)
306 && !option->cl_separate_alias)
307 {
308 decoded->canonical_option[0] = opt_text;
309 decoded->canonical_option[1] = arg;
310 decoded->canonical_option_num_elements = 2;
311 }
312 else
313 {
314 gcc_assert (option->flags & CL_JOINED);
315 decoded->canonical_option[0] = opts_concat (opt_text, arg, NULL);
316 decoded->canonical_option[1] = NULL;
317 decoded->canonical_option_num_elements = 1;
318 }
319 }
320 else
321 {
322 decoded->canonical_option[0] = opt_text;
323 decoded->canonical_option[1] = NULL;
324 decoded->canonical_option_num_elements = 1;
325 }
326 }
327
328 /* Structure describing mappings from options on the command line to
329 options to look up with find_opt. */
330 struct option_map
331 {
332 /* Prefix of the option on the command line. */
333 const char *opt0;
334 /* If two argv elements are considered to be merged into one option,
335 prefix for the second element, otherwise NULL. */
336 const char *opt1;
337 /* The new prefix to map to. */
338 const char *new_prefix;
339 /* Whether at least one character is needed following opt1 or opt0
340 for this mapping to be used. (--optimize= is valid for -O, but
341 --warn- is not valid for -W.) */
342 bool another_char_needed;
343 /* Whether the original option is a negated form of the option
344 resulting from this map. */
345 bool negated;
346 };
347 static const struct option_map option_map[] =
348 {
349 { "-Wno-", NULL, "-W", false, true },
350 { "-fno-", NULL, "-f", false, true },
351 { "-mno-", NULL, "-m", false, true },
352 { "--debug=", NULL, "-g", false, false },
353 { "--machine-", NULL, "-m", true, false },
354 { "--machine-no-", NULL, "-m", false, true },
355 { "--machine=", NULL, "-m", false, false },
356 { "--machine=no-", NULL, "-m", false, true },
357 { "--machine", "", "-m", false, false },
358 { "--machine", "no-", "-m", false, true },
359 { "--optimize=", NULL, "-O", false, false },
360 { "--std=", NULL, "-std=", false, false },
361 { "--std", "", "-std=", false, false },
362 { "--warn-", NULL, "-W", true, false },
363 { "--warn-no-", NULL, "-W", false, true },
364 { "--", NULL, "-f", true, false },
365 { "--no-", NULL, "-f", false, true }
366 };
367
368 /* Decode the switch beginning at ARGV for the language indicated by
369 LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into
370 the structure *DECODED. Returns the number of switches
371 consumed. */
372
373 static unsigned int
374 decode_cmdline_option (const char **argv, unsigned int lang_mask,
375 struct cl_decoded_option *decoded)
376 {
377 size_t opt_index;
378 const char *arg = 0;
379 int value = 1;
380 unsigned int result = 1, i, extra_args, separate_args = 0;
381 int adjust_len = 0;
382 size_t total_len;
383 char *p;
384 const struct cl_option *option;
385 int errors = 0;
386 const char *warn_message = NULL;
387 bool separate_arg_flag;
388 bool joined_arg_flag;
389 bool have_separate_arg = false;
390
391 extra_args = 0;
392
393 opt_index = find_opt (argv[0] + 1, lang_mask);
394 i = 0;
395 while (opt_index == OPT_SPECIAL_unknown
396 && i < ARRAY_SIZE (option_map))
397 {
398 const char *opt0 = option_map[i].opt0;
399 const char *opt1 = option_map[i].opt1;
400 const char *new_prefix = option_map[i].new_prefix;
401 bool another_char_needed = option_map[i].another_char_needed;
402 size_t opt0_len = strlen (opt0);
403 size_t opt1_len = (opt1 == NULL ? 0 : strlen (opt1));
404 size_t optn_len = (opt1 == NULL ? opt0_len : opt1_len);
405 size_t new_prefix_len = strlen (new_prefix);
406
407 extra_args = (opt1 == NULL ? 0 : 1);
408 value = !option_map[i].negated;
409
410 if (strncmp (argv[0], opt0, opt0_len) == 0
411 && (opt1 == NULL
412 || (argv[1] != NULL && strncmp (argv[1], opt1, opt1_len) == 0))
413 && (!another_char_needed
414 || argv[extra_args][optn_len] != 0))
415 {
416 size_t arglen = strlen (argv[extra_args]);
417 char *dup;
418
419 adjust_len = (int) optn_len - (int) new_prefix_len;
420 dup = XNEWVEC (char, arglen + 1 - adjust_len);
421 memcpy (dup, new_prefix, new_prefix_len);
422 memcpy (dup + new_prefix_len, argv[extra_args] + optn_len,
423 arglen - optn_len + 1);
424 opt_index = find_opt (dup + 1, lang_mask);
425 free (dup);
426 }
427 i++;
428 }
429
430 if (opt_index == OPT_SPECIAL_unknown)
431 {
432 arg = argv[0];
433 extra_args = 0;
434 value = 1;
435 goto done;
436 }
437
438 option = &cl_options[opt_index];
439
440 /* Reject negative form of switches that don't take negatives as
441 unrecognized. */
442 if (!value && option->cl_reject_negative)
443 {
444 opt_index = OPT_SPECIAL_unknown;
445 errors |= CL_ERR_NEGATIVE;
446 arg = argv[0];
447 goto done;
448 }
449
450 result = extra_args + 1;
451 warn_message = option->warn_message;
452
453 /* Check to see if the option is disabled for this configuration. */
454 if (option->cl_disabled)
455 errors |= CL_ERR_DISABLED;
456
457 /* Determine whether there may be a separate argument based on
458 whether this option is being processed for the driver, and, if
459 so, how many such arguments. */
460 separate_arg_flag = ((option->flags & CL_SEPARATE)
461 && !(option->cl_no_driver_arg
462 && (lang_mask & CL_DRIVER)));
463 separate_args = (separate_arg_flag
464 ? option->cl_separate_nargs + 1
465 : 0);
466 joined_arg_flag = (option->flags & CL_JOINED) != 0;
467
468 /* Sort out any argument the switch takes. */
469 if (joined_arg_flag)
470 {
471 /* Have arg point to the original switch. This is because
472 some code, such as disable_builtin_function, expects its
473 argument to be persistent until the program exits. */
474 arg = argv[extra_args] + cl_options[opt_index].opt_len + 1 + adjust_len;
475
476 if (*arg == '\0' && !option->cl_missing_ok)
477 {
478 if (separate_arg_flag)
479 {
480 arg = argv[extra_args + 1];
481 result = extra_args + 2;
482 if (arg == NULL)
483 result = extra_args + 1;
484 else
485 have_separate_arg = true;
486 }
487 else
488 /* Missing argument. */
489 arg = NULL;
490 }
491 }
492 else if (separate_arg_flag)
493 {
494 arg = argv[extra_args + 1];
495 for (i = 0; i < separate_args; i++)
496 if (argv[extra_args + 1 + i] == NULL)
497 {
498 errors |= CL_ERR_MISSING_ARG;
499 break;
500 }
501 result = extra_args + 1 + i;
502 if (arg != NULL)
503 have_separate_arg = true;
504 }
505
506 if (arg == NULL && (separate_arg_flag || joined_arg_flag))
507 errors |= CL_ERR_MISSING_ARG;
508
509 /* Is this option an alias (or an ignored option, marked as an alias
510 of OPT_SPECIAL_ignore)? */
511 if (option->alias_target != N_OPTS
512 && (!option->cl_separate_alias || have_separate_arg))
513 {
514 size_t new_opt_index = option->alias_target;
515
516 if (new_opt_index == OPT_SPECIAL_ignore)
517 {
518 gcc_assert (option->alias_arg == NULL);
519 gcc_assert (option->neg_alias_arg == NULL);
520 opt_index = new_opt_index;
521 arg = NULL;
522 value = 1;
523 }
524 else
525 {
526 const struct cl_option *new_option = &cl_options[new_opt_index];
527
528 /* The new option must not be an alias itself. */
529 gcc_assert (new_option->alias_target == N_OPTS
530 || new_option->cl_separate_alias);
531
532 if (option->neg_alias_arg)
533 {
534 gcc_assert (option->alias_arg != NULL);
535 gcc_assert (arg == NULL);
536 gcc_assert (!option->cl_negative_alias);
537 if (value)
538 arg = option->alias_arg;
539 else
540 arg = option->neg_alias_arg;
541 value = 1;
542 }
543 else if (option->alias_arg)
544 {
545 gcc_assert (value == 1);
546 gcc_assert (arg == NULL);
547 gcc_assert (!option->cl_negative_alias);
548 arg = option->alias_arg;
549 }
550
551 if (option->cl_negative_alias)
552 value = !value;
553
554 opt_index = new_opt_index;
555 option = new_option;
556
557 if (value == 0)
558 gcc_assert (!option->cl_reject_negative);
559
560 /* Recompute what arguments are allowed. */
561 separate_arg_flag = ((option->flags & CL_SEPARATE)
562 && !(option->cl_no_driver_arg
563 && (lang_mask & CL_DRIVER)));
564 joined_arg_flag = (option->flags & CL_JOINED) != 0;
565
566 if (separate_args > 1 || option->cl_separate_nargs)
567 gcc_assert (separate_args
568 == (unsigned int) option->cl_separate_nargs + 1);
569
570 if (!(errors & CL_ERR_MISSING_ARG))
571 {
572 if (separate_arg_flag || joined_arg_flag)
573 {
574 if (option->cl_missing_ok && arg == NULL)
575 arg = "";
576 gcc_assert (arg != NULL);
577 }
578 else
579 gcc_assert (arg == NULL);
580 }
581
582 /* Recheck for warnings and disabled options. */
583 if (option->warn_message)
584 {
585 gcc_assert (warn_message == NULL);
586 warn_message = option->warn_message;
587 }
588 if (option->cl_disabled)
589 errors |= CL_ERR_DISABLED;
590 }
591 }
592
593 /* Check if this is a switch for a different front end. */
594 if (!option_ok_for_language (option, lang_mask))
595 errors |= CL_ERR_WRONG_LANG;
596
597 /* Convert the argument to lowercase if appropriate. */
598 if (arg && option->cl_tolower)
599 {
600 size_t j;
601 size_t len = strlen (arg);
602 char *arg_lower = XOBNEWVEC (&opts_obstack, char, len + 1);
603
604 for (j = 0; j < len; j++)
605 arg_lower[j] = TOLOWER ((unsigned char) arg[j]);
606 arg_lower[len] = 0;
607 arg = arg_lower;
608 }
609
610 /* If the switch takes an integer, convert it. */
611 if (arg && option->cl_uinteger)
612 {
613 value = integral_argument (arg);
614 if (value == -1)
615 errors |= CL_ERR_UINT_ARG;
616 }
617
618 /* If the switch takes an enumerated argument, convert it. */
619 if (arg && (option->var_type == CLVC_ENUM))
620 {
621 const struct cl_enum *e = &cl_enums[option->var_enum];
622
623 gcc_assert (value == 1);
624 if (enum_arg_to_value (e->values, arg, &value, lang_mask))
625 {
626 const char *carg = NULL;
627
628 if (enum_value_to_arg (e->values, &carg, value, lang_mask))
629 arg = carg;
630 gcc_assert (carg != NULL);
631 }
632 else
633 errors |= CL_ERR_ENUM_ARG;
634 }
635
636 done:
637 decoded->opt_index = opt_index;
638 decoded->arg = arg;
639 decoded->value = value;
640 decoded->errors = errors;
641 decoded->warn_message = warn_message;
642
643 if (opt_index == OPT_SPECIAL_unknown)
644 gcc_assert (result == 1);
645
646 gcc_assert (result >= 1 && result <= ARRAY_SIZE (decoded->canonical_option));
647 decoded->canonical_option_num_elements = result;
648 total_len = 0;
649 for (i = 0; i < ARRAY_SIZE (decoded->canonical_option); i++)
650 {
651 if (i < result)
652 {
653 size_t len;
654 if (opt_index == OPT_SPECIAL_unknown)
655 decoded->canonical_option[i] = argv[i];
656 else
657 decoded->canonical_option[i] = NULL;
658 len = strlen (argv[i]);
659 /* If the argument is an empty string, we will print it as "" in
660 orig_option_with_args_text. */
661 total_len += (len != 0 ? len : 2) + 1;
662 }
663 else
664 decoded->canonical_option[i] = NULL;
665 }
666 if (opt_index != OPT_SPECIAL_unknown && opt_index != OPT_SPECIAL_ignore)
667 {
668 generate_canonical_option (opt_index, arg, value, decoded);
669 if (separate_args > 1)
670 {
671 for (i = 0; i < separate_args; i++)
672 {
673 if (argv[extra_args + 1 + i] == NULL)
674 break;
675 else
676 decoded->canonical_option[1 + i] = argv[extra_args + 1 + i];
677 }
678 gcc_assert (result == 1 + i);
679 decoded->canonical_option_num_elements = result;
680 }
681 }
682 decoded->orig_option_with_args_text
683 = p = XOBNEWVEC (&opts_obstack, char, total_len);
684 for (i = 0; i < result; i++)
685 {
686 size_t len = strlen (argv[i]);
687
688 /* Print the empty string verbally. */
689 if (len == 0)
690 {
691 *p++ = '"';
692 *p++ = '"';
693 }
694 else
695 memcpy (p, argv[i], len);
696 p += len;
697 if (i == result - 1)
698 *p++ = 0;
699 else
700 *p++ = ' ';
701 }
702
703 return result;
704 }
705
706 /* Obstack for option strings. */
707
708 struct obstack opts_obstack;
709
710 /* Like libiberty concat, but allocate using opts_obstack. */
711
712 char *
713 opts_concat (const char *first, ...)
714 {
715 char *newstr, *end;
716 size_t length = 0;
717 const char *arg;
718 va_list ap;
719
720 /* First compute the size of the result and get sufficient memory. */
721 va_start (ap, first);
722 for (arg = first; arg; arg = va_arg (ap, const char *))
723 length += strlen (arg);
724 newstr = XOBNEWVEC (&opts_obstack, char, length + 1);
725 va_end (ap);
726
727 /* Now copy the individual pieces to the result string. */
728 va_start (ap, first);
729 for (arg = first, end = newstr; arg; arg = va_arg (ap, const char *))
730 {
731 length = strlen (arg);
732 memcpy (end, arg, length);
733 end += length;
734 }
735 *end = '\0';
736 va_end (ap);
737 return newstr;
738 }
739
740 /* Decode command-line options (ARGC and ARGV being the arguments of
741 main) into an array, setting *DECODED_OPTIONS to a pointer to that
742 array and *DECODED_OPTIONS_COUNT to the number of entries in the
743 array. The first entry in the array is always one for the program
744 name (OPT_SPECIAL_program_name). LANG_MASK indicates the language
745 flags applicable for decoding (including CL_COMMON and CL_TARGET if
746 those options should be considered applicable). Do not produce any
747 diagnostics or set state outside of these variables. */
748
749 void
750 decode_cmdline_options_to_array (unsigned int argc, const char **argv,
751 unsigned int lang_mask,
752 struct cl_decoded_option **decoded_options,
753 unsigned int *decoded_options_count)
754 {
755 unsigned int n, i;
756 struct cl_decoded_option *opt_array;
757 unsigned int num_decoded_options;
758
759 opt_array = XNEWVEC (struct cl_decoded_option, argc);
760
761 opt_array[0].opt_index = OPT_SPECIAL_program_name;
762 opt_array[0].warn_message = NULL;
763 opt_array[0].arg = argv[0];
764 opt_array[0].orig_option_with_args_text = argv[0];
765 opt_array[0].canonical_option_num_elements = 1;
766 opt_array[0].canonical_option[0] = argv[0];
767 opt_array[0].canonical_option[1] = NULL;
768 opt_array[0].canonical_option[2] = NULL;
769 opt_array[0].canonical_option[3] = NULL;
770 opt_array[0].value = 1;
771 opt_array[0].errors = 0;
772 num_decoded_options = 1;
773
774 for (i = 1; i < argc; i += n)
775 {
776 const char *opt = argv[i];
777
778 /* Interpret "-" or a non-switch as a file name. */
779 if (opt[0] != '-' || opt[1] == '\0')
780 {
781 generate_option_input_file (opt, &opt_array[num_decoded_options]);
782 num_decoded_options++;
783 n = 1;
784 continue;
785 }
786
787 n = decode_cmdline_option (argv + i, lang_mask,
788 &opt_array[num_decoded_options]);
789 num_decoded_options++;
790 }
791
792 *decoded_options = opt_array;
793 *decoded_options_count = num_decoded_options;
794 prune_options (decoded_options, decoded_options_count);
795 }
796
797 /* Return true if NEXT_OPT_IDX cancels OPT_IDX. Return false if the
798 next one is the same as ORIG_NEXT_OPT_IDX. */
799
800 static bool
801 cancel_option (int opt_idx, int next_opt_idx, int orig_next_opt_idx)
802 {
803 /* An option can be canceled by the same option or an option with
804 Negative. */
805 if (cl_options [next_opt_idx].neg_index == opt_idx)
806 return true;
807
808 if (cl_options [next_opt_idx].neg_index != orig_next_opt_idx)
809 return cancel_option (opt_idx, cl_options [next_opt_idx].neg_index,
810 orig_next_opt_idx);
811
812 return false;
813 }
814
815 /* Filter out options canceled by the ones after them. */
816
817 static void
818 prune_options (struct cl_decoded_option **decoded_options,
819 unsigned int *decoded_options_count)
820 {
821 unsigned int old_decoded_options_count = *decoded_options_count;
822 struct cl_decoded_option *old_decoded_options = *decoded_options;
823 unsigned int new_decoded_options_count;
824 struct cl_decoded_option *new_decoded_options
825 = XNEWVEC (struct cl_decoded_option, old_decoded_options_count);
826 unsigned int i;
827 const struct cl_option *option;
828 unsigned int fdiagnostics_color_idx = 0;
829
830 /* Remove arguments which are negated by others after them. */
831 new_decoded_options_count = 0;
832 for (i = 0; i < old_decoded_options_count; i++)
833 {
834 unsigned int j, opt_idx, next_opt_idx;
835
836 if (old_decoded_options[i].errors & ~CL_ERR_WRONG_LANG)
837 goto keep;
838
839 opt_idx = old_decoded_options[i].opt_index;
840 switch (opt_idx)
841 {
842 case OPT_SPECIAL_unknown:
843 case OPT_SPECIAL_ignore:
844 case OPT_SPECIAL_program_name:
845 case OPT_SPECIAL_input_file:
846 goto keep;
847
848 /* Do not save OPT_fdiagnostics_color_, just remember the last one. */
849 case OPT_fdiagnostics_color_:
850 fdiagnostics_color_idx = i;
851 continue;
852
853 default:
854 gcc_assert (opt_idx < cl_options_count);
855 option = &cl_options[opt_idx];
856 if (option->neg_index < 0)
857 goto keep;
858
859 /* Skip joined switches. */
860 if ((option->flags & CL_JOINED))
861 goto keep;
862
863 for (j = i + 1; j < old_decoded_options_count; j++)
864 {
865 if (old_decoded_options[j].errors & ~CL_ERR_WRONG_LANG)
866 continue;
867 next_opt_idx = old_decoded_options[j].opt_index;
868 if (next_opt_idx >= cl_options_count)
869 continue;
870 if (cl_options[next_opt_idx].neg_index < 0)
871 continue;
872 if ((cl_options[next_opt_idx].flags & CL_JOINED))
873 continue;
874 if (cancel_option (opt_idx, next_opt_idx, next_opt_idx))
875 break;
876 }
877 if (j == old_decoded_options_count)
878 {
879 keep:
880 new_decoded_options[new_decoded_options_count]
881 = old_decoded_options[i];
882 new_decoded_options_count++;
883 }
884 break;
885 }
886 }
887
888 if (fdiagnostics_color_idx >= 1)
889 {
890 /* We put the last -fdiagnostics-color= at the first position
891 after argv[0] so it can take effect immediately. */
892 memmove (new_decoded_options + 2, new_decoded_options + 1,
893 sizeof (struct cl_decoded_option)
894 * (new_decoded_options_count - 1));
895 new_decoded_options[1] = old_decoded_options[fdiagnostics_color_idx];
896 new_decoded_options_count++;
897 }
898
899 free (old_decoded_options);
900 new_decoded_options = XRESIZEVEC (struct cl_decoded_option,
901 new_decoded_options,
902 new_decoded_options_count);
903 *decoded_options = new_decoded_options;
904 *decoded_options_count = new_decoded_options_count;
905 }
906
907 /* Handle option DECODED for the language indicated by LANG_MASK,
908 using the handlers in HANDLERS and setting fields in OPTS and
909 OPTS_SET. KIND is the diagnostic_t if this is a diagnostics
910 option, DK_UNSPECIFIED otherwise, and LOC is the location of the
911 option for options from the source file, UNKNOWN_LOCATION
912 otherwise. GENERATED_P is true for an option generated as part of
913 processing another option or otherwise generated internally, false
914 for one explicitly passed by the user. Returns false if the switch
915 was invalid. DC is the diagnostic context for options affecting
916 diagnostics state, or NULL. */
917
918 static bool
919 handle_option (struct gcc_options *opts,
920 struct gcc_options *opts_set,
921 const struct cl_decoded_option *decoded,
922 unsigned int lang_mask, int kind, location_t loc,
923 const struct cl_option_handlers *handlers,
924 bool generated_p, diagnostic_context *dc)
925 {
926 size_t opt_index = decoded->opt_index;
927 const char *arg = decoded->arg;
928 int value = decoded->value;
929 const struct cl_option *option = &cl_options[opt_index];
930 void *flag_var = option_flag_var (opt_index, opts);
931 size_t i;
932
933 if (flag_var)
934 set_option (opts, (generated_p ? NULL : opts_set),
935 opt_index, value, arg, kind, loc, dc);
936
937 for (i = 0; i < handlers->num_handlers; i++)
938 if (option->flags & handlers->handlers[i].mask)
939 {
940 if (!handlers->handlers[i].handler (opts, opts_set, decoded,
941 lang_mask, kind, loc,
942 handlers, dc))
943 return false;
944 }
945
946 return true;
947 }
948
949 /* Like handle_option, but OPT_INDEX, ARG and VALUE describe the
950 option instead of DECODED. This is used for callbacks when one
951 option implies another instead of an option being decoded from the
952 command line. */
953
954 bool
955 handle_generated_option (struct gcc_options *opts,
956 struct gcc_options *opts_set,
957 size_t opt_index, const char *arg, int value,
958 unsigned int lang_mask, int kind, location_t loc,
959 const struct cl_option_handlers *handlers,
960 diagnostic_context *dc)
961 {
962 struct cl_decoded_option decoded;
963
964 generate_option (opt_index, arg, value, lang_mask, &decoded);
965 return handle_option (opts, opts_set, &decoded, lang_mask, kind, loc,
966 handlers, true, dc);
967 }
968
969 /* Fill in *DECODED with an option described by OPT_INDEX, ARG and
970 VALUE for a front end using LANG_MASK. This is used when the
971 compiler generates options internally. */
972
973 void
974 generate_option (size_t opt_index, const char *arg, int value,
975 unsigned int lang_mask, struct cl_decoded_option *decoded)
976 {
977 const struct cl_option *option = &cl_options[opt_index];
978
979 decoded->opt_index = opt_index;
980 decoded->warn_message = NULL;
981 decoded->arg = arg;
982 decoded->value = value;
983 decoded->errors = (option_ok_for_language (option, lang_mask)
984 ? 0
985 : CL_ERR_WRONG_LANG);
986
987 generate_canonical_option (opt_index, arg, value, decoded);
988 switch (decoded->canonical_option_num_elements)
989 {
990 case 1:
991 decoded->orig_option_with_args_text = decoded->canonical_option[0];
992 break;
993
994 case 2:
995 decoded->orig_option_with_args_text
996 = opts_concat (decoded->canonical_option[0], " ",
997 decoded->canonical_option[1], NULL);
998 break;
999
1000 default:
1001 gcc_unreachable ();
1002 }
1003 }
1004
1005 /* Fill in *DECODED with an option for input file FILE. */
1006
1007 void
1008 generate_option_input_file (const char *file,
1009 struct cl_decoded_option *decoded)
1010 {
1011 decoded->opt_index = OPT_SPECIAL_input_file;
1012 decoded->warn_message = NULL;
1013 decoded->arg = file;
1014 decoded->orig_option_with_args_text = file;
1015 decoded->canonical_option_num_elements = 1;
1016 decoded->canonical_option[0] = file;
1017 decoded->canonical_option[1] = NULL;
1018 decoded->canonical_option[2] = NULL;
1019 decoded->canonical_option[3] = NULL;
1020 decoded->value = 1;
1021 decoded->errors = 0;
1022 }
1023
1024 /* Perform diagnostics for read_cmdline_option and control_warning_option
1025 functions. Returns true if an error has been diagnosed.
1026 LOC and LANG_MASK arguments like in read_cmdline_option.
1027 OPTION is the option to report diagnostics for, OPT the name
1028 of the option as text, ARG the argument of the option (for joined
1029 options), ERRORS is bitmask of CL_ERR_* values. */
1030
1031 static bool
1032 cmdline_handle_error (location_t loc, const struct cl_option *option,
1033 const char *opt, const char *arg, int errors,
1034 unsigned int lang_mask)
1035 {
1036 if (errors & CL_ERR_DISABLED)
1037 {
1038 error_at (loc, "command line option %qs"
1039 " is not supported by this configuration", opt);
1040 return true;
1041 }
1042
1043 if (errors & CL_ERR_MISSING_ARG)
1044 {
1045 if (option->missing_argument_error)
1046 error_at (loc, option->missing_argument_error, opt);
1047 else
1048 error_at (loc, "missing argument to %qs", opt);
1049 return true;
1050 }
1051
1052 if (errors & CL_ERR_UINT_ARG)
1053 {
1054 error_at (loc, "argument to %qs should be a non-negative integer",
1055 option->opt_text);
1056 return true;
1057 }
1058
1059 if (errors & CL_ERR_ENUM_ARG)
1060 {
1061 const struct cl_enum *e = &cl_enums[option->var_enum];
1062 unsigned int i;
1063 size_t len;
1064 char *s, *p;
1065
1066 if (e->unknown_error)
1067 error_at (loc, e->unknown_error, arg);
1068 else
1069 error_at (loc, "unrecognized argument in option %qs", opt);
1070
1071 len = 0;
1072 for (i = 0; e->values[i].arg != NULL; i++)
1073 len += strlen (e->values[i].arg) + 1;
1074
1075 s = XALLOCAVEC (char, len);
1076 p = s;
1077 for (i = 0; e->values[i].arg != NULL; i++)
1078 {
1079 if (!enum_arg_ok_for_language (&e->values[i], lang_mask))
1080 continue;
1081 size_t arglen = strlen (e->values[i].arg);
1082 memcpy (p, e->values[i].arg, arglen);
1083 p[arglen] = ' ';
1084 p += arglen + 1;
1085 }
1086 p[-1] = 0;
1087 inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
1088 return true;
1089 }
1090
1091 return false;
1092 }
1093
1094 /* Handle the switch DECODED (location LOC) for the language indicated
1095 by LANG_MASK, using the handlers in *HANDLERS and setting fields in
1096 OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
1097 diagnostic options. */
1098
1099 void
1100 read_cmdline_option (struct gcc_options *opts,
1101 struct gcc_options *opts_set,
1102 struct cl_decoded_option *decoded,
1103 location_t loc,
1104 unsigned int lang_mask,
1105 const struct cl_option_handlers *handlers,
1106 diagnostic_context *dc)
1107 {
1108 const struct cl_option *option;
1109 const char *opt = decoded->orig_option_with_args_text;
1110
1111 if (decoded->warn_message)
1112 warning_at (loc, 0, decoded->warn_message, opt);
1113
1114 if (decoded->opt_index == OPT_SPECIAL_unknown)
1115 {
1116 if (handlers->unknown_option_callback (decoded))
1117 error_at (loc, "unrecognized command line option %qs", decoded->arg);
1118 return;
1119 }
1120
1121 if (decoded->opt_index == OPT_SPECIAL_ignore)
1122 return;
1123
1124 option = &cl_options[decoded->opt_index];
1125
1126 if (decoded->errors
1127 && cmdline_handle_error (loc, option, opt, decoded->arg,
1128 decoded->errors, lang_mask))
1129 return;
1130
1131 if (decoded->errors & CL_ERR_WRONG_LANG)
1132 {
1133 handlers->wrong_lang_callback (decoded, lang_mask);
1134 return;
1135 }
1136
1137 gcc_assert (!decoded->errors);
1138
1139 if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
1140 loc, handlers, false, dc))
1141 error_at (loc, "unrecognized command line option %qs", opt);
1142 }
1143
1144 /* Set any field in OPTS, and OPTS_SET if not NULL, for option
1145 OPT_INDEX according to VALUE and ARG, diagnostic kind KIND,
1146 location LOC, using diagnostic context DC if not NULL for
1147 diagnostic classification. */
1148
1149 void
1150 set_option (struct gcc_options *opts, struct gcc_options *opts_set,
1151 int opt_index, int value, const char *arg, int kind,
1152 location_t loc, diagnostic_context *dc)
1153 {
1154 const struct cl_option *option = &cl_options[opt_index];
1155 void *flag_var = option_flag_var (opt_index, opts);
1156 void *set_flag_var = NULL;
1157
1158 if (!flag_var)
1159 return;
1160
1161 if ((diagnostic_t) kind != DK_UNSPECIFIED && dc != NULL)
1162 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
1163
1164 if (opts_set != NULL)
1165 set_flag_var = option_flag_var (opt_index, opts_set);
1166
1167 switch (option->var_type)
1168 {
1169 case CLVC_BOOLEAN:
1170 *(int *) flag_var = value;
1171 if (set_flag_var)
1172 *(int *) set_flag_var = 1;
1173 break;
1174
1175 case CLVC_EQUAL:
1176 if (option->cl_host_wide_int)
1177 *(HOST_WIDE_INT *) flag_var = (value
1178 ? option->var_value
1179 : !option->var_value);
1180 else
1181 *(int *) flag_var = (value
1182 ? option->var_value
1183 : !option->var_value);
1184 if (set_flag_var)
1185 *(int *) set_flag_var = 1;
1186 break;
1187
1188 case CLVC_BIT_CLEAR:
1189 case CLVC_BIT_SET:
1190 if ((value != 0) == (option->var_type == CLVC_BIT_SET))
1191 {
1192 if (option->cl_host_wide_int)
1193 *(HOST_WIDE_INT *) flag_var |= option->var_value;
1194 else
1195 *(int *) flag_var |= option->var_value;
1196 }
1197 else
1198 {
1199 if (option->cl_host_wide_int)
1200 *(HOST_WIDE_INT *) flag_var &= ~option->var_value;
1201 else
1202 *(int *) flag_var &= ~option->var_value;
1203 }
1204 if (set_flag_var)
1205 {
1206 if (option->cl_host_wide_int)
1207 *(HOST_WIDE_INT *) set_flag_var |= option->var_value;
1208 else
1209 *(int *) set_flag_var |= option->var_value;
1210 }
1211 break;
1212
1213 case CLVC_STRING:
1214 *(const char **) flag_var = arg;
1215 if (set_flag_var)
1216 *(const char **) set_flag_var = "";
1217 break;
1218
1219 case CLVC_ENUM:
1220 {
1221 const struct cl_enum *e = &cl_enums[option->var_enum];
1222
1223 e->set (flag_var, value);
1224 if (set_flag_var)
1225 e->set (set_flag_var, 1);
1226 }
1227 break;
1228
1229 case CLVC_DEFER:
1230 {
1231 vec<cl_deferred_option> *v
1232 = (vec<cl_deferred_option> *) *(void **) flag_var;
1233 cl_deferred_option p = {opt_index, arg, value};
1234 if (!v)
1235 v = XCNEW (vec<cl_deferred_option>);
1236 v->safe_push (p);
1237 *(void **) flag_var = v;
1238 if (set_flag_var)
1239 *(void **) set_flag_var = v;
1240 }
1241 break;
1242 }
1243 }
1244
1245 /* Return the address of the flag variable for option OPT_INDEX in
1246 options structure OPTS, or NULL if there is no flag variable. */
1247
1248 void *
1249 option_flag_var (int opt_index, struct gcc_options *opts)
1250 {
1251 const struct cl_option *option = &cl_options[opt_index];
1252
1253 if (option->flag_var_offset == (unsigned short) -1)
1254 return NULL;
1255 return (void *)(((char *) opts) + option->flag_var_offset);
1256 }
1257
1258 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
1259 or -1 if it isn't a simple on-off switch. */
1260
1261 int
1262 option_enabled (int opt_idx, void *opts)
1263 {
1264 const struct cl_option *option = &(cl_options[opt_idx]);
1265 struct gcc_options *optsg = (struct gcc_options *) opts;
1266 void *flag_var = option_flag_var (opt_idx, optsg);
1267
1268 if (flag_var)
1269 switch (option->var_type)
1270 {
1271 case CLVC_BOOLEAN:
1272 return *(int *) flag_var != 0;
1273
1274 case CLVC_EQUAL:
1275 if (option->cl_host_wide_int)
1276 return *(HOST_WIDE_INT *) flag_var == option->var_value;
1277 else
1278 return *(int *) flag_var == option->var_value;
1279
1280 case CLVC_BIT_CLEAR:
1281 if (option->cl_host_wide_int)
1282 return (*(HOST_WIDE_INT *) flag_var & option->var_value) == 0;
1283 else
1284 return (*(int *) flag_var & option->var_value) == 0;
1285
1286 case CLVC_BIT_SET:
1287 if (option->cl_host_wide_int)
1288 return (*(HOST_WIDE_INT *) flag_var & option->var_value) != 0;
1289 else
1290 return (*(int *) flag_var & option->var_value) != 0;
1291
1292 case CLVC_STRING:
1293 case CLVC_ENUM:
1294 case CLVC_DEFER:
1295 break;
1296 }
1297 return -1;
1298 }
1299
1300 /* Fill STATE with the current state of option OPTION in OPTS. Return
1301 true if there is some state to store. */
1302
1303 bool
1304 get_option_state (struct gcc_options *opts, int option,
1305 struct cl_option_state *state)
1306 {
1307 void *flag_var = option_flag_var (option, opts);
1308
1309 if (flag_var == 0)
1310 return false;
1311
1312 switch (cl_options[option].var_type)
1313 {
1314 case CLVC_BOOLEAN:
1315 case CLVC_EQUAL:
1316 state->data = flag_var;
1317 state->size = (cl_options[option].cl_host_wide_int
1318 ? sizeof (HOST_WIDE_INT)
1319 : sizeof (int));
1320 break;
1321
1322 case CLVC_BIT_CLEAR:
1323 case CLVC_BIT_SET:
1324 state->ch = option_enabled (option, opts);
1325 state->data = &state->ch;
1326 state->size = 1;
1327 break;
1328
1329 case CLVC_STRING:
1330 state->data = *(const char **) flag_var;
1331 if (state->data == 0)
1332 state->data = "";
1333 state->size = strlen ((const char *) state->data) + 1;
1334 break;
1335
1336 case CLVC_ENUM:
1337 state->data = flag_var;
1338 state->size = cl_enums[cl_options[option].var_enum].var_size;
1339 break;
1340
1341 case CLVC_DEFER:
1342 return false;
1343 }
1344 return true;
1345 }
1346
1347 /* Set a warning option OPT_INDEX (language mask LANG_MASK, option
1348 handlers HANDLERS) to have diagnostic kind KIND for option
1349 structures OPTS and OPTS_SET and diagnostic context DC (possibly
1350 NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). ARG is the
1351 argument of the option for joined options, or NULL otherwise. If IMPLY,
1352 the warning option in question is implied at this point. This is
1353 used by -Werror= and #pragma GCC diagnostic. */
1354
1355 void
1356 control_warning_option (unsigned int opt_index, int kind, const char *arg,
1357 bool imply, location_t loc, unsigned int lang_mask,
1358 const struct cl_option_handlers *handlers,
1359 struct gcc_options *opts,
1360 struct gcc_options *opts_set,
1361 diagnostic_context *dc)
1362 {
1363 if (cl_options[opt_index].alias_target != N_OPTS)
1364 {
1365 gcc_assert (!cl_options[opt_index].cl_separate_alias
1366 && !cl_options[opt_index].cl_negative_alias);
1367 if (cl_options[opt_index].alias_arg)
1368 arg = cl_options[opt_index].alias_arg;
1369 opt_index = cl_options[opt_index].alias_target;
1370 }
1371 if (opt_index == OPT_SPECIAL_ignore)
1372 return;
1373 if (dc)
1374 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
1375 if (imply)
1376 {
1377 const struct cl_option *option = &cl_options[opt_index];
1378
1379 /* -Werror=foo implies -Wfoo. */
1380 if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
1381 {
1382 int value = 1;
1383
1384 if (arg && *arg == '\0' && !option->cl_missing_ok)
1385 arg = NULL;
1386
1387 if ((option->flags & CL_JOINED) && arg == NULL)
1388 {
1389 cmdline_handle_error (loc, option, option->opt_text, arg,
1390 CL_ERR_MISSING_ARG, lang_mask);
1391 return;
1392 }
1393
1394 /* If the switch takes an integer, convert it. */
1395 if (arg && option->cl_uinteger)
1396 {
1397 value = integral_argument (arg);
1398 if (value == -1)
1399 {
1400 cmdline_handle_error (loc, option, option->opt_text, arg,
1401 CL_ERR_UINT_ARG, lang_mask);
1402 return;
1403 }
1404 }
1405
1406 /* If the switch takes an enumerated argument, convert it. */
1407 if (arg && option->var_type == CLVC_ENUM)
1408 {
1409 const struct cl_enum *e = &cl_enums[option->var_enum];
1410
1411 if (enum_arg_to_value (e->values, arg, &value, lang_mask))
1412 {
1413 const char *carg = NULL;
1414
1415 if (enum_value_to_arg (e->values, &carg, value, lang_mask))
1416 arg = carg;
1417 gcc_assert (carg != NULL);
1418 }
1419 else
1420 {
1421 cmdline_handle_error (loc, option, option->opt_text, arg,
1422 CL_ERR_ENUM_ARG, lang_mask);
1423 return;
1424 }
1425 }
1426
1427 handle_generated_option (opts, opts_set,
1428 opt_index, arg, value, lang_mask,
1429 kind, loc, handlers, dc);
1430 }
1431 }
1432 }