Skip to content

Commit 2cf6ca7

Browse files
authored
Merge pull request #44 from GuillaumeGomez/get_ptr_size
[PATCH] Allow `gcc_jit_type_get_size` to work with pointers
2 parents 78dc50f + 21e6e2d commit 2cf6ca7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

gcc/jit/libgccjit.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ gcc_jit_type_get_size (gcc_jit_type *type)
575575
{
576576
RETURN_VAL_IF_FAIL (type, -1, NULL, NULL, "NULL type");
577577
RETURN_VAL_IF_FAIL
578-
(type->is_int () || type->is_float (), -1, NULL, NULL,
579-
"only getting the size of integer or floating-point types is supported for now");
578+
(type->is_int () || type->is_float () || type->is_pointer (), -1, NULL, NULL,
579+
"only getting the size of integer or floating-point or pointer types is supported for now");
580580
return type->get_size ();
581581
}
582582

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* { dg-do compile { target x86_64-*-* } } */
2+
3+
#include <assert.h>
4+
#include "libgccjit.h"
5+
6+
#include "harness.h"
7+
8+
void
9+
create_code (gcc_jit_context *ctxt, void *user_data)
10+
{}
11+
12+
void
13+
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
14+
{
15+
gcc_jit_type *int_type =
16+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
17+
gcc_jit_type *int_ptr_type = gcc_jit_type_get_pointer (int_type);
18+
19+
int int_ptr_size = gcc_jit_type_get_size (int_ptr_type);
20+
CHECK_VALUE (int_ptr_size, 8);
21+
22+
gcc_jit_type *void_type =
23+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
24+
gcc_jit_type *void_ptr_type = gcc_jit_type_get_pointer (void_type);
25+
26+
CHECK_VALUE (int_ptr_size, gcc_jit_type_get_size (void_ptr_type));
27+
}

0 commit comments

Comments
 (0)