aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-05-17 19:28:47 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-05-17 19:28:47 +0000
commit6b5423a512421989934071586c9ddb6ee42ac417 (patch)
treeff6f37c704f22faac7eab9e79f10232646b62933 /gcc/jit
parentf51703a8f80c9935f27148bb53ec7591716fd519 (diff)
downloadgcc-6b5423a512421989934071586c9ddb6ee42ac417.zip
gcc-6b5423a512421989934071586c9ddb6ee42ac417.tar.gz
gcc-6b5423a512421989934071586c9ddb6ee42ac417.tar.bz2
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
Diffstat (limited to 'gcc/jit')
-rw-r--r--gcc/jit/ChangeLog13
-rw-r--r--gcc/jit/dummy-frontend.c34
-rw-r--r--gcc/jit/jit-playback.c38
-rw-r--r--gcc/jit/jit-playback.h7
4 files changed, 92 insertions, 0 deletions
diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog
index ae0a553..f9320ec 100644
--- a/gcc/jit/ChangeLog
+++ b/gcc/jit/ChangeLog
@@ -1,5 +1,18 @@
2016-05-17 David Malcolm <dmalcolm@redhat.com>
+ * 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.
+
+2016-05-17 David Malcolm <dmalcolm@redhat.com>
+
* docs/topics/expressions.rst (Function calls): Document
gcc_jit_context_new_call_through_ptr.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
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 <mpfr.h>
@@ -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. */
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 579230d..156448d 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see
#include "context.h"
#include "fold-const.h"
#include "gcc.h"
+#include "diagnostic.h"
#include <pthread.h>
@@ -2833,6 +2834,43 @@ add_error_va (location *loc, const char *fmt, va_list ap)
fmt, ap);
}
+/* Report a diagnostic up to the jit context as an error,
+ so that the compilation is treated as a failure.
+ For now, any kind of diagnostic is treated as an error by the jit
+ API. */
+
+void
+playback::context::
+add_diagnostic (struct diagnostic_context *diag_context,
+ struct diagnostic_info *diagnostic)
+{
+ /* At this point the text has been formatted into the pretty-printer's
+ output buffer. */
+ pretty_printer *pp = diag_context->printer;
+ const char *text = pp_formatted_text (pp);
+
+ /* Get location information (if any) from the diagnostic.
+ The recording::context::add_error[_va] methods require a
+ recording::location. We can't lookup the playback::location
+ from the file/line/column since any playback location instances
+ may have been garbage-collected away by now, so instead we create
+ another recording::location directly. */
+ location_t gcc_loc = diagnostic_location (diagnostic);
+ recording::location *rec_loc = NULL;
+ if (gcc_loc)
+ {
+ expanded_location exploc = expand_location (gcc_loc);
+ if (exploc.file)
+ rec_loc = m_recording_ctxt->new_location (exploc.file,
+ exploc.line,
+ exploc.column,
+ false);
+ }
+
+ m_recording_ctxt->add_error (rec_loc, "%s", text);
+ pp_clear_output_area (pp);
+}
+
/* Dealing with the linemap API. */
/* Construct a playback::location for a recording::location, if it
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 905747c..8f7a43d 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -27,6 +27,9 @@ along with GCC; see the file COPYING3. If not see
#include "jit-recording.h"
+struct diagnostic_context;
+struct diagnostic_info;
+
namespace gcc {
namespace jit {
@@ -203,6 +206,10 @@ public:
get_first_error () const;
void
+ add_diagnostic (struct diagnostic_context *context,
+ struct diagnostic_info *diagnostic);
+
+ void
set_tree_location (tree t, location *loc);
tree