https://gcc.gnu.org/g:654d79b98a67834fb33a51d05c452a1ff729e1d3

commit 654d79b98a67834fb33a51d05c452a1ff729e1d3
Author: Zhi Heng <yapz...@gmail.com>
Date:   Thu Apr 3 23:02:59 2025 +0800

    gccrs: Implement integer representation for enums
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-base.cc: Set enum representing
            type properly if repr is an integer type.
            * typecheck/rust-hir-type-check-item.cc: Update comments.
    
    Signed-off-by: Yap Zhi Heng <yapz...@gmail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 13 ++++++++++---
 gcc/rust/typecheck/rust-hir-type-check-item.cc |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index f066ddc4fd31..51c1ae78ec0f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -308,7 +308,7 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
   repr.pack = 0;
   repr.align = 0;
 
-  // FIXME handle repr types....
+  // FIXME handle non-integer repr types....
   bool ok = context->lookup_builtin ("isize", &repr.repr);
   rust_assert (ok);
 
@@ -353,8 +353,10 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
          // manually parsing the string "packed(2)" here.
 
          size_t oparen = inline_option.find ('(', 0);
-         bool is_pack = false, is_align = false, is_c = false,
-              is_integer = false;
+         bool is_pack = false;
+         bool is_align = false;
+         bool is_c = false;
+         bool is_integer = false;
          unsigned char value = 1;
 
          if (oparen == std::string::npos)
@@ -409,6 +411,11 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
          else if (is_integer)
            {
              repr.repr_kind = TyTy::ADTType::ReprKind::INT;
+             bool ok = context->lookup_builtin (inline_option, &repr.repr);
+             if (!ok)
+               {
+                 rust_error_at (attr.get_locus (), "Invalid repr type");
+               }
            }
 
          delete meta_items;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 7491cb47f5a7..a29f0432397a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -355,7 +355,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
       variants.push_back (field_type);
     }
 
-  // Check for zero-variant enum compatibility before processing repr attribute
+  // Check for zero-variant enum compatibility
   if (enum_decl.is_zero_variant ())
     {
       if (repr.repr_kind == TyTy::ADTType::ReprKind::INT

Reply via email to