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

Internal compiler error: Program erroneously uses uninitialized virtual registers: $r8 #4997

Closed
Braqzen opened this issue Aug 22, 2023 · 0 comments · Fixed by #5231
Closed
Assignees
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@Braqzen
Copy link
Contributor

Braqzen commented Aug 22, 2023

Version 0.44.0

The issue is the len_to_hash in the params of the asm().
If you change len_to_hash to len_to_hash: len_to_hash it will compile.

script;

use std::constants::ZERO_B256;

fn main() {
    let len_to_hash = 32;
    let mut buffer = b256::min();

    asm(hash: buffer, prefix: ZERO_B256, len_to_hash) {
        k256 hash prefix len_to_hash;
    }
}

The order of the params is irrelevant.

@Braqzen Braqzen added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged labels Aug 22, 2023
@xunilrj xunilrj self-assigned this Oct 25, 2023
IGI-111 pushed a commit that referenced this issue Oct 31, 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

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants