aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2009-03-29 23:56:07 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2009-03-29 23:56:07 +0100
commit148e4216a47b822512444dbd3ca5e2670aef431c (patch)
treee75993fadfb11c86fc56a516f41f7aafb3fee001 /gcc/c-common.c
parentba20e30910df3945603374d426730d6da5350572 (diff)
downloadgcc-148e4216a47b822512444dbd3ca5e2670aef431c.zip
gcc-148e4216a47b822512444dbd3ca5e2670aef431c.tar.gz
gcc-148e4216a47b822512444dbd3ca5e2670aef431c.tar.bz2
re PR preprocessor/34695 (Preprocessor warning->error conversion from -Werror is silent)
PR preprocessor/34695 gcc: * Makefile.in (c-opts.o): Depend on c-tree.h. * c-common.c: Move down include of diagnostic.h. (done_lexing, c_cpp_error): New. * c-common.h (done_lexing): Declare. * c-decl.c (c_write_global_declarations): Don't check cpp_errors (parse_in). * c-opts.c: Include c-tree.h. (c_common_init_options): Set preprocessor error callback. (c_common_handle_option): Do not set preprocessor inhibit_warnings, warnings_are_errors, warn_system_headers, pedantic_errors or inhibit_warnings flags. (c_common_post_options): Do not check cpp_errors (parse_in). (c_common_finish): Do not output dependencies if there were errors. Do not check return value of cpp_finish. * c-ppoutput.c (pp_file_change): Set input_location. * c-tree.h (c_cpp_error): Declare. * diagnostic.c (diagnostic_set_info_translated): Also initialize override_column. (diagnostic_build_prefix): Check override_column. * diagnostic.h (diagnostic_info): Add override_column field. (diagnostic_override_column): Define. gcc/cp: * cp-tree.h (cp_cpp_error): Remove. * error.c (cp_cpp_error): Remove. * parser.c (cp_lexer_new_main): Set done_lexing instead of client_diagnostic and error callback. gcc/fortran: * cpp.c (cb_cpp_error): New. (gfc_cpp_post_options): Don't set cpp_option->inhibit_warnings. Don't check cpp_errors (cpp_in). (gfc_cpp_init_0): Set cb->error. gcc/testsuite: * gcc.dg/builtin-redefine.c, gcc.dg/cpp/redef2.c, gcc.dg/cpp/redef3.c, gcc.dg/cpp/trad/redef2.c: Use dg-message instead of dg-warning for "previous definition" messages. * gcc.dg/cpp/Wvariadic-1.c, gcc.dg/cpp/Wvariadic-3.c: Expect "warnings being treated as errors" message. * gcc.dg/fltconst-1.c: Use -fshow-column. libcpp: * makedepend.c: Remove. * Makefile.in (makedepend_OBJS, makedepend$(EXEEXT)): Remove. (all, clean, TAGS_SOURCES, include): Remove makedepend handling. * directives.c (cpp_errors): Remove. * errors.c (print_location, _cpp_begin_message, v_message): Remove. (cpp_error, cpp_error_with_line): Always use error callback. (cpp_error, cpp_error_with_line, cpp_errno): Return bool. * include/cpplib.h (cpp_options): Remove pedantic_errors, inhibit_warnings, warn_system_headers, inhibit_errors, warnings_are_errors, client_diagnostic. (cpp_callbacks): Add extra arguments to error callback; make it return bool. (cpp_finish): Return void. (cpp_destroy): Remove inaccurate comment about return value. (cpp_errors, CPP_DL_EXTRACT, CPP_DL_WARNING_P): Remove. (CPP_DL_NOTE): Define. * include/line-map.h (linemap_print_containing_files): Remove. * init.c (cpp_finish): Do not check for or return number of errors. * internal.h (cpp_reader): Remove errors field. * line-map.c (linemap_print_containing_files): Remove. * macro.c (_cpp_create_definition): Use CPP_DL_NOTE for message about previous definition. Only emit it if previous diagnostic was emitted. From-SVN: r145263
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 8450cc9..9abd006 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3. If not see
#include "varray.h"
#include "expr.h"
#include "c-common.h"
-#include "diagnostic.h"
#include "tm_p.h"
#include "obstack.h"
#include "cpplib.h"
@@ -42,6 +41,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-inline.h"
#include "c-tree.h"
#include "toplev.h"
+#include "diagnostic.h"
#include "tree-iterator.h"
#include "hashtab.h"
#include "tree-mudflap.h"
@@ -497,6 +497,10 @@ tree (*make_fname_decl) (tree, int);
This is a count, since unevaluated expressions can nest. */
int skip_evaluation;
+/* Whether lexing has been completed, so subsequent preprocessor
+ errors should use the compiler's input_location. */
+bool done_lexing = false;
+
/* Information about how a function name is generated. */
struct fname_var_t
{
@@ -7928,6 +7932,65 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token, tree value)
#undef catenate_messages
}
+/* Callback from cpp_error for PFILE to print diagnostics from the
+ preprocessor. The diagnostic is of type LEVEL, at location
+ LOCATION unless this is after lexing and the compiler's location
+ should be used instead, with column number possibly overridden by
+ COLUMN_OVERRIDE if not zero; MSG is the translated message and AP
+ the arguments. Returns true if a diagnostic was emitted, false
+ otherwise. */
+
+bool
+c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level,
+ location_t location, unsigned int column_override,
+ const char *msg, va_list *ap)
+{
+ diagnostic_info diagnostic;
+ diagnostic_t dlevel;
+ int save_warn_system_headers = warn_system_headers;
+ bool ret;
+
+ switch (level)
+ {
+ case CPP_DL_WARNING_SYSHDR:
+ if (flag_no_output)
+ return false;
+ warn_system_headers = 1;
+ /* Fall through. */
+ case CPP_DL_WARNING:
+ if (flag_no_output)
+ return false;
+ dlevel = DK_WARNING;
+ break;
+ case CPP_DL_PEDWARN:
+ if (flag_no_output && !flag_pedantic_errors)
+ return false;
+ dlevel = DK_PEDWARN;
+ break;
+ case CPP_DL_ERROR:
+ dlevel = DK_ERROR;
+ break;
+ case CPP_DL_ICE:
+ dlevel = DK_ICE;
+ break;
+ case CPP_DL_NOTE:
+ dlevel = DK_NOTE;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ if (done_lexing)
+ location = input_location;
+ diagnostic_set_info_translated (&diagnostic, msg, ap,
+ location, dlevel);
+ if (column_override)
+ diagnostic_override_column (&diagnostic, column_override);
+ ret = report_diagnostic (&diagnostic);
+ if (level == CPP_DL_WARNING_SYSHDR)
+ warn_system_headers = save_warn_system_headers;
+ return ret;
+}
+
/* Walk a gimplified function and warn for functions whose return value is
ignored and attribute((warn_unused_result)) is set. This is done before
inlining, so we don't have to worry about that. */