diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd8f7759033..9933288018f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2012-05-14 Manuel López-Ibáñez + + PR 53063 + * doc/options.texi: (LangEnabledBy): Document it. + * optc-gen.awk: Handle LangEnabledBy. + * opth-gen.awk: Generate declaration for lang-specific functions. + * opt-read.awk: Record lang numbers. + * opt-functions.awk (flag_set_p): Ignore the arguments of flags. + (lang_sanitized_name): New. + 2012-05-14 Bernd Schmidt * attribs.c (decl_attributes): Avoid emitting a warning if diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 2f623f9030e..63039c9ac09 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2012-05-14 Manuel López-Ibáñez + + PR 53063 + * gcc-interface/misc.c: Include opts.h and options.h before tm.h. + (gnat_handle_option): Call lang-specific generated function. + 2012-05-13 Manuel López-Ibáñez * gcc-interface/lang.opt (I): Comment out help text with no effect. diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index ad15f672423..f2002f577ee 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -26,6 +26,8 @@ #include "config.h" #include "system.h" #include "coretypes.h" +#include "opts.h" +#include "options.h" #include "tm.h" #include "tree.h" #include "diagnostic.h" @@ -36,8 +38,6 @@ #include "toplev.h" #include "langhooks.h" #include "langhooks-def.h" -#include "opts.h" -#include "options.h" #include "plugin.h" #include "real.h" #include "function.h" /* For pass_by_reference. */ @@ -153,6 +153,10 @@ gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value, gcc_unreachable (); } + Ada_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + gnat_option_lang_mask (), kind, + loc, handlers, global_dc); return true; } diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 226568593d8..de50b215961 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2012-05-14 Manuel López-Ibáñez + + PR 53063 + * c.opt (Wc++0X-compat,Wdelete-non-virtual-dtor,Wjump-misses-init, + Wreorder): Use LangEnabledBy. + * c-opts.c (c_common_handle_option): Do not enable them + explicitly. Call lang-specific generated functions. + (c_common_post_options): Do not set them here. + 2012-05-13 Manuel López-Ibáñez * c.opt (Wclobbered,Wempty-body,Wignored-qualifiers, diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 8470de15ce0..a7fadc817aa 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -397,9 +397,9 @@ c_common_handle_option (size_t scode, const char *arg, int value, if (warn_main == -1) warn_main = (value ? 2 : 0); - /* In C, -Wall turns on -Wenum-compare, which we do here. - In C++ it is on by default, which is done in - c_common_post_options. */ + /* In C, -Wall and -Wc++-compat turns on -Wenum-compare, + which we do here. In C++ it is on by default, which is + done in c_common_post_options. */ if (warn_enum_compare == -1) warn_enum_compare = value; } @@ -407,9 +407,6 @@ c_common_handle_option (size_t scode, const char *arg, int value, { /* C++-specific warnings. */ warn_sign_compare = value; - warn_reorder = value; - warn_cxx0x_compat = value; - warn_delnonvdtor = value; warn_narrowing = value; } @@ -434,10 +431,6 @@ c_common_handle_option (size_t scode, const char *arg, int value, implies -Wenum-compare. */ if (warn_enum_compare == -1 && value) warn_enum_compare = value; - /* Because C++ always warns about a goto which misses an - initialization, -Wc++-compat turns on -Wjump-misses-init. */ - if (warn_jump_misses_init == -1 && value) - warn_jump_misses_init = value; cpp_opts->warn_cxx_operator_names = value; break; @@ -836,6 +829,40 @@ c_common_handle_option (size_t scode, const char *arg, int value, break; } + switch (c_language) + { + case clk_c: + C_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + c_family_lang_mask, kind, + loc, handlers, global_dc); + break; + + case clk_objc: + ObjC_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + c_family_lang_mask, kind, + loc, handlers, global_dc); + break; + + case clk_cxx: + CXX_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + c_family_lang_mask, kind, + loc, handlers, global_dc); + break; + + case clk_objcxx: + ObjCXX_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + c_family_lang_mask, kind, + loc, handlers, global_dc); + break; + + default: + gcc_unreachable (); + } + return result; } @@ -926,8 +953,6 @@ c_common_post_options (const char **pfilename) warn_strict_aliasing = 0; if (warn_strict_overflow == -1) warn_strict_overflow = 0; - if (warn_jump_misses_init == -1) - warn_jump_misses_init = 0; /* -Woverlength-strings is off by default, but is enabled by -Wpedantic. It is never enabled in C++, as the minimum limit is not normative diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 8afde8a25e2..0f13dc34eef 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -288,7 +288,7 @@ C ObjC Var(warn_cxx_compat) Warning Warn about C constructs that are not in the common subset of C and C++ Wc++0x-compat -C++ ObjC++ Var(warn_cxx0x_compat) Warning +C++ ObjC++ Var(warn_cxx0x_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Deprecated in favor of -Wc++11-compat Wc++11-compat @@ -336,7 +336,7 @@ C ObjC Var(warn_declaration_after_statement) Warning Warn when a declaration is found after a statement Wdelete-non-virtual-dtor -C++ ObjC++ Var(warn_delnonvdtor) Warning +C++ ObjC++ Var(warn_delnonvdtor) Warning LangEnabledBy(C++ ObjC++,Wall) Warn about deleting polymorphic objects with non-virtual destructors Wdeprecated @@ -446,7 +446,7 @@ C ObjC C++ ObjC++ Warning Warn about PCH files that are found but not used Wjump-misses-init -C ObjC Var(warn_jump_misses_init) Init(-1) Warning +C ObjC Var(warn_jump_misses_init) Warning LangEnabledby(C ObjC,Wc++-compat) Warn when a jump misses a variable initialization Wliteral-suffix @@ -598,7 +598,7 @@ C ObjC C++ ObjC++ Var(warn_redundant_decls) Warning Warn about multiple declarations of the same object Wreorder -C++ ObjC++ Var(warn_reorder) Warning +C++ ObjC++ Var(warn_reorder) Warning LangEnabledBy(C++ ObjC++,Wall) Warn when the compiler reorders code Wreturn-type diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi index 360cbdfb662..ef720307eee 100644 --- a/gcc/doc/options.texi +++ b/gcc/doc/options.texi @@ -461,4 +461,11 @@ value of @option{-fmath-errno} for languages that do not use @item EnabledBy(@var{opt}) If not explicitly set, the option is set to the value of @option{-@var{opt}}. + +@item LangEnabledBy(@var{language}, @var{opt}) +When compiling for the given language, the option is set to the value +of @option{-@var{opt}}, if not explicitly set. It is possible to +specify several different languages. Each @var{language} must have +been declared by an earlier @code{Language} record. @xref{Option file +format}. @end table diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 251194b46af..bfafc1b100c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2012-05-14 Manuel López-Ibáñez + + PR 53063 + * options.c (gfc_handle_option): Call lang-specific generated function. + 2012-05-13 Alessandro Fanfarillo Tobias Burnus diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 32a8a4cb464..f1721ce0a9b 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -1090,6 +1090,10 @@ gfc_handle_option (size_t scode, const char *arg, int value, break; } + Fortran_handle_option_auto (&global_options, &global_options_set, + scode, arg, value, + gfc_option_lang_mask (), kind, + loc, handlers, global_dc); return result; } diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk index 1f582fb4a16..8e098c28c2c 100644 --- a/gcc/opt-functions.awk +++ b/gcc/opt-functions.awk @@ -30,7 +30,9 @@ BEGIN { # Return nonzero if FLAGS contains a flag matching REGEX. function flag_set_p(regex, flags) { - return (" " flags " ") ~ (" " regex " ") + # Ignore the arguments of flags with arguments. + gsub ("\\([^)]+\\)", "", flags); + return (" " flags " ") ~ (" " regex " ") } # Return STRING if FLAGS contains a flag matching regexp REGEX, @@ -287,3 +289,10 @@ function opt_enum(name) { return "OPT_" opt_sanitized_name(name) } + +# Given the language called NAME return a sanitized version of its name. +function lang_sanitized_name(name) +{ + gsub( "[^" alnum "_]", "X", name ) + return name +} diff --git a/gcc/opt-read.awk b/gcc/opt-read.awk index 81c3ea894d9..2ca71eebf98 100644 --- a/gcc/opt-read.awk +++ b/gcc/opt-read.awk @@ -41,6 +41,7 @@ BEGIN { { if ($1 == "Language") { langs[n_langs] = $2 + lang_numbers[$2] = n_langs n_langs++; } else if ($1 == "TargetSave") { diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk index 61dbe8ce2ac..1d46a5dc3c9 100644 --- a/gcc/optc-gen.awk +++ b/gcc/optc-gen.awk @@ -30,6 +30,50 @@ # Dump that array of options into a C file. END { + +# Record first EnabledBy and LangEnabledBy uses. +n_enabledby = 0; +for (i = 0; i < n_langs; i++) { + n_enabledby_lang[i] = 0; +} +for (i = 0; i < n_opts; i++) { + enabledby_arg = opt_args("EnabledBy", flags[i]); + if (enabledby_arg != "") { + enabledby_name = enabledby_arg; + enabledby_index = opt_numbers[enabledby_name]; + if (enabledby_index == "") { + print "#error Enabledby: " enabledby_name + } else { + if (enables[enabledby_name] == "") { + enabledby[n_enabledby] = enabledby_name; + n_enabledby++; + } + enables[enabledby_name] = enables[enabledby_name] opts[i] ","; + } + } + + enabledby_arg = opt_args("LangEnabledBy", flags[i]); + if (enabledby_arg != "") { + n_enabledby_arg_langs = split(nth_arg(0, enabledby_arg), enabledby_arg_langs, " "); + enabledby_name = nth_arg(1, enabledby_arg); + enabledby_index = opt_numbers[enabledby_name]; + if (enabledby_index == "") { + print "#error Enabledby: " enabledby_name + } else { + for (j = 1; j <= n_enabledby_arg_langs; j++) { + lang_name = lang_sanitized_name(enabledby_arg_langs[j]); + lang_index = lang_numbers[enabledby_arg_langs[j]]; + if (enables[lang_name,enabledby_name] == "") { + enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_name; + n_enabledby_lang[lang_index]++; + } + enables[lang_name,enabledby_name] = enables[lang_name,enabledby_name] opts[i] ","; + } + } + } +} + + print "/* This file is auto-generated by optc-gen.awk. */" print "" n_headers = split(header_name, headers, " ") @@ -161,8 +205,7 @@ print "" print "const char * const lang_names[] =\n{" for (i = 0; i < n_langs; i++) { - macros[i] = "CL_" langs[i] - gsub( "[^" alnum "_]", "X", macros[i] ) + macros[i] = "CL_" lang_sanitized_name(langs[i]) s = substr(" ", length (macros[i])) print " " quote langs[i] quote "," } @@ -342,30 +385,6 @@ print " gcc_assert (decoded->canonical_option_num_elements <= 2); " print " " print " switch (code) " print " { " -n_enabledby = 0; -for (i = 0; i < n_opts; i++) { - # With identical flags, pick only the last one. The - # earlier loop ensured that it has all flags merged, - # and a nonempty help text if one of the texts was nonempty. - while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { - i++; - } - enabledby_arg = opt_args("EnabledBy", flags[i]); - if (enabledby_arg != "") { - enabledby_name = enabledby_arg; - enabledby_index = opt_numbers[enabledby_name]; - if (enabledby_index == "") { - print "#error Enabledby: " enabledby_name - } else { - enabledby_var_name = var_name(flags[enabledby_index]); - if (enables[enabledby_name] == "") { - enabledby[n_enabledby] = enabledby_name; - n_enabledby++; - } - enables[enabledby_name] = enables[enabledby_name] opts[i] ","; - } - } -} for (i = 0; i < n_enabledby; i++) { enabledby_name = enabledby[i]; print " case " opt_enum(enabledby_name) ":" @@ -378,7 +397,6 @@ for (i = 0; i < n_enabledby; i++) { print " lang_mask, kind, loc, handlers, dc);" } print " break;\n" - } print " default: " print " break; " @@ -386,4 +404,44 @@ print " } " print " return true; " print "} " +# Handle LangEnabledBy +for (i = 0; i < n_langs; i++) { + lang_name = lang_sanitized_name(langs[i]); + mark_unused = " ATTRIBUTE_UNUSED"; + + print "\n\n" + print "bool " + print lang_name "_handle_option_auto (struct gcc_options *opts" mark_unused ", " + print " struct gcc_options *opts_set" mark_unused ", " + print " size_t scode" mark_unused ", const char *arg" mark_unused ", int value" mark_unused ", " + print " unsigned int lang_mask" mark_unused ", int kind" mark_unused ", " + print " location_t loc" mark_unused ", " + print " const struct cl_option_handlers *handlers" mark_unused ", " + print " diagnostic_context *dc" mark_unused ") " + print "{ " + print " enum opt_code code = (enum opt_code) scode; " + print " " + print " switch (code) " + print " { " + + for (k = 0; k < n_enabledby_lang[i]; k++) { + enabledby_name = enabledby[lang_name,k]; + print " case " opt_enum(enabledby_name) ":" + n_enables = split(enables[lang_name,enabledby_name], thisenable, ","); + for (j = 1; j < n_enables; j++) { + opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]); + print " if (!opts_set->x_" opt_var_name ")" + print " handle_generated_option (opts, opts_set," + print " " opt_enum(thisenable[j]) ", arg, value," + print " lang_mask, kind, loc, handlers, dc);" + } + print " break;\n" + } + print " default: " + print " break; " + print " } " + print " return true; " + print "} " +} + } diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk index 8257587e1b3..8e583f03064 100644 --- a/gcc/opth-gen.awk +++ b/gcc/opth-gen.awk @@ -305,6 +305,17 @@ print " unsigned int lang_mask, int kind, " print " location_t loc, " print " const struct cl_option_handlers *handlers, " print " diagnostic_context *dc); " +for (i = 0; i < n_langs; i++) { + lang_name = lang_sanitized_name(langs[i]); + print "bool " + print lang_name "_handle_option_auto (struct gcc_options *opts, " + print " struct gcc_options *opts_set, " + print " size_t scode, const char *arg, int value, " + print " unsigned int lang_mask, int kind, " + print " location_t loc, " + print " const struct cl_option_handlers *handlers, " + print " diagnostic_context *dc); " +} print "#endif"; print "#endif"; print ""; @@ -401,8 +412,7 @@ for (i = 0; i < n_opts; i++) { print "" for (i = 0; i < n_langs; i++) { - macros[i] = "CL_" langs[i] - gsub( "[^" alnum "_]", "X", macros[i] ) + macros[i] = "CL_" lang_sanitized_name(langs[i]) s = substr(" ", length (macros[i])) print "#define " macros[i] s " (1U << " i ")" }