]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Implement integer representation for enums
authorZhi Heng <yapzhhg@gmail.com>
Thu, 3 Apr 2025 15:02:59 +0000 (23:02 +0800)
committerPhilip Herron <philip.herron@embecosm.com>
Wed, 16 Apr 2025 11:03:05 +0000 (11:03 +0000)
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 <yapzhhg@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-base.cc
gcc/rust/typecheck/rust-hir-type-check-item.cc

index f066ddc4fd31e9c8e799f2f0486db6c40ef78cb6..51c1ae78ec0fd1ef32cddfe4b18b03f357c71089 100644 (file)
@@ -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;
index 7491cb47f5a735fe02eb94293f0adb638b6f8613..a29f0432397a908fc95576ec3380354d1fe04050 100644 (file)
@@ -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