aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/jit-playback.c
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/jit-playback.c
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/jit-playback.c')
-rw-r--r--gcc/jit/jit-playback.c38
1 files changed, 38 insertions, 0 deletions
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