public inbox for
 help / color / mirror / Atom feed
* qual_union_type help
@ 2022-02-23 15:50 Philip Herron
  2022-02-23 17:33 ` Eric Botcazou
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Herron @ 2022-02-23 15:50 UTC (permalink / raw)
  To: gcc Mailing List, gcc-rust

Hi everyone

I am seeking some help on using the QUAL_UNION_TYPE it seems ideally
placed to be used for enums in Rust. My initial implementation was
achieved by simply using a union such as:

union my_enum {
  variant_a { enum discriminant; } ;
  variant_b { enum discriminant;} ;

Having each variant contain an enum for the discriminant meant that
dataless handling variants were quite simple. Upon trying to use the
QUAL_UNION_TYPE this all seems reasonably trivial but I can't figure
out what to set the DECL_QUALIFIER to be, initially from reading the
documentation on it
seemed that it wants a slightly different layout by using a
placeholder_expr to reference an outer discriminant field such that
the layout becomes:

struct my_enum {
  enum discriminant;
  union variants {
    variant_a { data };
    variant_b { data };

So I have been creating my DECL_QUALIFIER as follows:

tree field_offset = NULL_TREE;
tree place_holder = build0 (PLACEHOLDER_EXPR, sizetype);
tree place_holder_expr
  = build3 (COMPONENT_REF, TREE_TYPE (qual_field),
        place_holder, qual_field, field_offset);

    = build2 (EQ_EXPR, boolean_type_node,
                        place_holder_expr, discrim);

So this seems to generate some interesting code and then finally hit
an ICE inside:

Breakpoint 5, gimplify_expr (expr_p=0x7ffff6ff1f48,
pre_p=0x7fffffffd2d8, post_p=0x7fffffffbb58, gimple_test_f=0x15aa98f
<is_gimple_min_lval(tree_node*)>, fallback=3) at
15755                 gcc_unreachable ();
(gdb) call debug_tree(*expr_p)
 <placeholder_expr 0x7ffff70116a8
    type <integer_type 0x7ffff700a000 sizetype public unsigned DI
        size <integer_cst 0x7ffff6ff3c00 constant 64>
        unit-size <integer_cst 0x7ffff6ff3c18 constant 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1
canonical-type 0x7ffff700a000 precision:64 min <integer_cst
0x7ffff6ff3c30 0> max <integer_cst 0x7ffff6ff44a0

This makes sense this we can't gimplify a placeholder expression. So
this seems that when i make a constructor for the QUAL_UNION_TYPE i
must iterate the fields and replace the placeholder_expr to have a
reference to the discriminant via another COMPONENT_REF. Though does
this mean for the constructor i will need to create a temporary to
hold onto it to create another component_ref?

Or am I doing this completely wrong? I haven't had much success in
following the QUAL_UNION_TYPE code in the Ada front-end, but any
pointers would be greatly appreciated.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-23 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 15:50 qual_union_type help Philip Herron
2022-02-23 17:33 ` Eric Botcazou
2022-02-23 17:44   ` Philip Herron
2022-02-23 18:19     ` Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).