aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/libgccjit.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/jit/libgccjit.c')
-rw-r--r--gcc/jit/libgccjit.c83
1 files changed, 73 insertions, 10 deletions
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index d596d08..ad8ee75 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -172,6 +172,16 @@ struct gcc_jit_param : public gcc::jit::recording::param
} \
JIT_END_STMT
+#define RETURN_VAL_IF_FAIL_PRINTF5(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
+ JIT_BEGIN_STMT \
+ if (!(TEST_EXPR)) \
+ { \
+ jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
+ __func__, (A0), (A1), (A2), (A3), (A4)); \
+ return (RETURN_EXPR); \
+ } \
+ JIT_END_STMT
+
#define RETURN_VAL_IF_FAIL_PRINTF6(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
JIT_BEGIN_STMT \
if (!(TEST_EXPR)) \
@@ -197,6 +207,9 @@ struct gcc_jit_param : public gcc::jit::recording::param
#define RETURN_NULL_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
RETURN_VAL_IF_FAIL_PRINTF4 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3)
+#define RETURN_NULL_IF_FAIL_PRINTF5(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
+ RETURN_VAL_IF_FAIL_PRINTF5 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4)
+
#define RETURN_NULL_IF_FAIL_PRINTF6(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
RETURN_VAL_IF_FAIL_PRINTF6 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5)
@@ -844,10 +857,23 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt,
ctxt, loc,
"NULL params creating function %s", name);
for (int i = 0; i < num_params; i++)
- RETURN_NULL_IF_FAIL_PRINTF2 (
- params[i],
- ctxt, loc,
- "NULL parameter %i creating function %s", i, name);
+ {
+ RETURN_NULL_IF_FAIL_PRINTF2 (
+ params[i],
+ ctxt, loc,
+ "NULL parameter %i creating function %s", i, name);
+ RETURN_NULL_IF_FAIL_PRINTF5 (
+ (NULL == params[i]->get_scope ()),
+ ctxt, loc,
+ "parameter %i \"%s\""
+ " (type: %s)"
+ " for function %s"
+ " was already used for function %s",
+ i, params[i]->get_debug_string (),
+ params[i]->get_type ()->get_debug_string (),
+ name,
+ params[i]->get_scope ()->get_debug_string ());
+ }
return (gcc_jit_function*)
ctxt->new_function (loc, kind, return_type, name,
@@ -1800,7 +1826,14 @@ gcc_jit_block_add_eval (gcc_jit_block *block,
/* LOC can be NULL. */
RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
- return block->add_eval (loc, rvalue);
+ gcc::jit::recording::statement *stmt = block->add_eval (loc, rvalue);
+
+ /* "stmt" should be good enough to be usable in error-messages,
+ but might still not be compilable; perform some more
+ error-checking here. We do this here so that the error messages
+ can contain a stringified version of "stmt", whilst appearing
+ as close as possible to the point of failure. */
+ rvalue->verify_valid_within_stmt (__func__, stmt);
}
/* Public entrypoint. See description in libgccjit.h.
@@ -1832,7 +1865,15 @@ gcc_jit_block_add_assignment (gcc_jit_block *block,
rvalue->get_debug_string (),
rvalue->get_type ()->get_debug_string ());
- return block->add_assignment (loc, lvalue, rvalue);
+ gcc::jit::recording::statement *stmt = block->add_assignment (loc, lvalue, rvalue);
+
+ /* "stmt" should be good enough to be usable in error-messages,
+ but might still not be compilable; perform some more
+ error-checking here. We do this here so that the error messages
+ can contain a stringified version of "stmt", whilst appearing
+ as close as possible to the point of failure. */
+ lvalue->verify_valid_within_stmt (__func__, stmt);
+ rvalue->verify_valid_within_stmt (__func__, stmt);
}
/* Public entrypoint. See description in libgccjit.h.
@@ -1860,7 +1901,15 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block,
op);
RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
- return block->add_assignment_op (loc, lvalue, op, rvalue);
+ gcc::jit::recording::statement *stmt = block->add_assignment_op (loc, lvalue, op, rvalue);
+
+ /* "stmt" should be good enough to be usable in error-messages,
+ but might still not be compilable; perform some more
+ error-checking here. We do this here so that the error messages
+ can contain a stringified version of "stmt", whilst appearing
+ as close as possible to the point of failure. */
+ lvalue->verify_valid_within_stmt (__func__, stmt);
+ rvalue->verify_valid_within_stmt (__func__, stmt);
}
/* Internal helper function for determining if rvalue BOOLVAL is of
@@ -1921,7 +1970,14 @@ gcc_jit_block_end_with_conditional (gcc_jit_block *block,
on_false->get_debug_string (),
on_false->get_function ()->get_debug_string ());
- return block->end_with_conditional (loc, boolval, on_true, on_false);
+ gcc::jit::recording::statement *stmt = block->end_with_conditional (loc, boolval, on_true, on_false);
+
+ /* "stmt" should be good enough to be usable in error-messages,
+ but might still not be compilable; perform some more
+ error-checking here. We do this here so that the error messages
+ can contain a stringified version of "stmt", whilst appearing
+ as close as possible to the point of failure. */
+ boolval->verify_valid_within_stmt (__func__, stmt);
}
/* Public entrypoint. See description in libgccjit.h.
@@ -2003,7 +2059,14 @@ gcc_jit_block_end_with_return (gcc_jit_block *block,
func->get_debug_string (),
func->get_return_type ()->get_debug_string ());
- return block->end_with_return (loc, rvalue);
+ gcc::jit::recording::statement *stmt = block->end_with_return (loc, rvalue);
+
+ /* "stmt" should be good enough to be usable in error-messages,
+ but might still not be compilable; perform some more
+ error-checking here. We do this here so that the error messages
+ can contain a stringified version of "stmt", whilst appearing
+ as close as possible to the point of failure. */
+ rvalue->verify_valid_within_stmt (__func__, stmt);
}
/* Public entrypoint. See description in libgccjit.h.
@@ -2029,7 +2092,7 @@ gcc_jit_block_end_with_void_return (gcc_jit_block *block,
func->get_debug_string (),
func->get_return_type ()->get_debug_string ());
- return block->end_with_return (loc, NULL);
+ block->end_with_return (loc, NULL);
}
/**********************************************************************