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

[BUG] While loop logic causes seg fault. #2696

Open
johnsoez4 opened this issue May 17, 2024 · 6 comments
Open

[BUG] While loop logic causes seg fault. #2696

johnsoez4 opened this issue May 17, 2024 · 6 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@johnsoez4
Copy link

johnsoez4 commented May 17, 2024

Bug description

This issue started a few days ago with Mojo nightly version 2024.5.1002.
Edit 2024-05-28:

  • mojo 2024.5.822 (2cfed0ad) = OK
  • mojo 2024.5.1002 (83c7e1be) = KO (issues started)

In the code shown below, function app_run causes a seg fault, but app_close alone compiles and works properly. The logic to exit each while loop is essentially identical but inverted. I presume that both functions should compile and work properly.
Important: I just confirmed that this issue does NOT exist with Mojo stable version 24.3.0 (9882e19d).
stack_dump.txt

Steps to reproduce

fn main() raises:
    app_close()
    app_run()


fn app_close():
    # This compiles and works.
    var app_close = False
    var loops = 10
    while not app_close:
        loops -= 1
        if loops == 0:
            app_close = True
    print("app_close: Success!")


fn app_run():
    # This does not compile (seg fault).
    var app_run = True
    var loops = 10
    while app_run:
        loops -= 1
        if loops == 0:
            app_run = False
    print("app_run: Success!")
    ```
 
### System information
 
```shell
Ubuntu: 24.04 LTS
Python: 3.12.3
Mojo Nightly: 2024.5.1619 (bd52708e)
Modular: 0.7.4 (df7a9e8b)
@johnsoez4 johnsoez4 added bug Something isn't working mojo-repo Tag all issues with this label labels May 17, 2024
@johnsoez4
Copy link
Author

johnsoez4 commented May 19, 2024

No problem (confirmed OK on 2024-05-28)

  • mojo 2024.5.822 (2cfed0ad) OK

Problem confirmed:

  • mojo 2024.5.1002 (83c7e1be)
  • mojo 2024.5.1805 (341542be)
  • mojo 2024.5.1905 (46b7e7ee)
  • mojo 2024.5.2012 (fb60fe4f)
  • mojo 2024.5.2119 (79ef45f6)
  • mojo 2024.5.2205 (d3cacc7e)
  • mojo 2024.5.2305 (1e5d508e)
  • mojo 2024.5.2414 (39359abc)
  • mojo 2024.5.2605 (9c328b12)
  • mojo 2024.5.2805 (87564503)
  • mojo 2024.5.2912 (6861a424)
  • mojo 2024.5.3005 (0c465b6a)
  • mojo 2024.5.3112 (e60dc71f)
  • mojo 2024.6.105 (3cf18231)

@JoeLoser
Copy link
Collaborator

@johnsoez4
Copy link
Author

johnsoez4 commented May 28, 2024

@ematejska, @JoeLoser , @mzaks, @jopamer, @rd4com, @jdiggins

Here's an interesting clue to the mystery. It works when the line while app_run: is changed to while not not app_run:.

fn app_run():
    # This does not compile (seg fault).
    var app_run = True
    var loops = 10

    while not not app_run:  # This works.
    # while app_run:  # This does not work.
        loops -= 1
        if loops == 0:
            app_run = False
    print("app_run: Success!")
    ```

Copy link
Collaborator

JoeLoser commented May 28, 2024

This is a compiler bug from one of our passes. It's hitting an assertion in our compiler stack inside LLVM:

Assertion failed: (detail::isPresent(Val) && "dyn_cast on a non-existent value"), function dyn_cast, file Casting.h, line 662.FYI  

FYI @jeff

@ematejska
Copy link
Collaborator

Thanks for filing! We'll take a look.

@ematejska
Copy link
Collaborator

Duplicate filed here: #2821

Reduced use-case from there:

fn main():
    var loop = True
    while loop:
        loop=False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants