aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog12
-rw-r--r--gcc/c/c-decl.c14
-rw-r--r--gcc/c/c-errors.c43
-rw-r--r--gcc/c/c-parser.c16
4 files changed, 56 insertions, 29 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 1d55309..4f67dec 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,15 @@
+2014-08-19 Marek Polacek <polacek@redhat.com>
+
+ * c-decl.c (warn_variable_length_array): Pass OPT_Wvla unconditionally
+ to pedwarn_c90.
+ * c-errors.c: Include "opts.h".
+ (pedwarn_c90): Rewrite to handle -Wno-c90-c99-compat better.
+ * c-parser.c (disable_extension_diagnostics): Handle negative value
+ of warn_c90_c99_compat, too.
+ (restore_extension_diagnostics): Likewise.
+ (c_parser_compound_statement_nostart): Pass
+ OPT_Wdeclaration_after_statement unconditionally to pedwarn_c90.
+
2014-08-12 Marek Polacek <polacek@redhat.com>
* c-parser.c (c_parser_postfix_expression) <case RID_FUNCTION_NAME>:
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 7ba35bf..138b014 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4920,27 +4920,23 @@ check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
static void
warn_variable_length_array (tree name, tree size)
{
- int const_size = TREE_CONSTANT (size);
- enum opt_code opt = (warn_vla == -1 && !warn_c90_c99_compat)
- ? OPT_Wpedantic : OPT_Wvla;
-
- if (const_size)
+ if (TREE_CONSTANT (size))
{
if (name)
- pedwarn_c90 (input_location, opt,
+ pedwarn_c90 (input_location, OPT_Wvla,
"ISO C90 forbids array %qE whose size "
"can%'t be evaluated", name);
else
- pedwarn_c90 (input_location, opt, "ISO C90 forbids array "
+ pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids array "
"whose size can%'t be evaluated");
}
else
{
if (name)
- pedwarn_c90 (input_location, opt,
+ pedwarn_c90 (input_location, OPT_Wvla,
"ISO C90 forbids variable length array %qE", name);
else
- pedwarn_c90 (input_location, opt, "ISO C90 forbids variable "
+ pedwarn_c90 (input_location, OPT_Wvla, "ISO C90 forbids variable "
"length array");
}
}
diff --git a/gcc/c/c-errors.c b/gcc/c/c-errors.c
index 5a95b88..89393b9 100644
--- a/gcc/c/c-errors.c
+++ b/gcc/c/c-errors.c
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm_p.h"
#include "flags.h"
#include "diagnostic.h"
+#include "opts.h"
/* Issue an ISO C99 pedantic warning MSGID. */
@@ -56,26 +57,44 @@ pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
{
diagnostic_info diagnostic;
va_list ap;
- bool warned = false;
va_start (ap, gmsgid);
- if (pedantic && !flag_isoc99)
+ /* Warnings such as -Wvla are the most specific ones. */
+ if (opt != OPT_Wpedantic)
{
- diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
- diagnostic.option_index = opt;
- warned = report_diagnostic (&diagnostic);
+ int opt_var = *(int *) option_flag_var (opt, &global_options);
+ if (opt_var == 0)
+ goto out;
+ else if (opt_var > 0)
+ {
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
+ (pedantic && !flag_isoc99)
+ ? DK_PEDWARN : DK_WARNING);
+ diagnostic.option_index = opt;
+ report_diagnostic (&diagnostic);
+ goto out;
+ }
}
- else if (opt != OPT_Wpedantic)
+ /* Maybe we want to issue the C90/C99 compat warning, which is more
+ specific than -pedantic. */
+ if (warn_c90_c99_compat > 0)
{
- diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
- diagnostic.option_index = opt;
- warned = report_diagnostic (&diagnostic);
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
+ (pedantic && !flag_isoc99)
+ ? DK_PEDWARN : DK_WARNING);
+ diagnostic.option_index = OPT_Wc90_c99_compat;
+ report_diagnostic (&diagnostic);
}
- if (warn_c90_c99_compat && !warned)
+ /* -Wno-c90-c99-compat suppresses the pedwarns. */
+ else if (warn_c90_c99_compat == 0)
+ ;
+ /* For -pedantic outside C99, issue a pedwarn. */
+ else if (pedantic && !flag_isoc99)
{
- diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
- diagnostic.option_index = OPT_Wc90_c99_compat;
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
+ diagnostic.option_index = opt;
report_diagnostic (&diagnostic);
}
+out:
va_end (ap);
}
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 5f23379..6afe3eb 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1073,7 +1073,10 @@ disable_extension_diagnostics (void)
| (warn_long_long << 4)
| (warn_cxx_compat << 5)
| (warn_overlength_strings << 6)
- | (warn_c90_c99_compat << 7));
+ /* warn_c90_c99_compat has three states: -1/0/1, so we must
+ play tricks to properly restore it. */
+ | ((warn_c90_c99_compat == 1) << 7)
+ | ((warn_c90_c99_compat == -1) << 8));
cpp_opts->cpp_pedantic = pedantic = 0;
warn_pointer_arith = 0;
cpp_opts->cpp_warn_traditional = warn_traditional = 0;
@@ -1098,7 +1101,8 @@ restore_extension_diagnostics (int flags)
cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1;
warn_cxx_compat = (flags >> 5) & 1;
warn_overlength_strings = (flags >> 6) & 1;
- warn_c90_c99_compat = (flags >> 7) & 1;
+ /* See above for why is this needed. */
+ warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0);
}
/* Possibly kinds of declarator to parse. */
@@ -4570,9 +4574,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
c_parser_declaration_or_fndef (parser, true, true, true, true,
true, NULL, vNULL);
if (last_stmt)
- pedwarn_c90 (loc, (pedantic && !flag_isoc99)
- ? OPT_Wpedantic
- : OPT_Wdeclaration_after_statement,
+ pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
"ISO C90 forbids mixed declarations and code");
last_stmt = false;
}
@@ -4600,9 +4602,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
disable this diagnostic. */
restore_extension_diagnostics (ext);
if (last_stmt)
- pedwarn_c90 (loc, (pedantic && !flag_isoc99)
- ? OPT_Wpedantic
- : OPT_Wdeclaration_after_statement,
+ pedwarn_c90 (loc, OPT_Wdeclaration_after_statement,
"ISO C90 forbids mixed declarations and code");
last_stmt = false;
}