From c211cd236cb0b4cda31657cd96668aace2e8e4ac Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 8 Jan 2015 01:08:19 +0000 Subject: jit: Add checking for dereference of void * gcc/jit/ChangeLog: * jit-recording.h (gcc::jit::recording::type::is_void): New virtual function. (gcc::jit::recording::memento_of_get_type::is_void): New function, overriding default implementation. * libgccjit.c (gcc_jit_rvalue_dereference): Verify that the underlying type is not "void". gcc/testsuite/ChangeLog: * jit.dg/test-error-dereferencing-void-ptr.c: New test case. From-SVN: r219333 --- gcc/jit/ChangeLog | 9 +++++++++ gcc/jit/jit-recording.h | 2 ++ gcc/jit/libgccjit.c | 7 +++++++ 3 files changed, 18 insertions(+) (limited to 'gcc/jit') diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog index b17706e..01b3882 100644 --- a/gcc/jit/ChangeLog +++ b/gcc/jit/ChangeLog @@ -1,5 +1,14 @@ 2015-01-07 David Malcolm + * jit-recording.h (gcc::jit::recording::type::is_void): New + virtual function. + (gcc::jit::recording::memento_of_get_type::is_void): New + function, overriding default implementation. + * libgccjit.c (gcc_jit_rvalue_dereference): Verify that + the underlying type is not "void". + +2015-01-07 David Malcolm + * docs/topics/expressions.rst (Unary Operations): Add GCC_JIT_UNARY_OP_ABS. * jit-playback.c (gcc::jit::playback::context::new_unary_op): diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 3734e9a..9034e11 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -443,6 +443,7 @@ public: virtual bool is_bool () const = 0; virtual type *is_pointer () = 0; virtual type *is_array () = 0; + virtual bool is_void () const { return false; } bool is_numeric () const { @@ -494,6 +495,7 @@ public: bool is_bool () const; type *is_pointer () { return dereference (); } type *is_array () { return NULL; } + bool is_void () const { return m_kind == GCC_JIT_TYPE_VOID; } public: void replay_into (replayer *r); diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index 6853bb0..99b2d56 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -1664,6 +1664,13 @@ gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue, rvalue->get_debug_string (), rvalue->get_type ()->get_debug_string ()); + RETURN_NULL_IF_FAIL_PRINTF2 ( + !underlying_type->is_void (), + rvalue->m_ctxt, loc, + "dereference of void pointer %s (type: %s)", + rvalue->get_debug_string (), + rvalue->get_type ()->get_debug_string ()); + return (gcc_jit_lvalue *)rvalue->dereference (loc); } -- cgit v1.1