Skip to content

Commit 23de527

Browse files
Pasta-coderP-E-P
authored andcommitted
util/attributes: handle #[export_name] on static items
This patch enables validation for the #[export_name] attribute when used on static items. It reuses the validation logic introduced for functions to ensure that statics also receive compile-time checks for malformed inputs (e.g. non-string literals). Fixes #4388 gcc/rust/ChangeLog: * util/rust-attributes.cc (AttributeChecker::visit): Add check for export_name on static items. gcc/testsuite/ChangeLog: * rust/compile/issue-4388.rs: New test. Signed-off-by: Jayant Chauhan <[email protected]>
1 parent 5b9706f commit 23de527

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

gcc/rust/util/rust-attributes.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,16 @@ AttributeChecker::visit (AST::StaticItem &item)
10161016
BuiltinAttrDefinition result;
10171017
for (auto &attribute : item.get_outer_attrs ())
10181018
{
1019-
if (is_builtin (attribute, result) && result.name == Attrs::LINK_SECTION)
1019+
if (is_builtin (attribute, result))
10201020
{
1021-
check_link_section_attribute (attribute);
1021+
if (result.name == Attrs::LINK_SECTION)
1022+
{
1023+
check_link_section_attribute (attribute);
1024+
}
1025+
else if (result.name == Attrs::EXPORT_NAME)
1026+
{
1027+
check_export_name_attribute (attribute);
1028+
}
10221029
}
10231030
}
10241031
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[export_name] // { dg-error "malformed" }
2+
static A: i32 = 0;
3+
4+
#[export_name(123)] // { dg-error "attribute must be a string literal" }
5+
static B: i32 = 0;
6+
7+
#[export_name = 123] // { dg-error "attribute must be a string literal" }
8+
static C: i32 = 0;
9+
10+
#[export_name = "valid_static"]
11+
static D: i32 = 0;
12+
13+
fn main() {}

0 commit comments

Comments
 (0)