@@ -1,3 +1,14 @@
+2014-07-14 David Malcolm <dmalcolm@redhat.com>
+
+ * internal-api.c (gcc::jit::recording::context::new_array_type):
+ Reject attempts to create an array of a struct if the fields of
+ the struct haven't yet been set.
+ * internal-api.h (gcc::jit::recording::type::dyn_cast_struct): New
+ virtual function.
+ (gcc::jit::recording::struct_::dyn_cast_struct): New, overriding
+ for this subclass.
+ (gcc::jit::recording::struct_::get_name): New.
+
2014-05-07 David Malcolm <dmalcolm@redhat.com>
* Make-lang.in (LIBGCCJIT_LINKER_NAME): New.
@@ -345,6 +345,15 @@ recording::context::new_array_type (recording::location *loc,
recording::type *element_type,
int num_elements)
{
+ if (struct_ *s = element_type->dyn_cast_struct ())
+ if (!s->get_fields ())
+ {
+ add_error (NULL,
+ "cannot create an array of type %s"
+ " until the fields have been set",
+ s->get_name ()->c_str ());
+ return NULL;
+ }
recording::type *result =
new recording::array_type (this, loc, element_type, num_elements);
record (result);
@@ -477,8 +477,9 @@ public:
The caller is responsible for setting an error. */
virtual type *dereference () = 0;
- /* Dynamic cast. */
+ /* Dynamic casts. */
virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
+ virtual struct_ *dyn_cast_struct () { return NULL; }
/* Is it typesafe to copy to this type from rtype? */
virtual bool accepts_writes_from (type *rtype)
@@ -755,9 +756,12 @@ public:
location *loc,
string *name);
+ struct_ *dyn_cast_struct () { return this; }
+
type *
as_type () { return this; }
+ string *get_name () const { return m_name; }
fields * get_fields () { return m_fields; }
void