aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhi Heng <yapzhhg@gmail.com>2025-04-03 23:02:59 +0800
committerPhilip Herron <philip.herron@embecosm.com>2025-04-16 11:03:05 +0000
commit654d79b98a67834fb33a51d05c452a1ff729e1d3 (patch)
tree89b4d8f4d2ec1087a33f921d31e7b54ee52cbb30
parent2c109a2e8a97980b293edb7dc3609556473c7f3d (diff)
downloadgcc-654d79b98a67834fb33a51d05c452a1ff729e1d3.zip
gcc-654d79b98a67834fb33a51d05c452a1ff729e1d3.tar.gz
gcc-654d79b98a67834fb33a51d05c452a1ff729e1d3.tar.bz2
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 <yapzhhg@gmail.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-base.cc13
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-item.cc2
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 f066ddc..51c1ae7 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 7491cb4..a29f043 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