]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PATCH] Allow `gcc_jit_type_get_size` to work with pointers
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 29 Mar 2024 17:56:33 +0000 (18:56 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 29 Mar 2024 18:05:48 +0000 (19:05 +0100)
gcc/jit/ChangeLog:

* libgccjit.cc (gcc_jit_type_get_size): Add pointer support

gcc/jit/libgccjit.cc
gcc/testsuite/jit.dg/test-pointer_size.c [new file with mode: 0644]

index f40a978140515538bf9ed07fb20499acbbc7b975..445c0d0e0e39630f352dc6b35292e87c2715cc46 100644 (file)
@@ -560,8 +560,8 @@ gcc_jit_type_get_size (gcc_jit_type *type)
 {
   RETURN_VAL_IF_FAIL (type, -1, NULL, NULL, "NULL type");
   RETURN_VAL_IF_FAIL
-    (type->is_int () || type->is_float (), -1, NULL, NULL,
-     "only getting the size of integer or floating-point types is supported for now");
+    (type->is_int () || type->is_float () || type->is_pointer (), -1, NULL, NULL,
+     "only getting the size of integer or floating-point or pointer types is supported for now");
   return type->get_size ();
 }
 
diff --git a/gcc/testsuite/jit.dg/test-pointer_size.c b/gcc/testsuite/jit.dg/test-pointer_size.c
new file mode 100644 (file)
index 0000000..337796a
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-do compile { target x86_64-*-* } } */
+
+#include <assert.h>
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  gcc_jit_type *int_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+  gcc_jit_type *int_ptr_type = gcc_jit_type_get_pointer (int_type);
+
+  int int_ptr_size = gcc_jit_type_get_size (int_ptr_type);
+  CHECK_VALUE (int_ptr_size, 8);
+
+  gcc_jit_type *void_type =
+    gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+  gcc_jit_type *void_ptr_type = gcc_jit_type_get_pointer (void_type);
+
+  CHECK_VALUE (int_ptr_size, gcc_jit_type_get_size (void_ptr_type));
+}