Skip to content

Commit 681263c

Browse files
Polygonalrdkm
authored andcommitted
gccrs: Fix ICE for repr attribute malformation
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (parse_repr_options): Changed TOKEN_TREE assert into error, update malformed repr attribute error message to be inline with other attribute error messages. Signed-off-by: Yap Zhi Heng <[email protected]>
1 parent 279d97b commit 681263c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

gcc/rust/typecheck/rust-hir-type-check-base.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
412412
bool is_repr = attr.get_path ().as_string () == Values::Attributes::REPR;
413413
if (is_repr && !attr.has_attr_input ())
414414
{
415-
rust_error_at (attr.get_locus (), "malformed %qs attribute", "repr");
415+
rust_error_at (attr.get_locus (), "malformed %<repr%> attribute");
416416
continue;
417417
}
418418

@@ -421,7 +421,11 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
421421
const AST::AttrInput &input = attr.get_attr_input ();
422422
bool is_token_tree = input.get_attr_input_type ()
423423
== AST::AttrInput::AttrInputType::TOKEN_TREE;
424-
rust_assert (is_token_tree);
424+
if (!is_token_tree)
425+
{
426+
rust_error_at (attr.get_locus (), "malformed %<repr%> attribute");
427+
continue;
428+
}
425429
const auto &option = static_cast<const AST::DelimTokenTree &> (input);
426430
AST::AttrInputMetaItemContainer *meta_items
427431
= option.parse_to_meta_item ();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[repr = ""] // { dg-error "malformed .repr. attribute" }
2+
struct ThreeInts {
3+
first: i16,
4+
second: i8,
5+
third: i32
6+
}

0 commit comments

Comments
 (0)