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

Error for uninitialized register on asm blocks #5231

Merged
merged 8 commits into from
Oct 31, 2023

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Oct 26, 2023

Description

This PR closes #4997. The problem here is that "asm blocks registers" without initializers are considered uninitialized. There is no fallback to "capture" an available variable. This could be easily done, but that would leave us with no obvious syntax for unitialized registers.

With this in mind this PR solves the compiler bug with two diagnostics:

1 - uninitialized registers cannot be read before they are written. This generates an error:

 5 |     let _ = asm(r1) {
   |                 ^^ Unitialized register is being read before being written
 6 |         r1: u64
 7 |     };

2 - a warning when a unitialized register shadows an available variable with the same name. This is almost for sure a problem, and it is better the name the registe with something else and avoid all the confusion.

 27 |     let r5 = 0;
 28 |     asm(r5) {};
    |         -- This unitialized register is shadowing a variable, you probably meant to also initialize it like "r5: r5".
 29 | 
 30 |     0

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@xunilrj xunilrj self-assigned this Oct 27, 2023
@xunilrj xunilrj requested a review from a team October 27, 2023 09:54
@xunilrj xunilrj marked this pull request as ready for review October 27, 2023 09:54
@IGI-111 IGI-111 requested a review from a team October 27, 2023 12:11
vaivaswatha
vaivaswatha previously approved these changes Oct 27, 2023
@IGI-111 IGI-111 enabled auto-merge (squash) October 31, 2023 14:17
@IGI-111 IGI-111 merged commit de7c19b into master Oct 31, 2023
31 checks passed
@IGI-111 IGI-111 deleted the xunilrj/asm-block-uninitialized-reg branch October 31, 2023 14:54
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.

Internal compiler error: Program erroneously uses uninitialized virtual registers: $r8
3 participants