Skip to content

Commit

Permalink
Merge pull request #44 from GuillaumeGomez/get_ptr_size
Browse files Browse the repository at this point in the history
[PATCH] Allow `gcc_jit_type_get_size` to work with pointers
  • Loading branch information
antoyo authored Mar 27, 2024
2 parents 78dc50f + 21e6e2d commit 2cf6ca7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,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 ();
}

Expand Down
27 changes: 27 additions & 0 deletions gcc/testsuite/jit.dg/test-pointer_size.c
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit 2cf6ca7

Please sign in to comment.