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-expr.h | |
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-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 4cc4dfc..43eff72 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -24,6 +24,7 @@ #include "rust-compile-resolve-path.h" #include "rust-compile-block.h" #include "rust-compile-struct-field-expr.h" +#include "rust-constexpr.h" namespace Rust { namespace Compile { @@ -488,13 +489,10 @@ public: std::vector<tree> ctor_arguments; if (adt->is_enum ()) { - HirId variant_id = variant->get_id (); - mpz_t val; - mpz_init_set_ui (val, variant_id); - - tree t = TyTyResolveCompile::get_implicit_enumeral_node_type (ctx); - tree 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; ctor_arguments.push_back (qualifier); } |