Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-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 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* C/ObjC/C++ command line option handling. | 1 /* C/ObjC/C++ 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 |
20 <http://www.gnu.org/licenses/>. */ | 20 <http://www.gnu.org/licenses/>. */ |
21 | 21 |
22 #include "config.h" | 22 #include "config.h" |
23 #include "system.h" | 23 #include "system.h" |
24 #include "coretypes.h" | 24 #include "coretypes.h" |
25 #include "tm.h" | |
26 #include "tree.h" | 25 #include "tree.h" |
27 #include "c-common.h" | 26 #include "c-common.h" |
28 #include "c-pragma.h" | 27 #include "c-pragma.h" |
29 #include "flags.h" | 28 #include "flags.h" |
30 #include "toplev.h" | 29 #include "toplev.h" |
31 #include "langhooks.h" | 30 #include "langhooks.h" |
32 #include "tree-inline.h" | |
33 #include "diagnostic.h" | 31 #include "diagnostic.h" |
34 #include "intl.h" | 32 #include "intl.h" |
35 #include "cppdefault.h" | 33 #include "cppdefault.h" |
36 #include "incpath.h" | 34 #include "incpath.h" |
37 #include "debug.h" /* For debug_hooks. */ | 35 #include "debug.h" /* For debug_hooks. */ |
38 #include "opts.h" | 36 #include "opts.h" |
39 #include "options.h" | 37 #include "options.h" |
40 #include "mkdeps.h" | 38 #include "mkdeps.h" |
41 #include "target.h" | 39 #include "target.h" /* For gcc_targetcm. */ |
42 #include "tm_p.h" | |
43 #include "c-tree.h" /* For c_cpp_error. */ | 40 #include "c-tree.h" /* For c_cpp_error. */ |
44 | 41 |
45 #ifndef DOLLARS_IN_IDENTIFIERS | 42 #ifndef DOLLARS_IN_IDENTIFIERS |
46 # define DOLLARS_IN_IDENTIFIERS true | 43 # define DOLLARS_IN_IDENTIFIERS true |
47 #endif | 44 #endif |
104 static size_t deferred_count; | 101 static size_t deferred_count; |
105 | 102 |
106 /* Number of deferred options scanned for -include. */ | 103 /* Number of deferred options scanned for -include. */ |
107 static size_t include_cursor; | 104 static size_t include_cursor; |
108 | 105 |
109 static void set_Wimplicit (int); | |
110 static void handle_OPT_d (const char *); | 106 static void handle_OPT_d (const char *); |
111 static void set_std_cxx98 (int); | 107 static void set_std_cxx98 (int); |
112 static void set_std_cxx0x (int); | 108 static void set_std_cxx0x (int); |
113 static void set_std_c89 (int, int); | 109 static void set_std_c89 (int, int); |
114 static void set_std_c99 (int); | 110 static void set_std_c99 (int); |
111 static void set_std_c1x (int); | |
115 static void check_deps_environment_vars (void); | 112 static void check_deps_environment_vars (void); |
116 static void handle_deferred_opts (void); | 113 static void handle_deferred_opts (void); |
117 static void sanitize_cpp_opts (void); | 114 static void sanitize_cpp_opts (void); |
118 static void add_prefixed_path (const char *, size_t); | 115 static void add_prefixed_path (const char *, size_t); |
119 static void push_command_line_include (void); | 116 static void push_command_line_include (void); |
132 { | 129 { |
133 enum opt_code code; | 130 enum opt_code code; |
134 const char *arg; | 131 const char *arg; |
135 } *deferred_opts; | 132 } *deferred_opts; |
136 | 133 |
134 | |
135 static const unsigned int | |
136 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX); | |
137 | |
137 /* Complain that switch CODE expects an argument but none was | 138 /* Complain that switch CODE expects an argument but none was |
138 provided. OPT was the command-line option. Return FALSE to get | 139 provided. OPT was the command-line option. Return FALSE to get |
139 the default message in opts.c, TRUE if we provide a specialized | 140 the default message in opts.c, TRUE if we provide a specialized |
140 one. */ | 141 one. */ |
141 bool | 142 bool |
194 deferred_opts[deferred_count].code = code; | 195 deferred_opts[deferred_count].code = code; |
195 deferred_opts[deferred_count].arg = arg; | 196 deferred_opts[deferred_count].arg = arg; |
196 deferred_count++; | 197 deferred_count++; |
197 } | 198 } |
198 | 199 |
200 /* -Werror= may set a warning option to enable a warning that is emitted | |
201 by the preprocessor. Set any corresponding flag in cpp_opts. */ | |
202 | |
203 static void | |
204 warning_as_error_callback (int option_index) | |
205 { | |
206 switch (option_index) | |
207 { | |
208 default: | |
209 /* Ignore options not associated with the preprocessor. */ | |
210 break; | |
211 | |
212 case OPT_Wdeprecated: | |
213 cpp_opts->warn_deprecated = 1; | |
214 break; | |
215 | |
216 case OPT_Wcomment: | |
217 case OPT_Wcomments: | |
218 cpp_opts->warn_comments = 1; | |
219 break; | |
220 | |
221 case OPT_Wtrigraphs: | |
222 cpp_opts->warn_trigraphs = 1; | |
223 break; | |
224 | |
225 case OPT_Wmultichar: | |
226 cpp_opts->warn_multichar = 1; | |
227 break; | |
228 | |
229 case OPT_Wtraditional: | |
230 cpp_opts->warn_traditional = 1; | |
231 break; | |
232 | |
233 case OPT_Wlong_long: | |
234 cpp_opts->warn_long_long = 1; | |
235 break; | |
236 | |
237 case OPT_Wendif_labels: | |
238 cpp_opts->warn_endif_labels = 1; | |
239 break; | |
240 | |
241 case OPT_Wvariadic_macros: | |
242 /* Set the local flag that is used later to update cpp_opts. */ | |
243 warn_variadic_macros = 1; | |
244 break; | |
245 | |
246 case OPT_Wbuiltin_macro_redefined: | |
247 cpp_opts->warn_builtin_macro_redefined = 1; | |
248 break; | |
249 | |
250 case OPT_Wundef: | |
251 cpp_opts->warn_undef = 1; | |
252 break; | |
253 | |
254 case OPT_Wunused_macros: | |
255 /* Set the local flag that is used later to update cpp_opts. */ | |
256 warn_unused_macros = 1; | |
257 break; | |
258 | |
259 case OPT_Wc___compat: | |
260 /* Add warnings in the same way as c_common_handle_option below. */ | |
261 if (warn_enum_compare == -1) | |
262 warn_enum_compare = 1; | |
263 if (warn_jump_misses_init == -1) | |
264 warn_jump_misses_init = 1; | |
265 cpp_opts->warn_cxx_operator_names = 1; | |
266 break; | |
267 | |
268 case OPT_Wnormalized_: | |
269 inform (input_location, "-Werror=normalized=: Set -Wnormalized=nfc"); | |
270 cpp_opts->warn_normalize = normalized_C; | |
271 break; | |
272 | |
273 case OPT_Winvalid_pch: | |
274 cpp_opts->warn_invalid_pch = 1; | |
275 break; | |
276 | |
277 case OPT_Wcpp: | |
278 /* Handled by standard diagnostics using the option's associated | |
279 boolean variable. */ | |
280 break; | |
281 } | |
282 } | |
283 | |
199 /* Common initialization before parsing options. */ | 284 /* Common initialization before parsing options. */ |
200 unsigned int | 285 unsigned int |
201 c_common_init_options (unsigned int argc, const char **argv) | 286 c_common_init_options (unsigned int argc, const char **argv) |
202 { | 287 { |
203 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; | 288 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX}; |
204 unsigned int i, result; | 289 unsigned int i, result; |
205 struct cpp_callbacks *cb; | 290 struct cpp_callbacks *cb; |
291 | |
292 /* Register callback for warnings enabled by -Werror=. */ | |
293 register_warning_as_error_callback (warning_as_error_callback); | |
206 | 294 |
207 /* This is conditionalized only because that is the way the front | 295 /* This is conditionalized only because that is the way the front |
208 ends used to do it. Maybe this should be unconditional? */ | 296 ends used to do it. Maybe this should be unconditional? */ |
209 if (c_dialect_cxx ()) | 297 if (c_dialect_cxx ()) |
210 { | 298 { |
259 /* Handle switch SCODE with argument ARG. VALUE is true, unless no- | 347 /* Handle switch SCODE with argument ARG. VALUE is true, unless no- |
260 form of an -f or -W option was given. Returns 0 if the switch was | 348 form of an -f or -W option was given. Returns 0 if the switch was |
261 invalid, a negative number to prevent language-independent | 349 invalid, a negative number to prevent language-independent |
262 processing in toplev.c (a hack necessary for the short-term). */ | 350 processing in toplev.c (a hack necessary for the short-term). */ |
263 int | 351 int |
264 c_common_handle_option (size_t scode, const char *arg, int value) | 352 c_common_handle_option (size_t scode, const char *arg, int value, |
353 int kind) | |
265 { | 354 { |
266 const struct cl_option *option = &cl_options[scode]; | 355 const struct cl_option *option = &cl_options[scode]; |
267 enum opt_code code = (enum opt_code) scode; | 356 enum opt_code code = (enum opt_code) scode; |
268 int result = 1; | 357 int result = 1; |
269 | 358 |
272 bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM); | 361 bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM); |
273 | 362 |
274 switch (code) | 363 switch (code) |
275 { | 364 { |
276 default: | 365 default: |
277 if (cl_options[code].flags & (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX)) | 366 if (cl_options[code].flags & c_family_lang_mask) |
278 { | 367 { |
279 if ((option->flags & CL_TARGET) | 368 if ((option->flags & CL_TARGET) |
280 && ! targetcm.handle_c_option (scode, arg, value)) | 369 && ! targetcm.handle_c_option (scode, arg, value)) |
281 result = 0; | 370 result = 0; |
282 break; | 371 break; |
381 break; | 470 break; |
382 | 471 |
383 case OPT_Wall: | 472 case OPT_Wall: |
384 warn_unused = value; | 473 warn_unused = value; |
385 set_Wformat (value); | 474 set_Wformat (value); |
386 set_Wimplicit (value); | 475 handle_option (OPT_Wimplicit, value, NULL, c_family_lang_mask, kind); |
387 warn_char_subscripts = value; | 476 warn_char_subscripts = value; |
388 warn_missing_braces = value; | 477 warn_missing_braces = value; |
389 warn_parentheses = value; | 478 warn_parentheses = value; |
390 warn_return_type = value; | 479 warn_return_type = value; |
391 warn_sequence_point = value; /* Was C only. */ | 480 warn_sequence_point = value; /* Was C only. */ |
479 case OPT_Wformat_: | 568 case OPT_Wformat_: |
480 set_Wformat (atoi (arg)); | 569 set_Wformat (atoi (arg)); |
481 break; | 570 break; |
482 | 571 |
483 case OPT_Wimplicit: | 572 case OPT_Wimplicit: |
484 set_Wimplicit (value); | 573 gcc_assert (value == 0 || value == 1); |
574 if (warn_implicit_int == -1) | |
575 handle_option (OPT_Wimplicit_int, value, NULL, | |
576 c_family_lang_mask, kind); | |
577 if (warn_implicit_function_declaration == -1) | |
578 handle_option (OPT_Wimplicit_function_declaration, value, NULL, | |
579 c_family_lang_mask, kind); | |
485 break; | 580 break; |
486 | 581 |
487 case OPT_Wimport: | 582 case OPT_Wimport: |
488 /* Silently ignore for now. */ | 583 /* Silently ignore for now. */ |
489 break; | 584 break; |
799 case OPT_finput_charset_: | 894 case OPT_finput_charset_: |
800 cpp_opts->input_charset = arg; | 895 cpp_opts->input_charset = arg; |
801 break; | 896 break; |
802 | 897 |
803 case OPT_ftemplate_depth_: | 898 case OPT_ftemplate_depth_: |
899 /* Kept for backwards compatibility. */ | |
900 case OPT_ftemplate_depth_eq: | |
804 max_tinst_depth = value; | 901 max_tinst_depth = value; |
805 break; | 902 break; |
806 | 903 |
807 case OPT_fuse_cxa_atexit: | 904 case OPT_fuse_cxa_atexit: |
808 flag_use_cxa_atexit = value; | 905 flag_use_cxa_atexit = value; |
948 if (!preprocessing_asm_p) | 1045 if (!preprocessing_asm_p) |
949 set_std_cxx0x (code == OPT_std_c__0x /* ISO */); | 1046 set_std_cxx0x (code == OPT_std_c__0x /* ISO */); |
950 break; | 1047 break; |
951 | 1048 |
952 case OPT_std_c89: | 1049 case OPT_std_c89: |
1050 case OPT_std_c90: | |
953 case OPT_std_iso9899_1990: | 1051 case OPT_std_iso9899_1990: |
954 case OPT_std_iso9899_199409: | 1052 case OPT_std_iso9899_199409: |
955 if (!preprocessing_asm_p) | 1053 if (!preprocessing_asm_p) |
956 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */); | 1054 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */); |
957 break; | 1055 break; |
958 | 1056 |
959 case OPT_std_gnu89: | 1057 case OPT_std_gnu89: |
1058 case OPT_std_gnu90: | |
960 if (!preprocessing_asm_p) | 1059 if (!preprocessing_asm_p) |
961 set_std_c89 (false /* c94 */, false /* ISO */); | 1060 set_std_c89 (false /* c94 */, false /* ISO */); |
962 break; | 1061 break; |
963 | 1062 |
964 case OPT_std_c99: | 1063 case OPT_std_c99: |
971 | 1070 |
972 case OPT_std_gnu99: | 1071 case OPT_std_gnu99: |
973 case OPT_std_gnu9x: | 1072 case OPT_std_gnu9x: |
974 if (!preprocessing_asm_p) | 1073 if (!preprocessing_asm_p) |
975 set_std_c99 (false /* ISO */); | 1074 set_std_c99 (false /* ISO */); |
1075 break; | |
1076 | |
1077 case OPT_std_c1x: | |
1078 if (!preprocessing_asm_p) | |
1079 set_std_c1x (true /* ISO */); | |
1080 break; | |
1081 | |
1082 case OPT_std_gnu1x: | |
1083 if (!preprocessing_asm_p) | |
1084 set_std_c1x (false /* ISO */); | |
976 break; | 1085 break; |
977 | 1086 |
978 case OPT_trigraphs: | 1087 case OPT_trigraphs: |
979 cpp_opts->trigraphs = 1; | 1088 cpp_opts->trigraphs = 1; |
980 break; | 1089 break; |
1142 "-Wformat-contains-nul ignored without -Wformat"); | 1251 "-Wformat-contains-nul ignored without -Wformat"); |
1143 warning (OPT_Wformat_security, | 1252 warning (OPT_Wformat_security, |
1144 "-Wformat-security ignored without -Wformat"); | 1253 "-Wformat-security ignored without -Wformat"); |
1145 } | 1254 } |
1146 | 1255 |
1256 if (warn_implicit == -1) | |
1257 warn_implicit = 0; | |
1258 | |
1259 if (warn_implicit_int == -1) | |
1260 warn_implicit_int = 0; | |
1261 | |
1147 /* -Wimplicit-function-declaration is enabled by default for C99. */ | 1262 /* -Wimplicit-function-declaration is enabled by default for C99. */ |
1148 if (warn_implicit_function_declaration == -1) | 1263 if (warn_implicit_function_declaration == -1) |
1149 warn_implicit_function_declaration = flag_isoc99; | 1264 warn_implicit_function_declaration = flag_isoc99; |
1150 | 1265 |
1151 /* If we're allowing C++0x constructs, don't warn about C++0x | 1266 /* If we're allowing C++0x constructs, don't warn about C++0x |
1268 } | 1383 } |
1269 | 1384 |
1270 i = 0; | 1385 i = 0; |
1271 for (;;) | 1386 for (;;) |
1272 { | 1387 { |
1273 /* Start the main input file, if the debug writer wants it. */ | |
1274 if (debug_hooks->start_end_main_source_file) | |
1275 (*debug_hooks->start_source_file) (0, this_input_filename); | |
1276 finish_options (); | 1388 finish_options (); |
1277 pch_init (); | 1389 pch_init (); |
1278 push_file_scope (); | 1390 push_file_scope (); |
1279 c_parse_file (); | 1391 c_parse_file (); |
1280 finish_file (); | 1392 finish_file (); |
1529 else | 1641 else |
1530 cpp_assert (parse_in, opt->arg); | 1642 cpp_assert (parse_in, opt->arg); |
1531 } | 1643 } |
1532 } | 1644 } |
1533 | 1645 |
1646 /* Start the main input file, if the debug writer wants it. */ | |
1647 if (debug_hooks->start_end_main_source_file | |
1648 && !flag_preprocess_only) | |
1649 (*debug_hooks->start_source_file) (0, this_input_filename); | |
1650 | |
1534 /* Handle -imacros after -D and -U. */ | 1651 /* Handle -imacros after -D and -U. */ |
1535 for (i = 0; i < deferred_count; i++) | 1652 for (i = 0; i < deferred_count; i++) |
1536 { | 1653 { |
1537 struct deferred_opt *opt = &deferred_opts[i]; | 1654 struct deferred_opt *opt = &deferred_opts[i]; |
1538 | 1655 |
1543 include_cursor = deferred_count + 1; | 1660 include_cursor = deferred_count + 1; |
1544 cpp_scan_nooutput (parse_in); | 1661 cpp_scan_nooutput (parse_in); |
1545 } | 1662 } |
1546 } | 1663 } |
1547 } | 1664 } |
1548 else if (cpp_opts->directives_only) | 1665 else |
1549 cpp_init_special_builtins (parse_in); | 1666 { |
1667 if (cpp_opts->directives_only) | |
1668 cpp_init_special_builtins (parse_in); | |
1669 | |
1670 /* Start the main input file, if the debug writer wants it. */ | |
1671 if (debug_hooks->start_end_main_source_file | |
1672 && !flag_preprocess_only) | |
1673 (*debug_hooks->start_source_file) (0, this_input_filename); | |
1674 } | |
1550 | 1675 |
1551 include_cursor = 0; | 1676 include_cursor = 0; |
1552 push_command_line_include (); | 1677 push_command_line_include (); |
1553 } | 1678 } |
1554 | 1679 |
1611 flag_no_asm = iso; | 1736 flag_no_asm = iso; |
1612 flag_no_gnu_keywords = iso; | 1737 flag_no_gnu_keywords = iso; |
1613 flag_no_nonansi_builtin = iso; | 1738 flag_no_nonansi_builtin = iso; |
1614 flag_isoc94 = c94; | 1739 flag_isoc94 = c94; |
1615 flag_isoc99 = 0; | 1740 flag_isoc99 = 0; |
1741 flag_isoc1x = 0; | |
1616 } | 1742 } |
1617 | 1743 |
1618 /* Set the C 99 standard (without GNU extensions if ISO). */ | 1744 /* Set the C 99 standard (without GNU extensions if ISO). */ |
1619 static void | 1745 static void |
1620 set_std_c99 (int iso) | 1746 set_std_c99 (int iso) |
1621 { | 1747 { |
1622 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99); | 1748 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99); |
1623 flag_no_asm = iso; | 1749 flag_no_asm = iso; |
1624 flag_no_nonansi_builtin = iso; | 1750 flag_no_nonansi_builtin = iso; |
1625 flag_iso = iso; | 1751 flag_iso = iso; |
1752 flag_isoc1x = 0; | |
1753 flag_isoc99 = 1; | |
1754 flag_isoc94 = 1; | |
1755 } | |
1756 | |
1757 /* Set the C 1X standard draft (without GNU extensions if ISO). */ | |
1758 static void | |
1759 set_std_c1x (int iso) | |
1760 { | |
1761 cpp_set_lang (parse_in, iso ? CLK_STDC1X: CLK_GNUC1X); | |
1762 flag_no_asm = iso; | |
1763 flag_no_nonansi_builtin = iso; | |
1764 flag_iso = iso; | |
1765 flag_isoc1x = 1; | |
1626 flag_isoc99 = 1; | 1766 flag_isoc99 = 1; |
1627 flag_isoc94 = 1; | 1767 flag_isoc94 = 1; |
1628 } | 1768 } |
1629 | 1769 |
1630 /* Set the C++ 98 standard (without GNU extensions if ISO). */ | 1770 /* Set the C++ 98 standard (without GNU extensions if ISO). */ |
1645 cpp_set_lang (parse_in, iso ? CLK_CXX0X: CLK_GNUCXX0X); | 1785 cpp_set_lang (parse_in, iso ? CLK_CXX0X: CLK_GNUCXX0X); |
1646 flag_no_gnu_keywords = iso; | 1786 flag_no_gnu_keywords = iso; |
1647 flag_no_nonansi_builtin = iso; | 1787 flag_no_nonansi_builtin = iso; |
1648 flag_iso = iso; | 1788 flag_iso = iso; |
1649 cxx_dialect = cxx0x; | 1789 cxx_dialect = cxx0x; |
1650 } | |
1651 | |
1652 /* Handle setting implicit to ON. */ | |
1653 static void | |
1654 set_Wimplicit (int on) | |
1655 { | |
1656 warn_implicit = on; | |
1657 warn_implicit_int = on; | |
1658 warn_implicit_function_declaration = on; | |
1659 } | 1790 } |
1660 | 1791 |
1661 /* Args to -d specify what to dump. Silently ignore | 1792 /* Args to -d specify what to dump. Silently ignore |
1662 unrecognized options; they may be aimed at toplev.c. */ | 1793 unrecognized options; they may be aimed at toplev.c. */ |
1663 static void | 1794 static void |