Skip to content

Commit a2d83f6

Browse files
committed
libgccjit: Allow comparing array types
gcc/jit/ChangeLog: * jit-common.h: Add array_type class. * jit-recording.h (type::dyn_cast_array_type, memento_of_get_aligned::dyn_cast_array_type, array_type::dyn_cast_array_type, array_type::is_same_type_as): New methods. gcc/testsuite/ChangeLog: * jit.dg/test-types.c: Add array type comparison to the test.
1 parent 4630f61 commit a2d83f6

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

gcc/jit/jit-common.h

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace recording {
132132
class struct_;
133133
class union_;
134134
class vector_type;
135+
class array_type;
135136
class field;
136137
class bitfield;
137138
class fields;

gcc/jit/jit-recording.h

+17
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ class type : public memento
605605
virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
606606
virtual struct_ *dyn_cast_struct () { return NULL; }
607607
virtual vector_type *dyn_cast_vector_type () { return NULL; }
608+
virtual array_type *dyn_cast_array_type () { return NULL; }
608609

609610
/* Is it typesafe to copy to this type from rtype? */
610611
virtual bool accepts_writes_from (type *rtype)
@@ -823,6 +824,11 @@ class memento_of_get_const : public decorated_type
823824

824825
void replay_into (replayer *) final override;
825826

827+
array_type *dyn_cast_array_type () final override
828+
{
829+
return m_other_type->dyn_cast_array_type ();
830+
}
831+
826832
private:
827833
string * make_debug_string () final override;
828834
void write_reproducer (reproducer &r) final override;
@@ -1001,6 +1007,17 @@ class array_type : public type
10011007

10021008
type *dereference () final override;
10031009

1010+
bool is_same_type_as (type *other) final override
1011+
{
1012+
array_type *other_array_type = other->dyn_cast_array_type ();
1013+
if (!other_array_type)
1014+
return false;
1015+
return m_num_elements == other_array_type->m_num_elements
1016+
&& m_element_type->is_same_type_as (other_array_type->m_element_type);
1017+
}
1018+
1019+
array_type *dyn_cast_array_type () final override { return this; }
1020+
10041021
type* copy(context* ctxt) final override
10051022
{
10061023
type* result = new array_type (ctxt, m_loc, m_element_type->copy (ctxt), m_num_elements);

gcc/testsuite/jit.dg/test-types.c

+5
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
492492

493493
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
494494
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
495+
496+
gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
497+
gcc_jit_type *array_type1 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
498+
gcc_jit_type *array_type2 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2);
499+
CHECK (gcc_jit_compatible_types (array_type1, array_type2));
495500
}

0 commit comments

Comments
 (0)