Skip to content

Commit 141e034

Browse files
authored
Merge pull request #10 from antoyo/feature/jit-target-builtins-with-array-of-struct-fix
Multiple fixes
2 parents 6be77e0 + 9022bee commit 141e034

9 files changed

+70
-15
lines changed

gcc/jit/dummy-frontend.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,12 @@ struct GTY(()) lang_identifier
518518
/* The resulting tree type. */
519519

520520
union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
521-
chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
522-
lang_tree_node
523-
{
524-
union tree_node GTY((tag ("0"),
525-
desc ("tree_node_structure (&%h)"))) generic;
526-
struct lang_identifier GTY((tag ("1"))) identifier;
521+
chain_next ("(union lang_tree_node *) jit_tree_chain_next (&%h.generic)"))) lang_tree_node
522+
{
523+
union tree_node GTY ((tag ("0"),
524+
desc ("tree_node_structure (&%h)")))
525+
generic;
526+
struct lang_identifier GTY ((tag ("1"))) identifier;
527527
};
528528

529529
/* We don't use language_function. */

gcc/jit/jit-common.h

+14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_INT128_T + 1;
9393
9494
End of comment for inclusion in the docs. */
9595

96+
static inline tree
97+
jit_tree_chain_next (tree t)
98+
{
99+
/* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
100+
kind of object, never a long chain of nodes. Prefer
101+
TYPE_NEXT_VARIANT for types. */
102+
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
103+
return TYPE_NEXT_VARIANT (t);
104+
/* Otherwise, if there is TREE_CHAIN, return it. */
105+
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
106+
return TREE_CHAIN (t);
107+
return NULL;
108+
}
109+
96110
namespace gcc {
97111

98112
namespace jit {

gcc/jit/jit-playback.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ playback::compound_type *
405405
playback::context::
406406
new_compound_type (location *loc,
407407
const char *name,
408-
bool is_struct) /* else is union */
408+
bool is_struct, /* else is union */
409+
bool is_packed)
409410
{
410411
gcc_assert (name);
411412

@@ -415,14 +416,17 @@ new_compound_type (location *loc,
415416
TYPE_NAME (t) = get_identifier (name);
416417
TYPE_SIZE (t) = 0;
417418

419+
if (is_packed)
420+
TYPE_PACKED (t) = 1;
421+
418422
if (loc)
419423
set_tree_location (t, loc);
420424

421425
return new compound_type (t);
422426
}
423427

424428
void
425-
playback::compound_type::set_fields (const auto_vec<playback::field *> *fields)
429+
playback::compound_type::set_fields (const auto_vec<playback::field *> *fields, bool is_packed)
426430
{
427431
/* Compare with c/c-decl.cc: finish_struct. */
428432
tree t = as_tree ();
@@ -439,6 +443,10 @@ playback::compound_type::set_fields (const auto_vec<playback::field *> *fields)
439443
DECL_SIZE (x) = bitsize_int (width);
440444
DECL_BIT_FIELD (x) = 1;
441445
}
446+
447+
if (is_packed && (DECL_BIT_FIELD (x)
448+
|| TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
449+
DECL_PACKED (x) = 1;
442450
fieldlist = chainon (x, fieldlist);
443451
}
444452
fieldlist = nreverse (fieldlist);

gcc/jit/jit-playback.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class context : public log_user
8585
compound_type *
8686
new_compound_type (location *loc,
8787
const char *name,
88-
bool is_struct); /* else is union */
88+
bool is_struct, /* else is union */
89+
bool is_packed);
8990

9091
type *
9192
new_function_type (type *return_type,
@@ -472,7 +473,7 @@ class compound_type : public type
472473
: type (inner)
473474
{}
474475

475-
void set_fields (const auto_vec<field *> *fields);
476+
void set_fields (const auto_vec<field *> *fields, bool is_packed);
476477
};
477478

478479
class field : public wrapper

gcc/jit/jit-recording.cc

+13-5
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,15 @@ recording::context::new_array_type (recording::location *loc,
845845
recording::type *element_type,
846846
int num_elements)
847847
{
848-
if (struct_ *s = element_type->dyn_cast_struct ())
848+
/*if (struct_ *s = element_type->dyn_cast_struct ())
849849
if (!s->get_fields ())
850850
{
851851
add_error (NULL,
852852
"cannot create an array of type %s"
853853
" until the fields have been set",
854854
s->get_name ()->c_str ());
855855
return NULL;
856-
}
856+
}*/
857857
recording::type *result =
858858
new recording::array_type (this, loc, element_type, num_elements);
859859
record (result);
@@ -2385,6 +2385,12 @@ recording::type::get_aligned (size_t alignment_in_bytes)
23852385
return result;
23862386
}
23872387

2388+
void
2389+
recording::type::set_packed ()
2390+
{
2391+
m_packed = true;
2392+
}
2393+
23882394
/* Given a type, get a vector version of the type.
23892395
23902396
Implements the post-error-checking part of
@@ -3578,7 +3584,8 @@ recording::struct_::replay_into (replayer *r)
35783584
set_playback_obj (
35793585
r->new_compound_type (playback_location (r, get_loc ()),
35803586
get_name ()->c_str (),
3581-
true /* is_struct */));
3587+
true, /* is_struct */
3588+
m_packed));
35823589
}
35833590

35843591
const char *
@@ -3632,7 +3639,8 @@ recording::union_::replay_into (replayer *r)
36323639
set_playback_obj (
36333640
r->new_compound_type (playback_location (r, get_loc ()),
36343641
get_name ()->c_str (),
3635-
false /* is_struct */));
3642+
false, /* is_struct */
3643+
m_packed));
36363644
}
36373645

36383646
/* Implementation of recording::memento::make_debug_string for
@@ -3703,7 +3711,7 @@ recording::fields::replay_into (replayer *)
37033711
playback_fields.create (m_fields.length ());
37043712
for (unsigned i = 0; i < m_fields.length (); i++)
37053713
playback_fields.safe_push (m_fields[i]->playback_field ());
3706-
m_struct_or_union->playback_compound_type ()->set_fields (&playback_fields);
3714+
m_struct_or_union->playback_compound_type ()->set_fields (&playback_fields, m_struct_or_union->m_packed);
37073715
}
37083716

37093717
/* Override the default implementation of

gcc/jit/jit-recording.h

+6
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ class type : public memento
545545
type *get_aligned (size_t alignment_in_bytes);
546546
type *get_vector (size_t num_units);
547547

548+
void set_packed ();
549+
548550
/* Get the type obtained when dereferencing this type.
549551
550552
This will return NULL if it's not valid to dereference this type.
@@ -613,9 +615,13 @@ class type : public memento
613615
protected:
614616
type (context *ctxt)
615617
: memento (ctxt),
618+
m_packed (false),
616619
m_pointer_to_this_type (NULL)
617620
{}
618621

622+
public:
623+
bool m_packed;
624+
619625
private:
620626
type *m_pointer_to_this_type;
621627
};

gcc/jit/libgccjit.cc

+9
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ size_t
981981
gcc_jit_struct_get_field_count (gcc_jit_struct *struct_type)
982982
{
983983
RETURN_VAL_IF_FAIL (struct_type, 0, NULL, NULL, "NULL struct type");
984+
RETURN_VAL_IF_FAIL (struct_type->get_fields (), 0, NULL, NULL, "NULL fields");
984985
return struct_type->get_fields ()->length ();
985986
}
986987

@@ -4016,6 +4017,14 @@ gcc_jit_type_get_aligned (gcc_jit_type *type,
40164017
return (gcc_jit_type *)type->get_aligned (alignment_in_bytes);
40174018
}
40184019

4020+
void
4021+
gcc_jit_type_set_packed (gcc_jit_type *type)
4022+
{
4023+
RETURN_IF_FAIL (type, NULL, NULL, "NULL type");
4024+
4025+
type->set_packed ();
4026+
}
4027+
40194028
/* Public entrypoint. See description in libgccjit.h.
40204029
40214030
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

+4
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,10 @@ gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type);
20192019
extern gcc_jit_type *
20202020
gcc_jit_type_unqualified (gcc_jit_type *type);
20212021

2022+
/* Given type "T", get type "T __attribute__ ((packed))". */
2023+
extern void
2024+
gcc_jit_type_set_packed (gcc_jit_type *type);
2025+
20222026
#ifdef __cplusplus
20232027
}
20242028
#endif /* __cplusplus */

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,8 @@ LIBGCCJIT_ABI_25 {
278278
gcc_jit_context_new_vector_constructor;
279279
gcc_jit_context_new_vector_access;
280280
} LIBGCCJIT_ABI_24;
281+
282+
LIBGCCJIT_ABI_26 {
283+
global:
284+
gcc_jit_type_set_packed;
285+
} LIBGCCJIT_ABI_25;

0 commit comments

Comments
 (0)