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 Rust-GCC#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 <0001jayant@gmail.com>
BuiltinAttrDefinition result;
for (auto &attribute : item.get_outer_attrs ())
{
- if (is_builtin (attribute, result) && result.name == Attrs::LINK_SECTION)
+ if (is_builtin (attribute, result))
{
- check_link_section_attribute (attribute);
+ if (result.name == Attrs::LINK_SECTION)
+ {
+ check_link_section_attribute (attribute);
+ }
+ else if (result.name == Attrs::EXPORT_NAME)
+ {
+ check_export_name_attribute (attribute);
+ }
}
}
}
--- /dev/null
+#[export_name] // { dg-error "malformed" }
+static A: i32 = 0;
+
+#[export_name(123)] // { dg-error "attribute must be a string literal" }
+static B: i32 = 0;
+
+#[export_name = 123] // { dg-error "attribute must be a string literal" }
+static C: i32 = 0;
+
+#[export_name = "valid_static"]
+static D: i32 = 0;
+
+fn main() {}
\ No newline at end of file