Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[no_mangle] should not be applied to non-ASCII items #2552

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

tamaroning
Copy link
Contributor

@tamaroning tamaroning commented Aug 13, 2023

Fixes #2548

gccrs: Check function names with no_mangle.
gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl): Add parameter.
	* backend/rust-compile-base.h: Likewise.
	* backend/rust-compile-implitem.cc (CompileTraitItem::visit): Change type of parameter.
	* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
	* lex/rust-input-source.h: Move constants to rust-codepoint.h
	* util/rust-codepoint.h (struct Codepoint): Add is_ascii method.
	* util/rust-punycode.cc (extract_basic_string): Use it.
	* lex/rust-lex.cc (Lexer::parse_byte_char): Likewise.
	* backend/rust-mangle.cc (legacy_mangle_name): Likewise.
	* util/rust-unicode.cc (is_ascii_only): New function.
	* util/rust-unicode.h (is_ascii_only): Likewise.

Error diagnostics looks like this:

#[no_mangle]
pub fn ascii() {}

#[no_mangle]
pub fn notーascii() {}
./gccrs-build/gcc/crab1 a.rs -frust-incomplete-and-experimental-compiler-do-not-use -fdump-tree-gimple
a.rs:5:8: error: attribute ‘no_mangle’ requires ASCII identifier [E0754]
    5 | pub fn notーascii() {}
      |        ^~~~~~~~

@tamaroning tamaroning marked this pull request as ready for review August 13, 2023 08:52
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure having that check so late in the backend is the right way to go about it. We can add a check to the attribute checker in rust-attributes.h and just check if a function or method has the attribute and a non-ascii name. I think that will be easier

@tamaroning
Copy link
Contributor Author

Hm, I'm not sure having that check so late in the backend is the right way to go about it. We can add a check to the attribute checker in rust-attributes.h and just check if a function or method has the attribute and a non-ascii name. I think that will be easier

rustc does somethinig like it. It will be better.

@tamaroning tamaroning force-pushed the fix-no-mangle branch 2 times, most recently from a4743cc to ca730f1 Compare August 18, 2023 04:06
@tamaroning
Copy link
Contributor Author

@CohenArthur
Fixed code. Could you please review again?

@tamaroning tamaroning force-pushed the fix-no-mangle branch 3 times, most recently from 23ba1f7 to 179a71f Compare August 18, 2023 05:07
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! And yeah, it is much simpler. Thanks for making the changes! Great work!

Comment on lines 627 to 631
auto check_function_name = [] (const char *name, const Identifier &ident) {
if (!is_ascii_only (ident.as_string ()))
rust_error_at (ident.get_locus (),
"the %<#[%s]%> attribute requires ASCII identifier", name);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this function be used for anything other than the #[no_mangle] attribute? If no, we can skip having the const char *name argument. I think it would also be cleaner to have it as a static void function in the file rather than a lambda, as C++ lambdas are not super easy to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I will fix it later.

gcc/rust/ChangeLog:

	* lex/rust-input-source.h: Move constants from here...
	* util/rust-codepoint.h (struct Codepoint): ... to here
	* util/rust-attributes.cc (check_no_mangle_function): New function.
	(AttributeChecker::visit): Use it.
	* util/rust-unicode.cc (is_ascii_only): New function.
	* util/rust-unicode.h (is_ascii_only): Likewise.
	* backend/rust-mangle.cc (legacy_mangle_name): Use it.
	* util/rust-punycode.cc (extract_basic_string): Likewise.
	* lex/rust-lex.cc (Lexer::parse_byte_char): Likewise.

Signed-off-by: Raiki Tamura <[email protected]>
@tamaroning
Copy link
Contributor Author

@CohenArthur Everything is fixed now :)

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Tiny nitpick and I'll merge this. Thank you!

gcc/rust/util/rust-attributes.cc Show resolved Hide resolved
@CohenArthur CohenArthur added this pull request to the merge queue Aug 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Aug 29, 2023
@P-E-P P-E-P added this pull request to the merge queue Aug 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Aug 29, 2023
@CohenArthur CohenArthur added this pull request to the merge queue Aug 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Aug 29, 2023
@P-E-P P-E-P added this pull request to the merge queue Sep 1, 2023
Merged via the queue into Rust-GCC:master with commit 6479fbf Sep 1, 2023
9 checks passed
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.

#[no_mangle] should not be applied to non-ASCII items
3 participants