From 6b5423a512421989934071586c9ddb6ee42ac417 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 17 May 2016 19:28:47 +0000 Subject: jit: gcc diagnostics are jit errors libgccjit performs numerous checks at the API boundary, but if these succeed, it ignores errors and other diagnostics emitted within the core of gcc, and treats the compile of a gcc_jit_context as having succeeded. This patch ensures that if any diagnostics are emitted, they are visible from the libgccjit API, and that the the context is flagged as having failed. For now any kind of diagnostic is treated as a jit error, so warnings and notes also count as errors. gcc/jit/ChangeLog: * dummy-frontend.c: Include diagnostic.h. (jit_begin_diagnostic): New function. (jit_end_diagnostic): New function. (jit_langhook_init): Register jit_begin_diagnostic and jit_end_diagnostic with the global_dc. * jit-playback.c: Include diagnostic.h. (gcc::jit::playback::context::add_diagnostic): New method. * jit-playback.h (struct diagnostic_context): Add forward declaration. (gcc::jit::playback::context::add_diagnostic): New method. gcc/testsuite/ChangeLog: * jit.dg/test-error-array-bounds.c: New test case. From-SVN: r236342 --- gcc/jit/dummy-frontend.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'gcc/jit/dummy-frontend.c') diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c index 7194ba6..2631153 100644 --- a/gcc/jit/dummy-frontend.c +++ b/gcc/jit/dummy-frontend.c @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "debug.h" #include "langhooks.h" #include "langhooks-def.h" +#include "diagnostic.h" #include @@ -90,6 +91,35 @@ struct ggc_root_tab jit_root_tab[] = LAST_GGC_ROOT_TAB }; +/* JIT-specific implementation of diagnostic callbacks. */ + +/* Implementation of "begin_diagnostic". */ + +static void +jit_begin_diagnostic (diagnostic_context */*context*/, + diagnostic_info */*diagnostic*/) +{ + gcc_assert (gcc::jit::active_playback_ctxt); + JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); + + /* No-op (apart from logging); the real error-handling is done in the + "end_diagnostic" hook. */ +} + +/* Implementation of "end_diagnostic". */ + +static void +jit_end_diagnostic (diagnostic_context *context, + diagnostic_info *diagnostic) +{ + gcc_assert (gcc::jit::active_playback_ctxt); + JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); + + /* Delegate to the playback context (and thence to the + recording context). */ + gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic); +} + /* Language hooks. */ static bool @@ -105,6 +135,10 @@ jit_langhook_init (void) registered_root_tab = true; } + gcc_assert (global_dc); + global_dc->begin_diagnostic = jit_begin_diagnostic; + global_dc->end_diagnostic = jit_end_diagnostic; + build_common_tree_nodes (false); /* I don't know why this has to be done explicitly. */ -- cgit v1.1