This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[jit] Add typechecking to binary ops and comparisons


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]