Skip to content

Commit a23b621

Browse files
Pasta-coderP-E-P
authored andcommitted
util/attributes: Error on #[repr] applied to functions
The #[repr] attribute is only valid for structs, enums, and unions. Applying it to a function is invalid and should result in an error. This patch adds a check in the attribute visitor to reject #[repr] on functions, matching rustc behavior. Fixes #4232 gcc/rust/ChangeLog: * util/rust-attributes.cc (AttributeChecker::check_attributes): Emit error for #[repr]. gcc/testsuite/ChangeLog: * rust/compile/issue-4232.rs: New test. Signed-off-by: Jayant Chauhan <[email protected]>
1 parent 3d11639 commit a23b621

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

gcc/rust/util/rust-attributes.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,12 @@ AttributeChecker::visit (AST::Function &fun)
912912
{
913913
check_link_section_attribute (attribute);
914914
}
915+
else if (result.name == Attrs::REPR)
916+
{
917+
rust_error_at (
918+
attribute.get_locus (),
919+
"attribute should be applied to a struct, enum, or union");
920+
}
915921
}
916922

917923
if (fun.has_body ())
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// { dg-options "-w" }
2+
#[repr(C)] // { dg-error "attribute should be applied to a struct, enum, or union" }
3+
fn a() {}

0 commit comments

Comments
 (0)