From ef4afd9de440f10502f3cc84b2112cf83cde2610 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 2 Jan 2024 16:04:10 -0500 Subject: [PATCH] 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. --- gcc/jit/jit-common.h | 1 + gcc/jit/jit-recording.h | 17 +++++++++++++++++ gcc/testsuite/jit.dg/test-types.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h index 80c1618da96..57a667e6d12 100644 --- a/gcc/jit/jit-common.h +++ b/gcc/jit/jit-common.h @@ -118,6 +118,7 @@ namespace recording { class struct_; class union_; class vector_type; + class array_type; class field; class bitfield; class fields; diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 4a8082991fb..df33ce219fc 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -545,6 +545,7 @@ public: virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; } virtual struct_ *dyn_cast_struct () { return NULL; } virtual vector_type *dyn_cast_vector_type () { return NULL; } + virtual array_type *dyn_cast_array_type () { return NULL; } /* Is it typesafe to copy to this type from rtype? */ virtual bool accepts_writes_from (type *rtype) @@ -810,6 +811,11 @@ public: void replay_into (replayer *) final override; + array_type *dyn_cast_array_type () final override + { + return m_other_type->dyn_cast_array_type (); + } + private: string * make_debug_string () final override; void write_reproducer (reproducer &r) final override; @@ -868,6 +874,17 @@ class array_type : public type type *dereference () final override; + bool is_same_type_as (type *other) final override + { + array_type *other_array_type = other->dyn_cast_array_type (); + if (!other_array_type) + return false; + return m_num_elements == other_array_type->m_num_elements + && m_element_type->is_same_type_as (other_array_type->m_element_type); + } + + array_type *dyn_cast_array_type () final override { return this; } + bool is_int () const final override { return false; } bool is_float () const final override { return false; } bool is_bool () const final override { return false; } diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c index a01944e35fa..79f7ea21026 100644 --- a/gcc/testsuite/jit.dg/test-types.c +++ b/gcc/testsuite/jit.dg/test-types.c @@ -492,4 +492,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float)); CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double)); + + gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + gcc_jit_type *array_type1 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2); + gcc_jit_type *array_type2 = gcc_jit_context_new_array_type (ctxt, NULL, int_type, 2); + CHECK (gcc_jit_compatible_types (array_type1, array_type2)); } -- 2.43.0