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-pattern.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-pattern.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-pattern.cc | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index b255dc6..d715c7c 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -48,33 +48,10 @@ CompilePatternCaseLabelExpr::visit (HIR::PathInExpression &pattern) ok = adt->lookup_variant_by_id (variant_id, &variant); rust_assert (ok); - tree case_low = 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); - case_low = folded_discrim_expr; - } - else - { - mpz_t disciminantl; - if (variant->get_variant_type () == TyTy::VariantDef::VariantType::NUM) - { - mpz_init_set_ui (disciminantl, variant->get_discriminant ()); - } - else - { - HirId variant_id = variant->get_id (); - mpz_init_set_ui (disciminantl, variant_id); - } - - tree t = TyTyResolveCompile::get_implicit_enumeral_node_type (ctx); - case_low - = double_int_to_tree (t, mpz_get_double_int (t, disciminantl, 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 case_low = folded_discrim_expr; case_label_expr = build_case_label (case_low, NULL_TREE, associated_case_label); |