diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-05-17 19:28:47 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-05-17 19:28:47 +0000 |
commit | 6b5423a512421989934071586c9ddb6ee42ac417 (patch) | |
tree | ff6f37c704f22faac7eab9e79f10232646b62933 /gcc/testsuite/jit.dg | |
parent | f51703a8f80c9935f27148bb53ec7591716fd519 (diff) | |
download | gcc-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/testsuite/jit.dg')
-rw-r--r-- | gcc/testsuite/jit.dg/test-error-array-bounds.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/gcc/testsuite/jit.dg/test-error-array-bounds.c b/gcc/testsuite/jit.dg/test-error-array-bounds.c new file mode 100644 index 0000000..732ec87 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-error-array-bounds.c @@ -0,0 +1,72 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "libgccjit.h" + +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + /* Let's try to inject the equivalent of: + char + test_array_bounds (void) + { + char buffer[10]; + return buffer[10]; + } + with -Warray-bounds and -ftree-vrp and verify that the + out-of-bounds access is detected and reported as a jit error. */ + gcc_jit_context_add_command_line_option (ctxt, "-Warray-bounds"); + gcc_jit_context_add_command_line_option (ctxt, "-ftree-vrp"); + + /* Ensure that the error message doesn't contain colorization codes, + even if run at a TTY. */ + gcc_jit_context_add_command_line_option (ctxt, "-fdiagnostics-color=never"); + + gcc_jit_type *char_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR); + gcc_jit_type *array_type = + gcc_jit_context_new_array_type (ctxt, NULL, + char_type, 10); + gcc_jit_type *int_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + + /* Build the test_fn. */ + gcc_jit_function *test_fn = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + char_type, + "test_array_bounds", + 0, NULL, + 0); + gcc_jit_lvalue *buffer = + gcc_jit_function_new_local (test_fn, NULL, array_type, "buffer"); + + /* tree-vrp.c:check_all_array_refs only checks array lookups that + have source locations. */ + gcc_jit_location *dummy_loc = + gcc_jit_context_new_location (ctxt, "dummy.c", 10, 4); + + gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL); + gcc_jit_rvalue *index = + gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 10); + gcc_jit_lvalue *read_of_the_buffer = + gcc_jit_context_new_array_access (ctxt, dummy_loc, + gcc_jit_lvalue_as_rvalue (buffer), + index); + gcc_jit_block_end_with_return ( + block, dummy_loc, + gcc_jit_lvalue_as_rvalue (read_of_the_buffer)); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + /* Verify that the diagnostic led to the context failing... */ + CHECK_VALUE (result, NULL); + + /* ...and that the message was captured by the API. */ + CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), + "array subscript is above array bounds [-Warray-bounds]"); +} |