Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

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]

Emit a diagnostic when #[export_name] is used without arguments or
with invalid arguments (non-string literals). This prevents silent
failures or backend crashes when lowering the attribute to GIMPLE,
ensuring the attribute follows the expected form: #[export_name = name].

Fixes Rust-GCC#4387

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (check_export_name_attribute): New helper.
	(AttributeChecker::visit): Check export_name on functions.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4387.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
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 <[email protected]>
@Pasta-coder
Copy link
Contributor Author

@P-E-P please review .

thankyou .

@P-E-P P-E-P added this pull request to the merge queue Jan 16, 2026
Merged via the queue into Rust-GCC:master with commit 23de527 Jan 16, 2026
12 checks passed
@Pasta-coder Pasta-coder deleted the issue-4388 branch January 16, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle export_name attribute with static items

2 participants