This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[jit] Improvements to error-handling
- From: David Malcolm <dmalcolm at redhat dot com>
- To: jit at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Tue, 11 Feb 2014 13:18:08 -0500
- Subject: [jit] Improvements to error-handling
- Authentication-results: sourceware.org; auth=none
Committed to branch dmalcolm/jit:
gcc/jit/
* internal-api.c (gcc::jit::recording::context::add_error_va): If
GCC_JIT_STR_OPTION_PROGNAME is NULL, use "libgccjit.so", as per
the comment in libgccjit.h
(gcc::jit::recording::label::replay_into): When reporting on an
unplaced label, include the name of the containing function in
the error message.
* libgccjit.c: Remove comment about "Functions for use within the
code factory", as this distinction went away in commit
96b218c9a1d5f39fb649e02c0e77586b180e8516.
(RETURN_VAL_IF_FAIL_PRINTF4): New.
(RETURN_NULL_IF_FAIL_PRINTF4): New.
(jit_error): Invoke vfprintf with the correct format string in
the NULL context case.
(gcc_jit_context_new_call): Check for NULL entries within the
array of arguments.
---
gcc/jit/ChangeLog.jit | 18 ++++++++++++++++++
gcc/jit/internal-api.c | 10 ++++++++--
gcc/jit/libgccjit.c | 29 +++++++++++++++++++++++++----
3 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 68c38db..d331082 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,21 @@
+2014-02-11 David Malcolm <dmalcolm@redhat.com>
+
+ * internal-api.c (gcc::jit::recording::context::add_error_va): If
+ GCC_JIT_STR_OPTION_PROGNAME is NULL, use "libgccjit.so", as per
+ the comment in libgccjit.h
+ (gcc::jit::recording::label::replay_into): When reporting on an
+ unplaced label, include the name of the containing function in
+ the error message.
+ * libgccjit.c: Remove comment about "Functions for use within the
+ code factory", as this distinction went away in commit
+ 96b218c9a1d5f39fb649e02c0e77586b180e8516.
+ (RETURN_VAL_IF_FAIL_PRINTF4): New.
+ (RETURN_NULL_IF_FAIL_PRINTF4): New.
+ (jit_error): Invoke vfprintf with the correct format string in
+ the NULL context case.
+ (gcc_jit_context_new_call): Check for NULL entries within the
+ array of arguments.
+
2014-02-10 David Malcolm <dmalcolm@redhat.com>
* libgccjit.h (gcc_jit_context_get_int_type): New.
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index 9ff0eb8..6c66d3d 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -500,8 +500,12 @@ recording::context::add_error_va (const char *fmt, va_list ap)
char buf[1024];
vsnprintf (buf, sizeof (buf) - 1, fmt, ap);
+ const char *progname = get_str_option (GCC_JIT_STR_OPTION_PROGNAME);
+ if (!progname)
+ progname = "libgccjit.so";
+
fprintf (stderr, "%s: %s\n",
- get_str_option (GCC_JIT_STR_OPTION_PROGNAME),
+ progname,
buf);
if (!m_error_count)
@@ -1075,7 +1079,9 @@ recording::label::replay_into (replayer *r)
{
if (!m_has_been_placed)
{
- r->add_error ("unplaced label: %s", get_debug_string ());
+ r->add_error ("unplaced label within %s: %s",
+ m_func->get_debug_string (),
+ get_debug_string ());
return;
}
set_playback_obj (m_func->playback_function ()
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 94b3271..3c2d962 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -100,6 +100,16 @@ struct gcc_jit_loop : public gcc::jit::recording::loop
} \
JIT_END_STMT
+#define RETURN_VAL_IF_FAIL_PRINTF4(TEST_EXPR, RETURN_EXPR, CTXT, ERR_FMT, A0, A1, A2, A3) \
+ JIT_BEGIN_STMT \
+ if (!(TEST_EXPR)) \
+ { \
+ jit_error ((CTXT), "%s: " ERR_FMT, \
+ __func__, (A0), (A1), (A2), (A3)); \
+ return (RETURN_EXPR); \
+ } \
+ JIT_END_STMT
+
#define RETURN_VAL_IF_FAIL_PRINTF6(TEST_EXPR, RETURN_EXPR, CTXT, ERR_FMT, A0, A1, A2, A3, A4, A5) \
JIT_BEGIN_STMT \
if (!(TEST_EXPR)) \
@@ -119,6 +129,9 @@ struct gcc_jit_loop : public gcc::jit::recording::loop
#define RETURN_NULL_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, ERR_FMT, A0, A1, A2) \
RETURN_VAL_IF_FAIL_PRINTF3 (TEST_EXPR, NULL, CTXT, ERR_FMT, A0, A1, A2)
+#define RETURN_NULL_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, ERR_FMT, A0, A1, A2, A3) \
+ RETURN_VAL_IF_FAIL_PRINTF4 (TEST_EXPR, NULL, CTXT, ERR_FMT, A0, A1, A2, A3)
+
#define RETURN_NULL_IF_FAIL_PRINTF6(TEST_EXPR, CTXT, ERR_FMT, A0, A1, A2, A3, A4, A5) \
RETURN_VAL_IF_FAIL_PRINTF6 (TEST_EXPR, NULL, CTXT, ERR_FMT, A0, A1, A2, A3, A4, A5)
@@ -174,7 +187,8 @@ jit_error (gcc::jit::recording::context *ctxt, const char *fmt, ...)
else
{
/* No context? Send to stderr. */
- vfprintf (stderr, "%s\n", ap);
+ vfprintf (stderr, fmt, ap);
+ fprintf (stderr, "\n");
}
va_end (ap);
@@ -205,9 +219,6 @@ gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt)
return new gcc_jit_context (parent_ctxt);
}
-/**********************************************************************
- Functions for use within the code factory.
- **********************************************************************/
gcc_jit_location *
gcc_jit_context_new_location (gcc_jit_context *ctxt,
const char *filename,
@@ -630,6 +641,16 @@ gcc_jit_context_new_call (gcc_jit_context *ctxt,
gcc::jit::recording::param *param = func->get_param (i);
gcc_jit_rvalue *arg = args[i];
+ RETURN_NULL_IF_FAIL_PRINTF4 (
+ arg,
+ ctxt,
+ "NULL argument %i to function \"%s\":"
+ " param %s (type: %s)",
+ i + 1,
+ func->get_name ()->c_str (),
+ param->get_debug_string (),
+ param->get_type ()->get_debug_string ());
+
RETURN_NULL_IF_FAIL_PRINTF6 (
compatible_types (param->get_type (),
arg->get_type ()),
--
1.7.11.7