[jit] Add some type-checking to parameters requiring pointers
David Malcolm
dmalcolm@redhat.com
Wed Feb 19 15:48:00 GMT 2014
Committed to branch dmalcolm/jit:
gcc/jit/
* libgccjit.c (gcc_jit_context_new_rvalue_from_ptr): Verify that
pointer_type is indeed a pointer type.
(gcc_jit_context_null): Likewise.
(gcc_jit_context_new_array_access): Verify that ptr is indeed a
pointer.
* TODO.rst: Update
---
gcc/jit/ChangeLog.jit | 10 ++++++++++
gcc/jit/TODO.rst | 9 +--------
gcc/jit/libgccjit.c | 13 +++++++++++++
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 860bee6..0978a9c 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,13 @@
+2014-02-19 David Malcolm <dmalcolm@redhat.com>
+
+ * libgccjit.c (gcc_jit_context_new_rvalue_from_ptr): Verify that
+ pointer_type is indeed a pointer type.
+ (gcc_jit_context_null): Likewise.
+ (gcc_jit_context_new_array_access): Verify that ptr is indeed a
+ pointer.
+
+ * TODO.rst: Update
+
2014-02-18 David Malcolm <dmalcolm@redhat.com>
* libgccjit.h (gcc_jit_struct): New.
diff --git a/gcc/jit/TODO.rst b/gcc/jit/TODO.rst
index 7288aef..51a3cc9 100644
--- a/gcc/jit/TODO.rst
+++ b/gcc/jit/TODO.rst
@@ -96,20 +96,15 @@ Initial Release
* gcc_jit_context_one: must be a numeric type
- * gcc_jit_context_null: must be a pointer type
-
* gcc_jit_context_new_rvalue_from_double: must be a numeric type
- * gcc_jit_context_new_rvalue_from_ptr: must be a pointer type
-
* gcc_jit_context_new_unary_op: various checks needed
* gcc_jit_context_new_binary_op: various checks needed
* gcc_jit_context_new_comparison: must be numeric or pointer types
- * gcc_jit_context_new_array_lookup: "ptr" must be of pointer type;
- "index" must be of numeric type.
+ * gcc_jit_context_new_array_access: "index" must be of numeric type.
* gcc_jit_lvalue_access_field: must be field of correct struct
@@ -119,8 +114,6 @@ Initial Release
* gcc_jit_function_add_assignment_op: check the types
- * gcc_jit_function_add_conditional: boolval must be of numeric type
-
* gcc_jit_loop_end: verify that loops are validly nested?
Bugs
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index d089ad5..797785b 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -680,6 +680,10 @@ gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt,
{
RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context");
RETURN_NULL_IF_FAIL (pointer_type, ctxt, "NULL type");
+ RETURN_NULL_IF_FAIL_PRINTF1 (
+ pointer_type->dereference (), ctxt,
+ "not a pointer type (type: %s)",
+ pointer_type->get_debug_string ());
return (gcc_jit_rvalue *)ctxt->new_rvalue_from_ptr (pointer_type, value);
}
@@ -690,6 +694,10 @@ gcc_jit_context_null (gcc_jit_context *ctxt,
{
RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context");
RETURN_NULL_IF_FAIL (pointer_type, ctxt, "NULL type");
+ RETURN_NULL_IF_FAIL_PRINTF1 (
+ pointer_type->dereference (), ctxt,
+ "not a pointer type (type: %s)",
+ pointer_type->get_debug_string ());
return gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL);
}
@@ -823,6 +831,11 @@ gcc_jit_context_new_array_access (gcc_jit_context *ctxt,
RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context");
RETURN_NULL_IF_FAIL (ptr, ctxt, "NULL ptr");
RETURN_NULL_IF_FAIL (index, ctxt, "NULL index");
+ RETURN_NULL_IF_FAIL_PRINTF2 (
+ ptr->get_type ()->dereference (), ctxt,
+ "%s (type: %s) is not a pointer",
+ ptr->get_debug_string (),
+ ptr->get_type ()->get_debug_string ());
return (gcc_jit_lvalue *)ctxt->new_array_access (loc, ptr, index);
}
--
1.7.11.7
More information about the Gcc-patches
mailing list