Skip to content

Multiple fixes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gcc/jit/dummy-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ struct GTY(()) lang_identifier
/* The resulting tree type. */

union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
lang_tree_node
{
union tree_node GTY((tag ("0"),
desc ("tree_node_structure (&%h)"))) generic;
struct lang_identifier GTY((tag ("1"))) identifier;
chain_next ("(union lang_tree_node *) jit_tree_chain_next (&%h.generic)"))) lang_tree_node
{
union tree_node GTY ((tag ("0"),
desc ("tree_node_structure (&%h)")))
generic;
struct lang_identifier GTY ((tag ("1"))) identifier;
};

/* We don't use language_function. */
Expand Down
14 changes: 14 additions & 0 deletions gcc/jit/jit-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_INT128_T + 1;

End of comment for inclusion in the docs. */

static inline tree
jit_tree_chain_next (tree t)
{
/* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
kind of object, never a long chain of nodes. Prefer
TYPE_NEXT_VARIANT for types. */
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
return TYPE_NEXT_VARIANT (t);
/* Otherwise, if there is TREE_CHAIN, return it. */
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
return TREE_CHAIN (t);
return NULL;
}

namespace gcc {

namespace jit {
Expand Down
12 changes: 10 additions & 2 deletions gcc/jit/jit-playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ playback::compound_type *
playback::context::
new_compound_type (location *loc,
const char *name,
bool is_struct) /* else is union */
bool is_struct, /* else is union */
bool is_packed)
{
gcc_assert (name);

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

if (is_packed)
TYPE_PACKED (t) = 1;

if (loc)
set_tree_location (t, loc);

return new compound_type (t);
}

void
playback::compound_type::set_fields (const auto_vec<playback::field *> *fields)
playback::compound_type::set_fields (const auto_vec<playback::field *> *fields, bool is_packed)
{
/* Compare with c/c-decl.cc: finish_struct. */
tree t = as_tree ();
Expand All @@ -439,6 +443,10 @@ playback::compound_type::set_fields (const auto_vec<playback::field *> *fields)
DECL_SIZE (x) = bitsize_int (width);
DECL_BIT_FIELD (x) = 1;
}

if (is_packed && (DECL_BIT_FIELD (x)
|| TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
DECL_PACKED (x) = 1;
fieldlist = chainon (x, fieldlist);
}
fieldlist = nreverse (fieldlist);
Expand Down
5 changes: 3 additions & 2 deletions gcc/jit/jit-playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class context : public log_user
compound_type *
new_compound_type (location *loc,
const char *name,
bool is_struct); /* else is union */
bool is_struct, /* else is union */
bool is_packed);

type *
new_function_type (type *return_type,
Expand Down Expand Up @@ -472,7 +473,7 @@ class compound_type : public type
: type (inner)
{}

void set_fields (const auto_vec<field *> *fields);
void set_fields (const auto_vec<field *> *fields, bool is_packed);
};

class field : public wrapper
Expand Down
18 changes: 13 additions & 5 deletions gcc/jit/jit-recording.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,15 @@ recording::context::new_array_type (recording::location *loc,
recording::type *element_type,
int num_elements)
{
if (struct_ *s = element_type->dyn_cast_struct ())
/*if (struct_ *s = element_type->dyn_cast_struct ())
if (!s->get_fields ())
{
add_error (NULL,
"cannot create an array of type %s"
" until the fields have been set",
s->get_name ()->c_str ());
return NULL;
}
}*/
recording::type *result =
new recording::array_type (this, loc, element_type, num_elements);
record (result);
Expand Down Expand Up @@ -2385,6 +2385,12 @@ recording::type::get_aligned (size_t alignment_in_bytes)
return result;
}

void
recording::type::set_packed ()
{
m_packed = true;
}

/* Given a type, get a vector version of the type.

Implements the post-error-checking part of
Expand Down Expand Up @@ -3578,7 +3584,8 @@ recording::struct_::replay_into (replayer *r)
set_playback_obj (
r->new_compound_type (playback_location (r, get_loc ()),
get_name ()->c_str (),
true /* is_struct */));
true, /* is_struct */
m_packed));
}

const char *
Expand Down Expand Up @@ -3632,7 +3639,8 @@ recording::union_::replay_into (replayer *r)
set_playback_obj (
r->new_compound_type (playback_location (r, get_loc ()),
get_name ()->c_str (),
false /* is_struct */));
false, /* is_struct */
m_packed));
}

/* Implementation of recording::memento::make_debug_string for
Expand Down Expand Up @@ -3703,7 +3711,7 @@ recording::fields::replay_into (replayer *)
playback_fields.create (m_fields.length ());
for (unsigned i = 0; i < m_fields.length (); i++)
playback_fields.safe_push (m_fields[i]->playback_field ());
m_struct_or_union->playback_compound_type ()->set_fields (&playback_fields);
m_struct_or_union->playback_compound_type ()->set_fields (&playback_fields, m_struct_or_union->m_packed);
}

/* Override the default implementation of
Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ class type : public memento
type *get_aligned (size_t alignment_in_bytes);
type *get_vector (size_t num_units);

void set_packed ();

/* Get the type obtained when dereferencing this type.

This will return NULL if it's not valid to dereference this type.
Expand Down Expand Up @@ -613,9 +615,13 @@ class type : public memento
protected:
type (context *ctxt)
: memento (ctxt),
m_packed (false),
m_pointer_to_this_type (NULL)
{}

public:
bool m_packed;

private:
type *m_pointer_to_this_type;
};
Expand Down
9 changes: 9 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ size_t
gcc_jit_struct_get_field_count (gcc_jit_struct *struct_type)
{
RETURN_VAL_IF_FAIL (struct_type, 0, NULL, NULL, "NULL struct type");
RETURN_VAL_IF_FAIL (struct_type->get_fields (), 0, NULL, NULL, "NULL fields");
return struct_type->get_fields ()->length ();
}

Expand Down Expand Up @@ -4016,6 +4017,14 @@ gcc_jit_type_get_aligned (gcc_jit_type *type,
return (gcc_jit_type *)type->get_aligned (alignment_in_bytes);
}

void
gcc_jit_type_set_packed (gcc_jit_type *type)
{
RETURN_IF_FAIL (type, NULL, NULL, "NULL type");

type->set_packed ();
}

/* Public entrypoint. See description in libgccjit.h.

After error-checking, the real work is done by the
Expand Down
4 changes: 4 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,10 @@ gcc_jit_vector_type_get_element_type (gcc_jit_vector_type *vector_type);
extern gcc_jit_type *
gcc_jit_type_unqualified (gcc_jit_type *type);

/* Given type "T", get type "T __attribute__ ((packed))". */
extern void
gcc_jit_type_set_packed (gcc_jit_type *type);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,8 @@ LIBGCCJIT_ABI_25 {
gcc_jit_context_new_vector_constructor;
gcc_jit_context_new_vector_access;
} LIBGCCJIT_ABI_24;

LIBGCCJIT_ABI_26 {
global:
gcc_jit_type_set_packed;
} LIBGCCJIT_ABI_25;