aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts-common.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2015-12-08 14:26:35 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2015-12-08 14:26:35 +0100
commit63bbf46d5f44f34a54f4e9cff62377516633fb7f (patch)
tree0e888f7e79d4144fe4ea4fc640d979765f209cc9 /gcc/opts-common.c
parent091db7b0af49a12ecb6fea88c0e4443444ee82bd (diff)
downloadgcc-63bbf46d5f44f34a54f4e9cff62377516633fb7f.zip
gcc-63bbf46d5f44f34a54f4e9cff62377516633fb7f.tar.gz
gcc-63bbf46d5f44f34a54f4e9cff62377516633fb7f.tar.bz2
re PR c/48088 (-Werror=frame-larger-than=100 does not work as expected)
PR c/48088 PR c/68657 * common.opt (Wframe-larger-than=): Add Warning. * opts.h (control_warning_option): Add ARG argument. * opts-common.c (cmdline_handle_error): New function. (read_cmdline_option): Use it. (control_warning_option): Likewise. Add ARG argument. If non-NULL, decode it if needed and pass through to handle_generated_option. Handle CLVC_ENUM like CLVC_BOOLEAN. * opts.c (common_handle_option): Adjust control_warning_option caller. (enable_warning_as_error): Likewise. c-family/ * c.opt (Wfloat-conversion, Wsign-conversion): Add Warning. * c-pragma.c (handle_pragma_diagnostic): Adjust control_warning_option caller. ada/ * gcc-interface/trans.c (Pragma_to_gnu): Adjust control_warning_option caller. testsuite/ * c-c++-common/pr68657-1.c: New test. * c-c++-common/pr68657-2.c: New test. * c-c++-common/pr68657-3.c: New test. * gcc.dg/cpp/warn-normalized-3.c: Use -Werror=normalized=nfc instead of -Werror=normalized= in dg-options. From-SVN: r231406
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r--gcc/opts-common.c162
1 files changed, 116 insertions, 46 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 24967cc..507358a 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -1021,62 +1021,42 @@ generate_option_input_file (const char *file,
decoded->errors = 0;
}
-/* Handle the switch DECODED (location LOC) for the language indicated
- by LANG_MASK, using the handlers in *HANDLERS and setting fields in
- OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
- diagnostic options. */
+/* Perform diagnostics for read_cmdline_option and control_warning_option
+ functions. Returns true if an error has been diagnosed.
+ LOC and LANG_MASK arguments like in read_cmdline_option.
+ OPTION is the option to report diagnostics for, OPT the name
+ of the option as text, ARG the argument of the option (for joined
+ options), ERRORS is bitmask of CL_ERR_* values. */
-void
-read_cmdline_option (struct gcc_options *opts,
- struct gcc_options *opts_set,
- struct cl_decoded_option *decoded,
- location_t loc,
- unsigned int lang_mask,
- const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
+static bool
+cmdline_handle_error (location_t loc, const struct cl_option *option,
+ const char *opt, const char *arg, int errors,
+ unsigned int lang_mask)
{
- const struct cl_option *option;
- const char *opt = decoded->orig_option_with_args_text;
-
- if (decoded->warn_message)
- warning_at (loc, 0, decoded->warn_message, opt);
-
- if (decoded->opt_index == OPT_SPECIAL_unknown)
- {
- if (handlers->unknown_option_callback (decoded))
- error_at (loc, "unrecognized command line option %qs", decoded->arg);
- return;
- }
-
- if (decoded->opt_index == OPT_SPECIAL_ignore)
- return;
-
- option = &cl_options[decoded->opt_index];
-
- if (decoded->errors & CL_ERR_DISABLED)
+ if (errors & CL_ERR_DISABLED)
{
error_at (loc, "command line option %qs"
- " is not supported by this configuration", opt);
- return;
+ " is not supported by this configuration", opt);
+ return true;
}
- if (decoded->errors & CL_ERR_MISSING_ARG)
+ if (errors & CL_ERR_MISSING_ARG)
{
if (option->missing_argument_error)
error_at (loc, option->missing_argument_error, opt);
else
error_at (loc, "missing argument to %qs", opt);
- return;
+ return true;
}
- if (decoded->errors & CL_ERR_UINT_ARG)
+ if (errors & CL_ERR_UINT_ARG)
{
error_at (loc, "argument to %qs should be a non-negative integer",
option->opt_text);
- return;
+ return true;
}
- if (decoded->errors & CL_ERR_ENUM_ARG)
+ if (errors & CL_ERR_ENUM_ARG)
{
const struct cl_enum *e = &cl_enums[option->var_enum];
unsigned int i;
@@ -1084,7 +1064,7 @@ read_cmdline_option (struct gcc_options *opts,
char *s, *p;
if (e->unknown_error)
- error_at (loc, e->unknown_error, decoded->arg);
+ error_at (loc, e->unknown_error, arg);
else
error_at (loc, "unrecognized argument in option %qs", opt);
@@ -1105,9 +1085,49 @@ read_cmdline_option (struct gcc_options *opts,
}
p[-1] = 0;
inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+ return true;
+ }
+
+ return false;
+}
+
+/* Handle the switch DECODED (location LOC) for the language indicated
+ by LANG_MASK, using the handlers in *HANDLERS and setting fields in
+ OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
+ diagnostic options. */
+
+void
+read_cmdline_option (struct gcc_options *opts,
+ struct gcc_options *opts_set,
+ struct cl_decoded_option *decoded,
+ location_t loc,
+ unsigned int lang_mask,
+ const struct cl_option_handlers *handlers,
+ diagnostic_context *dc)
+{
+ const struct cl_option *option;
+ const char *opt = decoded->orig_option_with_args_text;
+
+ if (decoded->warn_message)
+ warning_at (loc, 0, decoded->warn_message, opt);
+
+ if (decoded->opt_index == OPT_SPECIAL_unknown)
+ {
+ if (handlers->unknown_option_callback (decoded))
+ error_at (loc, "unrecognized command line option %qs", decoded->arg);
return;
}
+ if (decoded->opt_index == OPT_SPECIAL_ignore)
+ return;
+
+ option = &cl_options[decoded->opt_index];
+
+ if (decoded->errors
+ && cmdline_handle_error (loc, option, opt, decoded->arg,
+ decoded->errors, lang_mask))
+ return;
+
if (decoded->errors & CL_ERR_WRONG_LANG)
{
handlers->wrong_lang_callback (decoded, lang_mask);
@@ -1327,13 +1347,14 @@ get_option_state (struct gcc_options *opts, int option,
/* Set a warning option OPT_INDEX (language mask LANG_MASK, option
handlers HANDLERS) to have diagnostic kind KIND for option
structures OPTS and OPTS_SET and diagnostic context DC (possibly
- NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). If IMPLY,
+ NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). ARG is the
+ argument of the option for joined options, or NULL otherwise. If IMPLY,
the warning option in question is implied at this point. This is
used by -Werror= and #pragma GCC diagnostic. */
void
-control_warning_option (unsigned int opt_index, int kind, bool imply,
- location_t loc, unsigned int lang_mask,
+control_warning_option (unsigned int opt_index, int kind, const char *arg,
+ bool imply, location_t loc, unsigned int lang_mask,
const struct cl_option_handlers *handlers,
struct gcc_options *opts,
struct gcc_options *opts_set,
@@ -1347,10 +1368,59 @@ control_warning_option (unsigned int opt_index, int kind, bool imply,
diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
if (imply)
{
+ const struct cl_option *option = &cl_options[opt_index];
+
/* -Werror=foo implies -Wfoo. */
- if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
- handle_generated_option (opts, opts_set,
- opt_index, NULL, 1, lang_mask,
- kind, loc, handlers, dc);
+ if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
+ {
+ int value = 1;
+
+ if (arg && *arg == '\0' && !option->cl_missing_ok)
+ arg = NULL;
+
+ if ((option->flags & CL_JOINED) && arg == NULL)
+ {
+ cmdline_handle_error (loc, option, option->opt_text, arg,
+ CL_ERR_MISSING_ARG, lang_mask);
+ return;
+ }
+
+ /* If the switch takes an integer, convert it. */
+ if (arg && option->cl_uinteger)
+ {
+ value = integral_argument (arg);
+ if (value == -1)
+ {
+ cmdline_handle_error (loc, option, option->opt_text, arg,
+ CL_ERR_UINT_ARG, lang_mask);
+ return;
+ }
+ }
+
+ /* If the switch takes an enumerated argument, convert it. */
+ if (arg && option->var_type == CLVC_ENUM)
+ {
+ const struct cl_enum *e = &cl_enums[option->var_enum];
+
+ if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+ {
+ const char *carg = NULL;
+
+ if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+ arg = carg;
+ gcc_assert (carg != NULL);
+ }
+ else
+ {
+ cmdline_handle_error (loc, option, option->opt_text, arg,
+ CL_ERR_ENUM_ARG, lang_mask);
+ return;
+ }
+ }
+
+ handle_generated_option (opts, opts_set,
+ opt_index, arg, value, lang_mask,
+ kind, loc, handlers, dc);
+ }
}
}