This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[jit] Add typechecking to binary ops and comparisons
- 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: Fri, 28 Feb 2014 18:38:13 -0500
- Subject: [jit] Add typechecking to binary ops and comparisons
- Authentication-results: sourceware.org; auth=none
Committed to branch dmalcolm/jit:
gcc/jit/
* libgccjit.c (gcc_jit_context_new_binary_op): Check that the
operands have the same type.
(gcc_jit_context_new_comparison): Likewise.
---
gcc/jit/ChangeLog.jit | 6 ++++++
gcc/jit/libgccjit.c | 18 ++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 625e01a..f2fea8c 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,5 +1,11 @@
2014-02-28 David Malcolm <dmalcolm@redhat.com>
+ * libgccjit.c (gcc_jit_context_new_binary_op): Check that the
+ operands have the same type.
+ (gcc_jit_context_new_comparison): Likewise.
+
+2014-02-28 David Malcolm <dmalcolm@redhat.com>
+
* libgccjit.h (gcc_jit_context_new_cast): New.
* libgccjit.map (gcc_jit_context_new_cast): New.
* libgccjit++.h (gccjit::context::new_cast): New method.
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 6c078ce..d9f63cf 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -752,6 +752,15 @@ gcc_jit_context_new_binary_op (gcc_jit_context *ctxt,
RETURN_NULL_IF_FAIL (result_type, ctxt, "NULL result_type");
RETURN_NULL_IF_FAIL (a, ctxt, "NULL a");
RETURN_NULL_IF_FAIL (b, ctxt, "NULL b");
+ RETURN_NULL_IF_FAIL_PRINTF4 (
+ a->get_type () == b->get_type (),
+ ctxt,
+ "mismatching types for binary op:"
+ " a: %s (type: %s) b: %s (type: %s)",
+ a->get_debug_string (),
+ a->get_type ()->get_debug_string (),
+ b->get_debug_string (),
+ b->get_type ()->get_debug_string ());
return (gcc_jit_rvalue *)ctxt->new_binary_op (loc, op, result_type, a, b);
}
@@ -766,6 +775,15 @@ gcc_jit_context_new_comparison (gcc_jit_context *ctxt,
/* op is checked by the inner function. */
RETURN_NULL_IF_FAIL (a, ctxt, "NULL a");
RETURN_NULL_IF_FAIL (b, ctxt, "NULL b");
+ RETURN_NULL_IF_FAIL_PRINTF4 (
+ a->get_type () == b->get_type (),
+ ctxt,
+ "mismatching types for comparison:"
+ " a: %s (type: %s) b: %s (type: %s)",
+ a->get_debug_string (),
+ a->get_type ()->get_debug_string (),
+ b->get_debug_string (),
+ b->get_type ()->get_debug_string ());
return (gcc_jit_rvalue *)ctxt->new_comparison (loc, op, a, b);
}
--
1.7.11.7