comparison gcc/c-family/c-opts.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* C/ObjC/C++ command line option handling. 1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002-2017 Free Software Foundation, Inc. 2 Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 Contributed by Neil Booth. 3 Contributed by Neil Booth.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
38 #include "debug.h" /* For debug_hooks. */ 38 #include "debug.h" /* For debug_hooks. */
39 #include "opts.h" 39 #include "opts.h"
40 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */ 40 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
41 #include "mkdeps.h" 41 #include "mkdeps.h"
42 #include "dumpfile.h" 42 #include "dumpfile.h"
43 #include "file-prefix-map.h" /* add_*_prefix_map() */
43 44
44 #ifndef DOLLARS_IN_IDENTIFIERS 45 #ifndef DOLLARS_IN_IDENTIFIERS
45 # define DOLLARS_IN_IDENTIFIERS true 46 # define DOLLARS_IN_IDENTIFIERS true
46 #endif 47 #endif
47 48
113 static void set_std_cxx17 (int); 114 static void set_std_cxx17 (int);
114 static void set_std_cxx2a (int); 115 static void set_std_cxx2a (int);
115 static void set_std_c89 (int, int); 116 static void set_std_c89 (int, int);
116 static void set_std_c99 (int); 117 static void set_std_c99 (int);
117 static void set_std_c11 (int); 118 static void set_std_c11 (int);
119 static void set_std_c17 (int);
120 static void set_std_c2x (int);
118 static void check_deps_environment_vars (void); 121 static void check_deps_environment_vars (void);
119 static void handle_deferred_opts (void); 122 static void handle_deferred_opts (void);
120 static void sanitize_cpp_opts (void); 123 static void sanitize_cpp_opts (void);
121 static void add_prefixed_path (const char *, incpath_kind); 124 static void add_prefixed_path (const char *, incpath_kind);
122 static void push_command_line_include (void); 125 static void push_command_line_include (void);
220 = new (ggc_alloc <string_concat_db> ()) string_concat_db (); 223 = new (ggc_alloc <string_concat_db> ()) string_concat_db ();
221 224
222 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, 225 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
223 ident_hash, line_table); 226 ident_hash, line_table);
224 cb = cpp_get_callbacks (parse_in); 227 cb = cpp_get_callbacks (parse_in);
225 cb->error = c_cpp_error; 228 cb->diagnostic = c_cpp_diagnostic;
226 229
227 cpp_opts = cpp_get_options (parse_in); 230 cpp_opts = cpp_get_options (parse_in);
228 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; 231 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
229 cpp_opts->objc = c_dialect_objc (); 232 cpp_opts->objc = c_dialect_objc ();
230 233
234 237
235 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count); 238 deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
236 239
237 if (c_language == clk_c) 240 if (c_language == clk_c)
238 { 241 {
239 /* The default for C is gnu11. */ 242 /* The default for C is gnu17. */
240 set_std_c11 (false /* ISO */); 243 set_std_c17 (false /* ISO */);
241 244
242 /* If preprocessing assembly language, accept any of the C-family 245 /* If preprocessing assembly language, accept any of the C-family
243 front end options since the driver may pass them through. */ 246 front end options since the driver may pass them through. */
244 for (i = 1; i < decoded_options_count; i++) 247 for (i = 1; i < decoded_options_count; i++)
245 if (decoded_options[i].opt_index == OPT_lang_asm) 248 if (decoded_options[i].opt_index == OPT_lang_asm)
258 261
259 /* Handle switch SCODE with argument ARG. VALUE is true, unless no- 262 /* Handle switch SCODE with argument ARG. VALUE is true, unless no-
260 form of an -f or -W option was given. Returns false if the switch was 263 form of an -f or -W option was given. Returns false if the switch was
261 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */ 264 invalid, true if valid. Use HANDLERS in recursive handle_option calls. */
262 bool 265 bool
263 c_common_handle_option (size_t scode, const char *arg, int value, 266 c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
264 int kind, location_t loc, 267 int kind, location_t loc,
265 const struct cl_option_handlers *handlers) 268 const struct cl_option_handlers *handlers)
266 { 269 {
267 const struct cl_option *option = &cl_options[scode]; 270 const struct cl_option *option = &cl_options[scode];
268 enum opt_code code = (enum opt_code) scode; 271 enum opt_code code = (enum opt_code) scode;
377 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */ 380 /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */
378 381
379 cpp_opts->warn_num_sign_change = value; 382 cpp_opts->warn_num_sign_change = value;
380 break; 383 break;
381 384
382 case OPT_Walloca_larger_than_:
383 if (!value)
384 inform (loc, "-Walloca-larger-than=0 is meaningless");
385 break;
386
387 case OPT_Wvla_larger_than_:
388 if (!value)
389 inform (loc, "-Wvla-larger-than=0 is meaningless");
390 break;
391
392 case OPT_Wunknown_pragmas: 385 case OPT_Wunknown_pragmas:
393 /* Set to greater than 1, so that even unknown pragmas in 386 /* Set to greater than 1, so that even unknown pragmas in
394 system headers will be warned about. */ 387 system headers will be warned about. */
395 /* ??? There is no way to handle this automatically for now. */ 388 /* ??? There is no way to handle this automatically for now. */
396 warn_unknown_pragmas = value * 2; 389 warn_unknown_pragmas = value * 2;
413 { 406 {
414 warning (0, "%<-Wabi=1%> is not supported, using =2"); 407 warning (0, "%<-Wabi=1%> is not supported, using =2");
415 value = 2; 408 value = 2;
416 } 409 }
417 warn_abi_version = value; 410 warn_abi_version = value;
418 if (flag_abi_compat_version == -1)
419 flag_abi_compat_version = value;
420 break; 411 break;
421 412
422 case OPT_fcanonical_system_headers: 413 case OPT_fcanonical_system_headers:
423 cpp_opts->canonical_system_headers = value; 414 cpp_opts->canonical_system_headers = value;
424 break; 415 break;
445 436
446 case OPT_fdollars_in_identifiers: 437 case OPT_fdollars_in_identifiers:
447 cpp_opts->dollars_in_ident = value; 438 cpp_opts->dollars_in_ident = value;
448 break; 439 break;
449 440
441 case OPT_fmacro_prefix_map_:
442 add_macro_prefix_map (arg);
443 break;
444
450 case OPT_ffreestanding: 445 case OPT_ffreestanding:
451 value = !value; 446 value = !value;
452 /* Fall through. */ 447 /* Fall through. */
453 case OPT_fhosted: 448 case OPT_fhosted:
454 flag_hosted = value; 449 flag_hosted = value;
671 break; 666 break;
672 667
673 case OPT_std_gnu11: 668 case OPT_std_gnu11:
674 if (!preprocessing_asm_p) 669 if (!preprocessing_asm_p)
675 set_std_c11 (false /* ISO */); 670 set_std_c11 (false /* ISO */);
671 break;
672
673 case OPT_std_c17:
674 if (!preprocessing_asm_p)
675 set_std_c17 (true /* ISO */);
676 break;
677
678 case OPT_std_gnu17:
679 if (!preprocessing_asm_p)
680 set_std_c17 (false /* ISO */);
681 break;
682
683 case OPT_std_c2x:
684 if (!preprocessing_asm_p)
685 set_std_c2x (true /* ISO */);
686 break;
687
688 case OPT_std_gnu2x:
689 if (!preprocessing_asm_p)
690 set_std_c2x (false /* ISO */);
676 break; 691 break;
677 692
678 case OPT_trigraphs: 693 case OPT_trigraphs:
679 cpp_opts->trigraphs = 1; 694 cpp_opts->trigraphs = 1;
680 break; 695 break;
897 912
898 /* Declone C++ 'structors if -Os. */ 913 /* Declone C++ 'structors if -Os. */
899 if (flag_declone_ctor_dtor == -1) 914 if (flag_declone_ctor_dtor == -1)
900 flag_declone_ctor_dtor = optimize_size; 915 flag_declone_ctor_dtor = optimize_size;
901 916
902 if (warn_abi_version == -1)
903 {
904 if (flag_abi_compat_version != -1)
905 warn_abi_version = flag_abi_compat_version;
906 else
907 warn_abi_version = 0;
908 }
909
910 if (flag_abi_compat_version == 1) 917 if (flag_abi_compat_version == 1)
911 { 918 {
912 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2"); 919 warning (0, "%<-fabi-compat-version=1%> is not supported, using =2");
913 flag_abi_compat_version = 2; 920 flag_abi_compat_version = 2;
914 } 921 }
915 else if (flag_abi_compat_version == -1) 922
916 { 923 /* Change flag_abi_version to be the actual current ABI level, for the
917 /* Generate compatibility aliases for ABI v11 (7.1) by default. */ 924 benefit of c_cpp_builtins, and to make comparison simpler. */
918 flag_abi_compat_version 925 const int latest_abi_version = 13;
919 = (flag_abi_version == 0 ? 11 : 0); 926 /* Generate compatibility aliases for ABI v11 (7.1) by default. */
920 } 927 const int abi_compat_default = 11;
921 928
922 /* Change flag_abi_version to be the actual current ABI level for the 929 #define clamp(X) if (X == 0 || X > latest_abi_version) X = latest_abi_version
923 benefit of c_cpp_builtins. */ 930 clamp (flag_abi_version);
924 if (flag_abi_version == 0) 931 clamp (warn_abi_version);
925 flag_abi_version = 12; 932 clamp (flag_abi_compat_version);
933 #undef clamp
934
935 /* Default -Wabi= or -fabi-compat-version= from each other. */
936 if (warn_abi_version == -1 && flag_abi_compat_version != -1)
937 warn_abi_version = flag_abi_compat_version;
938 else if (flag_abi_compat_version == -1 && warn_abi_version != -1)
939 flag_abi_compat_version = warn_abi_version;
940 else if (warn_abi_version == -1 && flag_abi_compat_version == -1)
941 {
942 warn_abi_version = latest_abi_version;
943 if (flag_abi_version == latest_abi_version)
944 {
945 auto_diagnostic_group d;
946 if (warning (OPT_Wabi, "-Wabi won't warn about anything"))
947 {
948 inform (input_location, "-Wabi warns about differences "
949 "from the most up-to-date ABI, which is also used "
950 "by default");
951 inform (input_location, "use e.g. -Wabi=11 to warn about "
952 "changes from GCC 7");
953 }
954 flag_abi_compat_version = abi_compat_default;
955 }
956 else
957 flag_abi_compat_version = latest_abi_version;
958 }
926 959
927 /* By default, enable the new inheriting constructor semantics along with ABI 960 /* By default, enable the new inheriting constructor semantics along with ABI
928 11. New and old should coexist fine, but it is a change in what 961 11. New and old should coexist fine, but it is a change in what
929 artificial symbols are generated. */ 962 artificial symbols are generated. */
930 if (!global_options_set.x_flag_new_inheriting_ctors) 963 if (!global_options_set.x_flag_new_inheriting_ctors)
975 flag_extern_tls_init = 0; 1008 flag_extern_tls_init = 0;
976 } 1009 }
977 else 1010 else
978 flag_extern_tls_init = 1; 1011 flag_extern_tls_init = 1;
979 } 1012 }
1013
1014 /* Enable by default only for C++ and C++ with ObjC extensions. */
1015 if (warn_return_type == -1 && c_dialect_cxx ())
1016 warn_return_type = 1;
980 1017
981 if (num_in_fnames > 1) 1018 if (num_in_fnames > 1)
982 error ("too many filenames given. Type %s --help for usage", 1019 error ("too many filenames given. Type %s --help for usage",
983 progname); 1020 progname);
984 1021
1526 flag_no_gnu_keywords = iso; 1563 flag_no_gnu_keywords = iso;
1527 flag_no_nonansi_builtin = iso; 1564 flag_no_nonansi_builtin = iso;
1528 flag_isoc94 = c94; 1565 flag_isoc94 = c94;
1529 flag_isoc99 = 0; 1566 flag_isoc99 = 0;
1530 flag_isoc11 = 0; 1567 flag_isoc11 = 0;
1568 flag_isoc2x = 0;
1531 lang_hooks.name = "GNU C89"; 1569 lang_hooks.name = "GNU C89";
1532 } 1570 }
1533 1571
1534 /* Set the C 99 standard (without GNU extensions if ISO). */ 1572 /* Set the C 99 standard (without GNU extensions if ISO). */
1535 static void 1573 static void
1537 { 1575 {
1538 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99); 1576 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1539 flag_no_asm = iso; 1577 flag_no_asm = iso;
1540 flag_no_nonansi_builtin = iso; 1578 flag_no_nonansi_builtin = iso;
1541 flag_iso = iso; 1579 flag_iso = iso;
1580 flag_isoc2x = 0;
1542 flag_isoc11 = 0; 1581 flag_isoc11 = 0;
1543 flag_isoc99 = 1; 1582 flag_isoc99 = 1;
1544 flag_isoc94 = 1; 1583 flag_isoc94 = 1;
1545 lang_hooks.name = "GNU C99"; 1584 lang_hooks.name = "GNU C99";
1546 } 1585 }
1551 { 1590 {
1552 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11); 1591 cpp_set_lang (parse_in, iso ? CLK_STDC11: CLK_GNUC11);
1553 flag_no_asm = iso; 1592 flag_no_asm = iso;
1554 flag_no_nonansi_builtin = iso; 1593 flag_no_nonansi_builtin = iso;
1555 flag_iso = iso; 1594 flag_iso = iso;
1595 flag_isoc2x = 0;
1556 flag_isoc11 = 1; 1596 flag_isoc11 = 1;
1557 flag_isoc99 = 1; 1597 flag_isoc99 = 1;
1558 flag_isoc94 = 1; 1598 flag_isoc94 = 1;
1559 lang_hooks.name = "GNU C11"; 1599 lang_hooks.name = "GNU C11";
1560 } 1600 }
1601
1602 /* Set the C 17 standard (without GNU extensions if ISO). */
1603 static void
1604 set_std_c17 (int iso)
1605 {
1606 cpp_set_lang (parse_in, iso ? CLK_STDC17: CLK_GNUC17);
1607 flag_no_asm = iso;
1608 flag_no_nonansi_builtin = iso;
1609 flag_iso = iso;
1610 flag_isoc2x = 0;
1611 flag_isoc11 = 1;
1612 flag_isoc99 = 1;
1613 flag_isoc94 = 1;
1614 lang_hooks.name = "GNU C17";
1615 }
1616
1617 /* Set the C 2X standard (without GNU extensions if ISO). */
1618 static void
1619 set_std_c2x (int iso)
1620 {
1621 cpp_set_lang (parse_in, iso ? CLK_STDC2X: CLK_GNUC2X);
1622 flag_no_asm = iso;
1623 flag_no_nonansi_builtin = iso;
1624 flag_iso = iso;
1625 flag_isoc2x = 1;
1626 flag_isoc11 = 1;
1627 flag_isoc99 = 1;
1628 flag_isoc94 = 1;
1629 lang_hooks.name = "GNU C2X";
1630 }
1631
1561 1632
1562 /* Set the C++ 98 standard (without GNU extensions if ISO). */ 1633 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1563 static void 1634 static void
1564 set_std_cxx98 (int iso) 1635 set_std_cxx98 (int iso)
1565 { 1636 {