Skip to content

gccrs: Fix ICE in handle_inline_attribute_on_fndecl #3754

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

varun-r-mallya
Copy link

@varun-r-mallya varun-r-mallya commented Apr 17, 2025

I added a check to see if the attr_input_type was
a TOKEN_TREE and added an error message if a LITERAL is passed to it.

Fixes #3658

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
Handle LITERAL attribute input type.

gcc/testsuite/ChangeLog:

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

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@varun-r-mallya varun-r-mallya force-pushed the varun-r-mallya/issue3658 branch from d27811e to 4b6b663 Compare April 17, 2025 19:09
@dkm
Copy link
Member

dkm commented Apr 17, 2025

FTR, in the changelog, you're supposed to give extra info, not only the filename:

   * backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl): Handle LITERAL attribute input type.

@varun-r-mallya varun-r-mallya force-pushed the varun-r-mallya/issue3658 branch from 4b6b663 to 603be25 Compare April 17, 2025 19:41
@varun-r-mallya
Copy link
Author

FTR, in the changelog, you're supposed to give extra info, not only the filename:

   * backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl): Handle LITERAL attribute input type.

Just made the requested change.

@dkm
Copy link
Member

dkm commented Apr 18, 2025

You must also use full issue ref, not only #<number>. We need this because commits will be contributed to GCC, so a bare #3658 will be ambiguous and will probably cause issue with the various bug trackers involved.

Please use Rust-GCC/gccrs#3658 instead (will be rendered the same here : #3658)

@dkm
Copy link
Member

dkm commented Apr 18, 2025

(obviously, https://github.com/Rust-GCC/gccrs/actions/runs/14523528568/job/40749776631?pr=3754 didn't work as expected...)

@varun-r-mallya
Copy link
Author

varun-r-mallya commented Apr 18, 2025

(obviously, https://github.com/Rust-GCC/gccrs/actions/runs/14523528568/job/40749776631?pr=3754 didn't work as expected...)

would this be something I could fix in the CI so it fails properly ?

@varun-r-mallya varun-r-mallya force-pushed the varun-r-mallya/issue3658 branch from 603be25 to caecfd5 Compare April 18, 2025 07:43
@varun-r-mallya
Copy link
Author

#3754 (comment)
fixed :)

@dkm
Copy link
Member

dkm commented Apr 18, 2025

(obviously, https://github.com/Rust-GCC/gccrs/actions/runs/14523528568/job/40749776631?pr=3754 didn't work as expected...)

would this be something I could fix in the CI so it fails properly ?

probably yes :)

@varun-r-mallya
Copy link
Author

#3754 (comment)
I'll try to send in a PR soon!!

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

You need to add a test case to gcc/testsuite/rust/compile

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.

I think there might be some issues with your clang-format setup and the file was formatted automatically? make sure you've copied <gccrs>/contrib/clang-format to <gccrs>/.clang-format (check the leading period is here) for your editor to pick it up automatically.

I think the changes themselves are good, well done :)

Comment on lines -381 to +398
const std::string inline_option
= meta_item->get_items ().at (0)->as_string ();
const std::string inline_option
= meta_item->get_items ().at (0)->as_string ();

// we only care about NEVER and ALWAYS else its an error
bool is_always = inline_option.compare ("always") == 0;
bool is_never = inline_option.compare ("never") == 0;
// we only care about NEVER and ALWAYS else its an error
bool is_always = inline_option.compare ("always") == 0;
bool is_never = inline_option.compare ("never") == 0;
Copy link
Member

Choose a reason for hiding this comment

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

e.g. this is what I mean with the formatting, it shouldn't have changed here

Copy link
Author

Choose a reason for hiding this comment

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

I think this happened because I enclosed it in an if statement. I did try running clang-format with the file again, but it didn't really change anything. Please tell me why this is happening ? Also, it did pass the CI for clang-format so I am assuming this might be a CI bug as well if it is actually a problem.

Copy link
Member

Choose a reason for hiding this comment

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

You could reduce the nesting to avoid the extra changes by doing something like:

else if (input_type != AST::AttrInput::AttrInputType::TOKEN_TREE)
{
  // emit error
}

Then carry on with logic, I think should do it

I added a check to see if the attr_input_type was
a TOKEN_TREE and added an error message if a LITERAL is passed to it.

Fixes Rust-GCC#3658

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
	Handle LITERAL attribute input type.

gcc/testsuite/ChangeLog:

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

Signed-off-by: varun-r-mallya <[email protected]>
@varun-r-mallya varun-r-mallya force-pushed the varun-r-mallya/issue3658 branch from caecfd5 to 12d8a23 Compare April 18, 2025 10:30
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.

ICE in handle_inline_attribute_on_fndecl, at rust/backend/rust-compile-base.cc:369 inline attr w param
4 participants