Mercurial > hg > CbC > CbC_gcc
comparison gcc/opts.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Command line option handling. | 1 /* Command line option handling. |
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 | 2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Contributed by Neil Booth. | 4 Contributed by Neil Booth. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
370 /* Input file names. */ | 370 /* Input file names. */ |
371 const char **in_fnames; | 371 const char **in_fnames; |
372 unsigned num_in_fnames; | 372 unsigned num_in_fnames; |
373 | 373 |
374 static int common_handle_option (size_t scode, const char *arg, int value, | 374 static int common_handle_option (size_t scode, const char *arg, int value, |
375 unsigned int lang_mask); | 375 unsigned int lang_mask, int kind); |
376 static void handle_param (const char *); | 376 static void handle_param (const char *); |
377 static unsigned int handle_option (const char **argv, unsigned int lang_mask); | |
378 static char *write_langs (unsigned int lang_mask); | 377 static char *write_langs (unsigned int lang_mask); |
379 static void complain_wrong_lang (const char *, const struct cl_option *, | 378 static void complain_wrong_lang (const char *, const struct cl_option *, |
380 unsigned int lang_mask); | 379 unsigned int lang_mask); |
381 static void handle_options (unsigned int, const char **, unsigned int); | |
382 static void set_debug_level (enum debug_info_type type, int extended, | 380 static void set_debug_level (enum debug_info_type type, int extended, |
383 const char *arg); | 381 const char *arg); |
384 | 382 |
385 /* If ARG is a non-negative integer made up solely of digits, return its | 383 /* If ARG is a non-negative integer made up solely of digits, return its |
386 value, otherwise return -1. */ | 384 value, otherwise return -1. */ |
483 } | 481 } |
484 | 482 |
485 input_location = saved_loc; | 483 input_location = saved_loc; |
486 } | 484 } |
487 | 485 |
486 | |
487 /* Handle option OPT_INDEX, and argument ARG, for the language | |
488 indicated by LANG_MASK. VALUE is true, unless no- form of an -f or | |
489 -W option was given. KIND is the diagnostic_t if this is a | |
490 diagnostics option, DK_UNSPECIFIED otherwise. Returns false if the | |
491 switch was invalid. */ | |
492 bool | |
493 handle_option (int opt_index, int value, const char *arg, | |
494 unsigned int lang_mask, int kind) | |
495 { | |
496 const struct cl_option *option = &cl_options[opt_index]; | |
497 | |
498 if (option->flag_var) | |
499 set_option (opt_index, value, arg, kind); | |
500 | |
501 if (option->flags & lang_mask) | |
502 { | |
503 if (lang_hooks.handle_option (opt_index, arg, value, kind) == 0) | |
504 return false; | |
505 #ifdef ENABLE_LTO | |
506 else | |
507 lto_register_user_option (opt_index, arg, value, lang_mask); | |
508 #endif | |
509 } | |
510 | |
511 if (option->flags & CL_COMMON) | |
512 { | |
513 if (common_handle_option (opt_index, arg, value, lang_mask, kind) == 0) | |
514 return false; | |
515 #ifdef ENABLE_LTO | |
516 else | |
517 lto_register_user_option (opt_index, arg, value, CL_COMMON); | |
518 #endif | |
519 } | |
520 | |
521 if (option->flags & CL_TARGET) | |
522 { | |
523 if (!targetm.handle_option (opt_index, arg, value)) | |
524 return false; | |
525 #ifdef ENABLE_LTO | |
526 else | |
527 lto_register_user_option (opt_index, arg, value, CL_TARGET); | |
528 #endif | |
529 } | |
530 return true; | |
531 } | |
532 | |
488 /* Handle the switch beginning at ARGV for the language indicated by | 533 /* Handle the switch beginning at ARGV for the language indicated by |
489 LANG_MASK. Returns the number of switches consumed. */ | 534 LANG_MASK. Returns the number of switches consumed. */ |
490 static unsigned int | 535 static unsigned int |
491 handle_option (const char **argv, unsigned int lang_mask) | 536 read_cmdline_option (const char **argv, unsigned int lang_mask) |
492 { | 537 { |
493 size_t opt_index; | 538 size_t opt_index; |
494 const char *opt, *arg = 0; | 539 const char *opt, *arg = 0; |
495 char *dup = 0; | 540 char *dup = 0; |
496 int value = 1; | 541 int value = 1; |
607 option->opt_text); | 652 option->opt_text); |
608 goto done; | 653 goto done; |
609 } | 654 } |
610 } | 655 } |
611 | 656 |
612 if (option->flag_var) | 657 if (!handle_option (opt_index, value, arg, lang_mask, DK_UNSPECIFIED)) |
613 set_option (option, value, arg); | 658 result = 0; |
614 | |
615 if (option->flags & lang_mask) | |
616 { | |
617 if (lang_hooks.handle_option (opt_index, arg, value) == 0) | |
618 result = 0; | |
619 else | |
620 lto_register_user_option (opt_index, arg, value, lang_mask); | |
621 } | |
622 | |
623 if (result && (option->flags & CL_COMMON)) | |
624 { | |
625 if (common_handle_option (opt_index, arg, value, lang_mask) == 0) | |
626 result = 0; | |
627 else | |
628 lto_register_user_option (opt_index, arg, value, CL_COMMON); | |
629 } | |
630 | |
631 if (result && (option->flags & CL_TARGET)) | |
632 { | |
633 if (!targetm.handle_option (opt_index, arg, value)) | |
634 result = 0; | |
635 else | |
636 lto_register_user_option (opt_index, arg, value, CL_TARGET); | |
637 } | |
638 | 659 |
639 done: | 660 done: |
640 if (dup) | 661 if (dup) |
641 free (dup); | 662 free (dup); |
642 return result; | 663 return result; |
733 | 754 |
734 /* Decode and handle the vector of command line options. LANG_MASK | 755 /* Decode and handle the vector of command line options. LANG_MASK |
735 contains has a single bit set representing the current | 756 contains has a single bit set representing the current |
736 language. */ | 757 language. */ |
737 static void | 758 static void |
738 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask) | 759 read_cmdline_options (unsigned int argc, const char **argv, unsigned int lang_mask) |
739 { | 760 { |
740 unsigned int n, i; | 761 unsigned int n, i; |
741 | 762 |
742 for (i = 1; i < argc; i += n) | 763 for (i = 1; i < argc; i += n) |
743 { | 764 { |
755 add_input_filename (opt); | 776 add_input_filename (opt); |
756 n = 1; | 777 n = 1; |
757 continue; | 778 continue; |
758 } | 779 } |
759 | 780 |
760 n = handle_option (argv + i, lang_mask); | 781 n = read_cmdline_option (argv + i, lang_mask); |
761 | 782 |
762 if (!n) | 783 if (!n) |
763 { | 784 { |
764 n = 1; | 785 n = 1; |
765 error ("unrecognized command line option \"%s\"", opt); | 786 error ("unrecognized command line option \"%s\"", opt); |
856 flag_forward_propagate = opt1; | 877 flag_forward_propagate = opt1; |
857 flag_if_conversion = opt1; | 878 flag_if_conversion = opt1; |
858 flag_if_conversion2 = opt1; | 879 flag_if_conversion2 = opt1; |
859 flag_ipa_pure_const = opt1; | 880 flag_ipa_pure_const = opt1; |
860 flag_ipa_reference = opt1; | 881 flag_ipa_reference = opt1; |
882 flag_ipa_profile = opt1; | |
861 flag_merge_constants = opt1; | 883 flag_merge_constants = opt1; |
862 flag_split_wide_types = opt1; | 884 flag_split_wide_types = opt1; |
863 flag_tree_ccp = opt1; | 885 flag_tree_ccp = opt1; |
864 flag_tree_dce = opt1; | 886 flag_tree_dce = opt1; |
865 flag_tree_dom = opt1; | 887 flag_tree_dom = opt1; |
896 flag_reorder_blocks = opt2; | 918 flag_reorder_blocks = opt2; |
897 flag_reorder_functions = opt2; | 919 flag_reorder_functions = opt2; |
898 flag_tree_vrp = opt2; | 920 flag_tree_vrp = opt2; |
899 flag_tree_builtin_call_dce = opt2; | 921 flag_tree_builtin_call_dce = opt2; |
900 flag_tree_pre = opt2; | 922 flag_tree_pre = opt2; |
901 flag_tree_switch_conversion = 1; | 923 flag_tree_switch_conversion = opt2; |
902 flag_ipa_cp = opt2; | 924 flag_ipa_cp = opt2; |
903 flag_ipa_sra = opt2; | 925 flag_ipa_sra = opt2; |
904 | 926 |
905 /* Track fields in field-sensitive alias analysis. */ | 927 /* Track fields in field-sensitive alias analysis. */ |
906 set_param_value ("max-fields-for-field-sensitive", | 928 set_param_value ("max-fields-for-field-sensitive", |
943 set_param_value ("min-crossjump-insns", 1); | 965 set_param_value ("min-crossjump-insns", 1); |
944 } | 966 } |
945 else | 967 else |
946 set_param_value ("min-crossjump-insns", initial_min_crossjump_insns); | 968 set_param_value ("min-crossjump-insns", initial_min_crossjump_insns); |
947 | 969 |
970 /* Enable -Werror=coverage-mismatch by default */ | |
971 enable_warning_as_error("coverage-mismatch", 1, lang_mask); | |
972 | |
948 if (first_time_p) | 973 if (first_time_p) |
949 { | 974 { |
950 /* Initialize whether `char' is signed. */ | 975 /* Initialize whether `char' is signed. */ |
951 flag_signed_char = DEFAULT_SIGNED_CHAR; | 976 flag_signed_char = DEFAULT_SIGNED_CHAR; |
952 /* Set this to a special "uninitialized" value. The actual default is | 977 /* Set this to a special "uninitialized" value. The actual default is |
959 | 984 |
960 /* Some targets have ABI-specified unwind tables. */ | 985 /* Some targets have ABI-specified unwind tables. */ |
961 flag_unwind_tables = targetm.unwind_tables_default; | 986 flag_unwind_tables = targetm.unwind_tables_default; |
962 } | 987 } |
963 | 988 |
989 #ifdef ENABLE_LTO | |
964 /* Clear any options currently held for LTO. */ | 990 /* Clear any options currently held for LTO. */ |
965 lto_clear_user_options (); | 991 lto_clear_user_options (); |
992 #endif | |
966 | 993 |
967 #ifdef OPTIMIZATION_OPTIONS | 994 #ifdef OPTIMIZATION_OPTIONS |
968 /* Allow default optimizations to be specified on a per-machine basis. */ | 995 /* Allow default optimizations to be specified on a per-machine basis. */ |
969 OPTIMIZATION_OPTIONS (optimize, optimize_size); | 996 OPTIMIZATION_OPTIONS (optimize, optimize_size); |
970 #endif | 997 #endif |
971 | 998 |
972 handle_options (argc, argv, lang_mask); | 999 read_cmdline_options (argc, argv, lang_mask); |
973 | 1000 |
974 /* Make DUMP_BASE_NAME relative to the AUX_BASE_NAME directory, | 1001 if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name)) |
975 typically the directory to contain the object file. */ | 1002 { |
976 if (aux_base_name && ! IS_ABSOLUTE_PATH (dump_base_name)) | 1003 /* First try to make DUMP_BASE_NAME relative to the DUMP_DIR_NAME |
977 { | 1004 directory. Then try to make DUMP_BASE_NAME relative to the |
978 const char *aux_base; | 1005 AUX_BASE_NAME directory, typically the directory to contain |
979 | 1006 the object file. */ |
980 base_of_path (aux_base_name, &aux_base); | 1007 if (dump_dir_name) |
981 if (aux_base_name != aux_base) | 1008 dump_base_name = concat (dump_dir_name, dump_base_name, NULL); |
982 { | 1009 else if (aux_base_name) |
983 int dir_len = aux_base - aux_base_name; | 1010 { |
984 char *new_dump_base_name = | 1011 const char *aux_base; |
985 XNEWVEC (char, strlen(dump_base_name) + dir_len + 1); | 1012 |
986 | 1013 base_of_path (aux_base_name, &aux_base); |
987 /* Copy directory component from AUX_BASE_NAME. */ | 1014 if (aux_base_name != aux_base) |
988 memcpy (new_dump_base_name, aux_base_name, dir_len); | 1015 { |
989 /* Append existing DUMP_BASE_NAME. */ | 1016 int dir_len = aux_base - aux_base_name; |
990 strcpy (new_dump_base_name + dir_len, dump_base_name); | 1017 char *new_dump_base_name = |
991 dump_base_name = new_dump_base_name; | 1018 XNEWVEC (char, strlen(dump_base_name) + dir_len + 1); |
1019 | |
1020 /* Copy directory component from AUX_BASE_NAME. */ | |
1021 memcpy (new_dump_base_name, aux_base_name, dir_len); | |
1022 /* Append existing DUMP_BASE_NAME. */ | |
1023 strcpy (new_dump_base_name + dir_len, dump_base_name); | |
1024 dump_base_name = new_dump_base_name; | |
1025 } | |
992 } | 1026 } |
993 } | 1027 } |
994 | 1028 |
995 /* Handle related options for unit-at-a-time, toplevel-reorder, and | 1029 /* Handle related options for unit-at-a-time, toplevel-reorder, and |
996 section-anchors. */ | 1030 section-anchors. */ |
1025 { | 1059 { |
1026 if (flag_pie) | 1060 if (flag_pie) |
1027 flag_pic = flag_pie; | 1061 flag_pic = flag_pie; |
1028 if (flag_pic && !flag_pie) | 1062 if (flag_pic && !flag_pie) |
1029 flag_shlib = 1; | 1063 flag_shlib = 1; |
1064 first_time_p = false; | |
1030 } | 1065 } |
1031 | 1066 |
1032 if (optimize == 0) | 1067 if (optimize == 0) |
1033 { | 1068 { |
1034 /* Inlining does not work if not optimizing, | 1069 /* Inlining does not work if not optimizing, |
1103 inform (input_location, | 1138 inform (input_location, |
1104 "-fira-algorithm=CB does not work on this architecture"); | 1139 "-fira-algorithm=CB does not work on this architecture"); |
1105 flag_ira_algorithm = IRA_ALGORITHM_PRIORITY; | 1140 flag_ira_algorithm = IRA_ALGORITHM_PRIORITY; |
1106 } | 1141 } |
1107 | 1142 |
1108 /* Save the current optimization options if this is the first call. */ | |
1109 if (first_time_p) | |
1110 { | |
1111 optimization_default_node = build_optimization_node (); | |
1112 optimization_current_node = optimization_default_node; | |
1113 first_time_p = false; | |
1114 } | |
1115 if (flag_conserve_stack) | 1143 if (flag_conserve_stack) |
1116 { | 1144 { |
1117 if (!PARAM_SET_P (PARAM_LARGE_STACK_FRAME)) | 1145 if (!PARAM_SET_P (PARAM_LARGE_STACK_FRAME)) |
1118 PARAM_VALUE (PARAM_LARGE_STACK_FRAME) = 100; | 1146 PARAM_VALUE (PARAM_LARGE_STACK_FRAME) = 100; |
1119 if (!PARAM_SET_P (PARAM_STACK_FRAME_GROWTH)) | 1147 if (!PARAM_SET_P (PARAM_STACK_FRAME_GROWTH)) |
1120 PARAM_VALUE (PARAM_STACK_FRAME_GROWTH) = 40; | 1148 PARAM_VALUE (PARAM_STACK_FRAME_GROWTH) = 40; |
1149 } | |
1150 if (flag_wpa || flag_ltrans) | |
1151 { | |
1152 /* These passes are not WHOPR compatible yet. */ | |
1153 flag_ipa_pta = 0; | |
1154 flag_ipa_struct_reorg = 0; | |
1121 } | 1155 } |
1122 | 1156 |
1123 if (flag_lto || flag_whopr) | 1157 if (flag_lto || flag_whopr) |
1124 { | 1158 { |
1125 #ifdef ENABLE_LTO | 1159 #ifdef ENABLE_LTO |
1451 extra handling need to be listed here; if you simply want | 1485 extra handling need to be listed here; if you simply want |
1452 VALUE assigned to a variable, it happens automatically. */ | 1486 VALUE assigned to a variable, it happens automatically. */ |
1453 | 1487 |
1454 static int | 1488 static int |
1455 common_handle_option (size_t scode, const char *arg, int value, | 1489 common_handle_option (size_t scode, const char *arg, int value, |
1456 unsigned int lang_mask) | 1490 unsigned int lang_mask, int kind ATTRIBUTE_UNUSED) |
1457 { | 1491 { |
1458 static bool verbose = false; | 1492 static bool verbose = false; |
1459 enum opt_code code = (enum opt_code) scode; | 1493 enum opt_code code = (enum opt_code) scode; |
1460 | 1494 |
1461 switch (code) | 1495 switch (code) |
1699 | 1733 |
1700 case OPT_dumpbase: | 1734 case OPT_dumpbase: |
1701 dump_base_name = arg; | 1735 dump_base_name = arg; |
1702 break; | 1736 break; |
1703 | 1737 |
1738 case OPT_dumpdir: | |
1739 dump_dir_name = arg; | |
1740 break; | |
1741 | |
1704 case OPT_falign_functions_: | 1742 case OPT_falign_functions_: |
1705 align_functions = value; | 1743 align_functions = value; |
1706 break; | 1744 break; |
1707 | 1745 |
1708 case OPT_falign_jumps_: | 1746 case OPT_falign_jumps_: |
1750 else | 1788 else |
1751 return 0; | 1789 return 0; |
1752 break; | 1790 break; |
1753 | 1791 |
1754 case OPT_fdiagnostics_show_option: | 1792 case OPT_fdiagnostics_show_option: |
1755 global_dc->show_option_requested = true; | 1793 global_dc->show_option_requested = value; |
1756 break; | 1794 break; |
1757 | 1795 |
1758 case OPT_fdump_: | 1796 case OPT_fdump_: |
1759 if (!dump_switch_p (arg)) | 1797 if (!dump_switch_p (arg)) |
1760 return 0; | 1798 return 0; |
2109 | 2147 |
2110 case OPT_pedantic_errors: | 2148 case OPT_pedantic_errors: |
2111 flag_pedantic_errors = pedantic = 1; | 2149 flag_pedantic_errors = pedantic = 1; |
2112 break; | 2150 break; |
2113 | 2151 |
2152 case OPT_fwhopr: | |
2153 flag_whopr = value; | |
2154 break; | |
2155 | |
2114 case OPT_fsee: | 2156 case OPT_fsee: |
2115 case OPT_fcse_skip_blocks: | 2157 case OPT_fcse_skip_blocks: |
2116 case OPT_floop_optimize: | 2158 case OPT_floop_optimize: |
2117 case OPT_frerun_loop_opt: | 2159 case OPT_frerun_loop_opt: |
2160 case OPT_fsched2_use_traces: | |
2118 case OPT_fstrength_reduce: | 2161 case OPT_fstrength_reduce: |
2119 case OPT_ftree_store_copy_prop: | 2162 case OPT_ftree_store_copy_prop: |
2120 case OPT_fforce_addr: | 2163 case OPT_fforce_addr: |
2121 case OPT_ftree_salias: | 2164 case OPT_ftree_salias: |
2122 case OPT_ftree_store_ccp: | 2165 case OPT_ftree_store_ccp: |
2166 case OPT_Wunreachable_code: | |
2167 case OPT_fargument_alias: | |
2168 case OPT_fargument_noalias: | |
2169 case OPT_fargument_noalias_anything: | |
2170 case OPT_fargument_noalias_global: | |
2123 /* These are no-ops, preserved for backward compatibility. */ | 2171 /* These are no-ops, preserved for backward compatibility. */ |
2124 break; | 2172 break; |
2125 | 2173 |
2126 case OPT_fuse_linker_plugin: | 2174 case OPT_fuse_linker_plugin: |
2127 /* No-op. Used by the driver and passed to us because it starts with f.*/ | 2175 /* No-op. Used by the driver and passed to us because it starts with f.*/ |
2350 } | 2398 } |
2351 | 2399 |
2352 /* Set *OPTION according to VALUE and ARG. */ | 2400 /* Set *OPTION according to VALUE and ARG. */ |
2353 | 2401 |
2354 void | 2402 void |
2355 set_option (const struct cl_option *option, int value, const char *arg) | 2403 set_option (int opt_index, int value, const char *arg, int kind) |
2356 { | 2404 { |
2405 const struct cl_option *option = &cl_options[opt_index]; | |
2406 | |
2357 if (!option->flag_var) | 2407 if (!option->flag_var) |
2358 return; | 2408 return; |
2359 | 2409 |
2360 switch (option->var_type) | 2410 switch (option->var_type) |
2361 { | 2411 { |
2381 | 2431 |
2382 case CLVC_STRING: | 2432 case CLVC_STRING: |
2383 *(const char **) option->flag_var = arg; | 2433 *(const char **) option->flag_var = arg; |
2384 break; | 2434 break; |
2385 } | 2435 } |
2436 | |
2437 if ((diagnostic_t)kind != DK_UNSPECIFIED) | |
2438 diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t)kind); | |
2439 } | |
2440 | |
2441 | |
2442 /* Callback function, called when -Werror= enables a warning. */ | |
2443 | |
2444 static void (*warning_as_error_callback) (int) = NULL; | |
2445 | |
2446 /* Register a callback for enable_warning_as_error calls. */ | |
2447 | |
2448 void | |
2449 register_warning_as_error_callback (void (*callback) (int)) | |
2450 { | |
2451 gcc_assert (warning_as_error_callback == NULL || callback == NULL); | |
2452 warning_as_error_callback = callback; | |
2386 } | 2453 } |
2387 | 2454 |
2388 /* Enable a warning option as an error. This is used by -Werror= and | 2455 /* Enable a warning option as an error. This is used by -Werror= and |
2389 also by legacy Werror-implicit-function-declaration. */ | 2456 also by legacy Werror-implicit-function-declaration. */ |
2390 | 2457 |
2402 { | 2469 { |
2403 error ("-Werror=%s: No option -%s", arg, new_option); | 2470 error ("-Werror=%s: No option -%s", arg, new_option); |
2404 } | 2471 } |
2405 else | 2472 else |
2406 { | 2473 { |
2407 diagnostic_t kind = value ? DK_ERROR : DK_WARNING; | 2474 const diagnostic_t kind = value ? DK_ERROR : DK_WARNING; |
2475 | |
2408 diagnostic_classify_diagnostic (global_dc, option_index, kind); | 2476 diagnostic_classify_diagnostic (global_dc, option_index, kind); |
2409 | 2477 if (kind == DK_ERROR) |
2410 /* -Werror=foo implies -Wfoo. */ | 2478 { |
2411 if (cl_options[option_index].var_type == CLVC_BOOLEAN | 2479 const struct cl_option * const option = cl_options + option_index; |
2412 && cl_options[option_index].flag_var | 2480 |
2413 && kind == DK_ERROR) | 2481 /* -Werror=foo implies -Wfoo. */ |
2414 *(int *) cl_options[option_index].flag_var = 1; | 2482 if (option->var_type == CLVC_BOOLEAN) |
2483 handle_option (option_index, value, arg, lang_mask, (int)kind); | |
2484 | |
2485 if (warning_as_error_callback) | |
2486 warning_as_error_callback (option_index); | |
2487 } | |
2415 } | 2488 } |
2416 free (new_option); | 2489 free (new_option); |
2417 } | 2490 } |