]> 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)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 28 Apr 2025 14:18:53 +0000 (16:18 +0200)
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 c6bb147c1c8f7429e960f86f7039940a34948332..2ee0d0833e82145bb65d1856a1bbc8409fb2fd88 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 85a9ada2b9b418f2fd13633148b77b953e4b3681..177dd556293c4a6970f9c3f0cb1eeac4166d8dba 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