diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-02 14:06:25 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-02 14:06:25 +0000 |
commit | 46ee20dbdbb02b40ae199293dfa774fafad72c0e (patch) | |
tree | 7a9abfd0b49074b315715fa1b2cef51951cabdca /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | 6e5f8f76cbe47880ceae1bcf0bf7f07f601517ec (diff) | |
download | gcc-46ee20dbdbb02b40ae199293dfa774fafad72c0e.zip gcc-46ee20dbdbb02b40ae199293dfa774fafad72c0e.tar.gz gcc-46ee20dbdbb02b40ae199293dfa774fafad72c0e.tar.bz2 |
Fix enum variant discriminant values
Enum discriminants before this patch were either:
- The hir-id of the tuple/struct variant
- The expression of the specified discriminant
- Computed int64 of the dataless variant
Each of these had tree ways of computing the qualifier this patch changes
this to be more in line with rust to compute the values unless its a
specified discriminant value. In order to compile this we now create an
implicit HIR::LiteralExpr and feed this into our constexpr code so it
reuses the same path as the variants with a specified constant
discriminant.
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index ddb6c91..c624046 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -86,8 +86,8 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, &union_disriminator)) return ctx->get_backend ()->error_expression (); - // FIXME should really return error_mark_node and or rust_internal_error - // error_mark_node + // this can only be for discriminant variants the others are built up + // using call-expr or struct-init rust_assert (variant->get_variant_type () == TyTy::VariantDef::VariantType::NUM); @@ -95,24 +95,10 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt); // make the ctor for the union - tree qualifier = error_mark_node; - if (variant->is_specified_discriminant_node ()) - { - auto discrim_node = variant->get_discriminant_node (); - auto &discrim_expr = discrim_node->get_discriminant_expression (); - - tree discrim_expr_node - = CompileExpr::Compile (discrim_expr.get (), ctx); - tree folded_discrim_expr = ConstCtx::fold (discrim_expr_node); - qualifier = folded_discrim_expr; - } - else - { - mpz_t val; - mpz_init_set_ui (val, variant->get_discriminant ()); - tree t = TyTyResolveCompile::get_implicit_enumeral_node_type (ctx); - qualifier = double_int_to_tree (t, mpz_get_double_int (t, val, true)); - } + HIR::Expr *discrim_expr = variant->get_discriminant (); + tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); + tree folded_discrim_expr = ConstCtx::fold (discrim_expr_node); + tree qualifier = folded_discrim_expr; return ctx->get_backend ()->constructor_expression (compiled_adt_type, true, {qualifier}, |