Mercurial > hg > CbC > CbC_gcc
comparison gcc/opts-common.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Command line option handling. | 1 /* Command line option handling. |
2 Copyright (C) 2006-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2006-2020 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 |
203 { | 203 { |
204 errno = 0; | 204 errno = 0; |
205 value = strtoull (arg, &end, 0); | 205 value = strtoull (arg, &end, 0); |
206 if (*end) | 206 if (*end) |
207 { | 207 { |
208 /* errno is most likely EINVAL here. */ | 208 if (errno) |
209 *err = errno; | 209 *err = errno; |
210 else | |
211 *err = EINVAL; | |
210 return -1; | 212 return -1; |
211 } | 213 } |
212 | 214 |
213 return value; | 215 return value; |
214 } | 216 } |
506 char *alternative = concat (opt0 + 1, opt_text + new_prefix_len, | 508 char *alternative = concat (opt0 + 1, opt_text + new_prefix_len, |
507 NULL); | 509 NULL); |
508 candidates->safe_push (alternative); | 510 candidates->safe_push (alternative); |
509 } | 511 } |
510 } | 512 } |
513 | |
514 /* For all params (e.g. --param=key=value), | |
515 include also '--param key=value'. */ | |
516 const char *prefix = "--param="; | |
517 if (strstr (opt_text, prefix) == opt_text) | |
518 { | |
519 char *param = xstrdup (opt_text + 1); | |
520 gcc_assert (param[6] == '='); | |
521 param[6] = ' '; | |
522 candidates->safe_push (param); | |
523 } | |
511 } | 524 } |
512 | 525 |
513 /* Decode the switch beginning at ARGV for the language indicated by | 526 /* Decode the switch beginning at ARGV for the language indicated by |
514 LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into | 527 LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into |
515 the structure *DECODED. Returns the number of switches | 528 the structure *DECODED. Returns the number of switches |
533 bool joined_arg_flag; | 546 bool joined_arg_flag; |
534 bool have_separate_arg = false; | 547 bool have_separate_arg = false; |
535 | 548 |
536 extra_args = 0; | 549 extra_args = 0; |
537 | 550 |
538 opt_index = find_opt (argv[0] + 1, lang_mask); | 551 const char *opt_value = argv[0] + 1; |
552 opt_index = find_opt (opt_value, lang_mask); | |
539 i = 0; | 553 i = 0; |
540 while (opt_index == OPT_SPECIAL_unknown | 554 while (opt_index == OPT_SPECIAL_unknown |
541 && i < ARRAY_SIZE (option_map)) | 555 && i < ARRAY_SIZE (option_map)) |
542 { | 556 { |
543 const char *opt0 = option_map[i].opt0; | 557 const char *opt0 = option_map[i].opt0; |
662 && (!option->cl_separate_alias || have_separate_arg)) | 676 && (!option->cl_separate_alias || have_separate_arg)) |
663 { | 677 { |
664 size_t new_opt_index = option->alias_target; | 678 size_t new_opt_index = option->alias_target; |
665 | 679 |
666 if (new_opt_index == OPT_SPECIAL_ignore | 680 if (new_opt_index == OPT_SPECIAL_ignore |
667 || new_opt_index == OPT_SPECIAL_deprecated) | 681 || new_opt_index == OPT_SPECIAL_warn_removed) |
668 { | 682 { |
669 gcc_assert (option->alias_arg == NULL); | 683 gcc_assert (option->alias_arg == NULL); |
670 gcc_assert (option->neg_alias_arg == NULL); | 684 gcc_assert (option->neg_alias_arg == NULL); |
671 opt_index = new_opt_index; | 685 opt_index = new_opt_index; |
672 arg = NULL; | 686 arg = NULL; |
741 } | 755 } |
742 | 756 |
743 /* Check if this is a switch for a different front end. */ | 757 /* Check if this is a switch for a different front end. */ |
744 if (!option_ok_for_language (option, lang_mask)) | 758 if (!option_ok_for_language (option, lang_mask)) |
745 errors |= CL_ERR_WRONG_LANG; | 759 errors |= CL_ERR_WRONG_LANG; |
760 else if (strcmp (option->opt_text, "-Werror=") == 0 | |
761 && strchr (opt_value, ',') == NULL) | |
762 { | |
763 /* Verify that -Werror argument is a valid warning | |
764 for a language. */ | |
765 char *werror_arg = xstrdup (opt_value + 6); | |
766 werror_arg[0] = 'W'; | |
767 | |
768 size_t warning_index = find_opt (werror_arg, lang_mask); | |
769 if (warning_index != OPT_SPECIAL_unknown) | |
770 { | |
771 const struct cl_option *warning_option | |
772 = &cl_options[warning_index]; | |
773 if (!option_ok_for_language (warning_option, lang_mask)) | |
774 errors |= CL_ERR_WRONG_LANG; | |
775 } | |
776 } | |
746 | 777 |
747 /* Convert the argument to lowercase if appropriate. */ | 778 /* Convert the argument to lowercase if appropriate. */ |
748 if (arg && option->cl_tolower) | 779 if (arg && option->cl_tolower) |
749 { | 780 { |
750 size_t j; | 781 size_t j; |
818 } | 849 } |
819 else | 850 else |
820 decoded->canonical_option[i] = NULL; | 851 decoded->canonical_option[i] = NULL; |
821 } | 852 } |
822 if (opt_index != OPT_SPECIAL_unknown && opt_index != OPT_SPECIAL_ignore | 853 if (opt_index != OPT_SPECIAL_unknown && opt_index != OPT_SPECIAL_ignore |
823 && opt_index != OPT_SPECIAL_deprecated) | 854 && opt_index != OPT_SPECIAL_warn_removed) |
824 { | 855 { |
825 generate_canonical_option (opt_index, arg, value, decoded); | 856 generate_canonical_option (opt_index, arg, value, decoded); |
826 if (separate_args > 1) | 857 if (separate_args > 1) |
827 { | 858 { |
828 for (i = 0; i < separate_args; i++) | 859 for (i = 0; i < separate_args; i++) |
939 num_decoded_options++; | 970 num_decoded_options++; |
940 n = 1; | 971 n = 1; |
941 continue; | 972 continue; |
942 } | 973 } |
943 | 974 |
975 /* Interpret "--param" "key=name" as "--param=key=name". */ | |
976 const char *needle = "--param"; | |
977 if (i + 1 < argc && strcmp (opt, needle) == 0) | |
978 { | |
979 const char *replacement | |
980 = opts_concat (needle, "=", argv[i + 1], NULL); | |
981 argv[++i] = replacement; | |
982 } | |
983 | |
944 n = decode_cmdline_option (argv + i, lang_mask, | 984 n = decode_cmdline_option (argv + i, lang_mask, |
945 &opt_array[num_decoded_options]); | 985 &opt_array[num_decoded_options]); |
946 num_decoded_options++; | 986 num_decoded_options++; |
947 } | 987 } |
948 | 988 |
996 opt_idx = old_decoded_options[i].opt_index; | 1036 opt_idx = old_decoded_options[i].opt_index; |
997 switch (opt_idx) | 1037 switch (opt_idx) |
998 { | 1038 { |
999 case OPT_SPECIAL_unknown: | 1039 case OPT_SPECIAL_unknown: |
1000 case OPT_SPECIAL_ignore: | 1040 case OPT_SPECIAL_ignore: |
1001 case OPT_SPECIAL_deprecated: | 1041 case OPT_SPECIAL_warn_removed: |
1002 case OPT_SPECIAL_program_name: | 1042 case OPT_SPECIAL_program_name: |
1003 case OPT_SPECIAL_input_file: | 1043 case OPT_SPECIAL_input_file: |
1004 goto keep; | 1044 goto keep; |
1005 | 1045 |
1006 /* Do not save OPT_fdiagnostics_color_, just remember the last one. */ | 1046 /* Do not save OPT_fdiagnostics_color_, just remember the last one. */ |
1013 option = &cl_options[opt_idx]; | 1053 option = &cl_options[opt_idx]; |
1014 if (option->neg_index < 0) | 1054 if (option->neg_index < 0) |
1015 goto keep; | 1055 goto keep; |
1016 | 1056 |
1017 /* Skip joined switches. */ | 1057 /* Skip joined switches. */ |
1018 if ((option->flags & CL_JOINED)) | 1058 if ((option->flags & CL_JOINED) |
1059 && (!option->cl_reject_negative | |
1060 || (unsigned int) option->neg_index != opt_idx)) | |
1019 goto keep; | 1061 goto keep; |
1020 | 1062 |
1021 for (j = i + 1; j < old_decoded_options_count; j++) | 1063 for (j = i + 1; j < old_decoded_options_count; j++) |
1022 { | 1064 { |
1023 if (old_decoded_options[j].errors & ~CL_ERR_WRONG_LANG) | 1065 if (old_decoded_options[j].errors & ~CL_ERR_WRONG_LANG) |
1025 next_opt_idx = old_decoded_options[j].opt_index; | 1067 next_opt_idx = old_decoded_options[j].opt_index; |
1026 if (next_opt_idx >= cl_options_count) | 1068 if (next_opt_idx >= cl_options_count) |
1027 continue; | 1069 continue; |
1028 if (cl_options[next_opt_idx].neg_index < 0) | 1070 if (cl_options[next_opt_idx].neg_index < 0) |
1029 continue; | 1071 continue; |
1030 if ((cl_options[next_opt_idx].flags & CL_JOINED)) | 1072 if ((cl_options[next_opt_idx].flags & CL_JOINED) |
1031 continue; | 1073 && (!cl_options[next_opt_idx].cl_reject_negative |
1074 || ((unsigned int) cl_options[next_opt_idx].neg_index | |
1075 != next_opt_idx))) | |
1076 continue; | |
1032 if (cancel_option (opt_idx, next_opt_idx, next_opt_idx)) | 1077 if (cancel_option (opt_idx, next_opt_idx, next_opt_idx)) |
1033 break; | 1078 break; |
1034 } | 1079 } |
1035 if (j == old_decoded_options_count) | 1080 if (j == old_decoded_options_count) |
1036 { | 1081 { |
1225 const char *opt, const char *arg, int errors, | 1270 const char *opt, const char *arg, int errors, |
1226 unsigned int lang_mask) | 1271 unsigned int lang_mask) |
1227 { | 1272 { |
1228 if (errors & CL_ERR_DISABLED) | 1273 if (errors & CL_ERR_DISABLED) |
1229 { | 1274 { |
1230 error_at (loc, "command line option %qs" | 1275 error_at (loc, "command-line option %qs" |
1231 " is not supported by this configuration", opt); | 1276 " is not supported by this configuration", opt); |
1232 return true; | 1277 return true; |
1233 } | 1278 } |
1234 | 1279 |
1235 if (errors & CL_ERR_MISSING_ARG) | 1280 if (errors & CL_ERR_MISSING_ARG) |
1314 warning_at (loc, 0, decoded->warn_message, opt); | 1359 warning_at (loc, 0, decoded->warn_message, opt); |
1315 | 1360 |
1316 if (decoded->opt_index == OPT_SPECIAL_unknown) | 1361 if (decoded->opt_index == OPT_SPECIAL_unknown) |
1317 { | 1362 { |
1318 if (handlers->unknown_option_callback (decoded)) | 1363 if (handlers->unknown_option_callback (decoded)) |
1319 error_at (loc, "unrecognized command line option %qs", decoded->arg); | 1364 error_at (loc, "unrecognized command-line option %qs", decoded->arg); |
1320 return; | 1365 return; |
1321 } | 1366 } |
1322 | 1367 |
1323 if (decoded->opt_index == OPT_SPECIAL_ignore) | 1368 if (decoded->opt_index == OPT_SPECIAL_ignore) |
1324 return; | 1369 return; |
1325 | 1370 |
1326 if (decoded->opt_index == OPT_SPECIAL_deprecated) | 1371 if (decoded->opt_index == OPT_SPECIAL_warn_removed) |
1327 { | 1372 { |
1328 /* Warn only about positive ignored options. */ | 1373 /* Warn only about positive ignored options. */ |
1329 if (decoded->value) | 1374 if (decoded->value) |
1330 warning_at (loc, 0, "switch %qs is no longer supported", opt); | 1375 warning_at (loc, 0, "switch %qs is no longer supported", opt); |
1331 return; | 1376 return; |
1346 | 1391 |
1347 gcc_assert (!decoded->errors); | 1392 gcc_assert (!decoded->errors); |
1348 | 1393 |
1349 if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED, | 1394 if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED, |
1350 loc, handlers, false, dc)) | 1395 loc, handlers, false, dc)) |
1351 error_at (loc, "unrecognized command line option %qs", opt); | 1396 error_at (loc, "unrecognized command-line option %qs", opt); |
1352 } | 1397 } |
1353 | 1398 |
1354 /* Set any field in OPTS, and OPTS_SET if not NULL, for option | 1399 /* Set any field in OPTS, and OPTS_SET if not NULL, for option |
1355 OPT_INDEX according to VALUE and ARG, diagnostic kind KIND, | 1400 OPT_INDEX according to VALUE and ARG, diagnostic kind KIND, |
1356 location LOC, using diagnostic context DC if not NULL for | 1401 location LOC, using diagnostic context DC if not NULL for |
1499 | 1544 |
1500 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled, | 1545 /* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled, |
1501 or -1 if it isn't a simple on-off switch. */ | 1546 or -1 if it isn't a simple on-off switch. */ |
1502 | 1547 |
1503 int | 1548 int |
1504 option_enabled (int opt_idx, void *opts) | 1549 option_enabled (int opt_idx, unsigned lang_mask, void *opts) |
1505 { | 1550 { |
1506 const struct cl_option *option = &(cl_options[opt_idx]); | 1551 const struct cl_option *option = &(cl_options[opt_idx]); |
1552 | |
1553 /* A language-specific option can only be considered enabled when it's | |
1554 valid for the current language. */ | |
1555 if (!(option->flags & CL_COMMON) | |
1556 && (option->flags & CL_LANG_ALL) | |
1557 && !(option->flags & lang_mask)) | |
1558 return 0; | |
1559 | |
1507 struct gcc_options *optsg = (struct gcc_options *) opts; | 1560 struct gcc_options *optsg = (struct gcc_options *) opts; |
1508 void *flag_var = option_flag_var (opt_idx, optsg); | 1561 void *flag_var = option_flag_var (opt_idx, optsg); |
1509 | 1562 |
1510 if (flag_var) | 1563 if (flag_var) |
1511 switch (option->var_type) | 1564 switch (option->var_type) |
1571 : sizeof (int)); | 1624 : sizeof (int)); |
1572 break; | 1625 break; |
1573 | 1626 |
1574 case CLVC_BIT_CLEAR: | 1627 case CLVC_BIT_CLEAR: |
1575 case CLVC_BIT_SET: | 1628 case CLVC_BIT_SET: |
1576 state->ch = option_enabled (option, opts); | 1629 state->ch = option_enabled (option, -1, opts); |
1577 state->data = &state->ch; | 1630 state->data = &state->ch; |
1578 state->size = 1; | 1631 state->size = 1; |
1579 break; | 1632 break; |
1580 | 1633 |
1581 case CLVC_STRING: | 1634 case CLVC_STRING: |
1618 && !cl_options[opt_index].cl_negative_alias); | 1671 && !cl_options[opt_index].cl_negative_alias); |
1619 if (cl_options[opt_index].alias_arg) | 1672 if (cl_options[opt_index].alias_arg) |
1620 arg = cl_options[opt_index].alias_arg; | 1673 arg = cl_options[opt_index].alias_arg; |
1621 opt_index = cl_options[opt_index].alias_target; | 1674 opt_index = cl_options[opt_index].alias_target; |
1622 } | 1675 } |
1623 if (opt_index == OPT_SPECIAL_ignore || opt_index == OPT_SPECIAL_deprecated) | 1676 if (opt_index == OPT_SPECIAL_ignore || opt_index == OPT_SPECIAL_warn_removed) |
1624 return; | 1677 return; |
1625 if (dc) | 1678 if (dc) |
1626 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc); | 1679 diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc); |
1627 if (imply) | 1680 if (imply) |
1628 { | 1681 { |