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

Certain code with if statement leads to an ICE #749

Closed
cburgdorf opened this issue Jun 22, 2022 · 0 comments · Fixed by #750
Closed

Certain code with if statement leads to an ICE #749

cburgdorf opened this issue Jun 22, 2022 · 0 comments · Fixed by #750

Comments

@cburgdorf
Copy link
Collaborator

cburgdorf commented Jun 22, 2022

What is wrong?

The following leads to an ICE

contract Bar {

    something: bool

    pub fn move_field(self) {
        if true {
            if self.something { 
                return 
            }
        }
        if true {
            if self.something { 
                return 
            }
        }
    }
}

ICE:

Error: DeclarationError: Variable not found or variable not lvalue.
  --> input.yul:33:17:
   |
33 |                 $$tmp_5 := and($$sptr_load(add(0, 0), 8), 0xff)
   |                 ^^^^^^^


Error: DeclarationError: Identifier "$$tmp_5" not found.
  --> input.yul:34:24:
   |
34 |                 switch $$tmp_5
   |                        ^^^^^^^

Looking at the relevant YUL we can see that the second $$tmp_5 is used but not declared. Or maybe the initial declaration of $$tmp_5 should have been made one block higher 🤔 I haven't really analyzed it yet.

switch 1
case 1 {
    let $$tmp_3
    $$tmp_3: = and($$sptr_load(add(0, 0), 8), 0xff)
    switch $$tmp_3
    case 1 {
        leave
    }
    case 0 {
        switch 1
        case 1 {
            let $$tmp_5
            $$tmp_5: = and($$sptr_load(add(0, 0), 8), 0xff)
            switch $$tmp_5
            case 1 {
                leave
            }
            case 0 {
                leave
            }
        }
        case 0 {
            leave
        }
    }
}
case 0 {
    switch 1
    case 1 {
        $$tmp_5: = and($$sptr_load(add(0, 0), 8), 0xff)
        switch $$tmp_5
        case 1 {
            leave
        }
        case 0 {
            leave
        }
    }
    case 0 {
        leave
    }
}
}

It's as minimal as I could get it:

The following alternations would make the ICE go away:

  • removing the return
  • unnesting
  • removing the second (duplicated) if block
  • using a local condition instead of self.something

How can it be fixed

🔪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant