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]: Crash on invalid snippet upon using the member access operator #1579

Closed
isuckatcs opened this issue Dec 30, 2023 · 2 comments
Closed
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-lang Tag for all issues related to language.

Comments

@isuckatcs
Copy link
Contributor

isuckatcs commented Dec 30, 2023

Bug description

The following invalid snippet hits an assertion during parsing/sema. The crash only happens if the member access operator (a.x) is present.

@register_passable
struct S:
    var x: Int

    fn __init__() -> S:
        let a = Self
        a.x = 0
mojo: /__w/modular/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = M::KGEN::DeclRefType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo repro.mojo
1.      Crash resolving decl body at loc(".../repro.mojo":5:5)
    >>     fn __init__() -> S:
           ^.......................
    >>         let a = Self
    >>         a.x = 0
       ...............<
2.      Crash parsing statement at loc(".../repro.mojo":7:9)
    >>         a.x = 0
               ^......<

Steps to reproduce

  • run the snippet in the description with mojo

System information

- Ubuntu 22.04.3 LTS (WSL 2)
- mojo 0.6.1 (876ded2e)
- modular 0.3.1 (589ce200)
@isuckatcs isuckatcs added bug Something isn't working mojo Issues that are related to mojo labels Dec 30, 2023
@junweizeng
Copy link
Contributor

junweizeng commented Dec 30, 2023

The original code snippet seems unable to reproduce the error. Following is the corrected code snippet.

@register_passable
struct S:
    var x: Int

    fn __init__() -> S:
        let a = Self
        a.x = 0

Steps to reproduce and complete crash report is as follows:

$ mojo build test.mojo
mojo: /__w/modular/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = M::KGEN::DeclRefType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
[6055:6055:20231230,234755.738277:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[6055:6055:20231230,234755.738352:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo test.mojo
1.      Crash resolving decl body at loc("/path/to/test.mojo":5:5)
    >>     fn __init__() -> S:
           ^..................
    >>         let a = Self
    >>         a.x = 0
       ...............<
2.      Crash parsing statement at loc("/path/to/test.mojo":7:9)
    >>         a.x = 0
               ^......<
 #0 0x000055c0350feee7 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x60fee7)
 #1 0x000055c0350fcabe (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x60dabe)
 #2 0x000055c0350ff5bf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x6105bf)
 #3 0x00007fe7a6d44520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fe7a6d989fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007fe7a6d44476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fe7a6d2a7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fe7a6d2a71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007fe7a6d3be96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000055c03679cdf3 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x1caddf3)
#10 0x000055c0355a489a (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xab589a)
#11 0x000055c0355a4114 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xab5114)
#12 0x000055c0355a6013 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xab7013)
#13 0x000055c03558e3ee (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa9f3ee)
#14 0x000055c03558e10f (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa9f10f)
#15 0x000055c035591f9e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaa2f9e)
#16 0x000055c0355901bb (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaa11bb)
#17 0x000055c0355e4eff (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaf5eff)
#18 0x000055c0355e60b8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaf70b8)
#19 0x000055c0355f4b97 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xb05b97)
#20 0x000055c0355f42bb (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xb052bb)
#21 0x000055c0355a0c3a (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xab1c3a)
#22 0x000055c0355b0a1d (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xac1a1d)
#23 0x000055c0355b1a51 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xac2a51)
#24 0x000055c0355992d9 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaaa2d9)
#25 0x000055c0355cf2bc (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xae02bc)
#26 0x000055c0355cc0d8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xadd0d8)
#27 0x000055c0355cbf76 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xadcf76)
#28 0x000055c03556b7c9 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa7c7c9)
#29 0x000055c035585bce (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa96bce)
#30 0x000055c0355863d8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa973d8)
#31 0x000055c03552c7f4 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa3d7f4)
#32 0x000055c03552cb60 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa3db60)
#33 0x000055c0350c77bf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d87bf)
#34 0x000055c0350b3c6b (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5c4c6b)
#35 0x000055c0350c68c9 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d78c9)
#36 0x000055c0350ad352 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5be352)
#37 0x00007fe7a6d2bd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x00007fe7a6d2be40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x000055c0350ac92e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5bd92e)
Aborted

System information

Ubuntu 22.04.3 LTS (WSL 2)

mojo 0.6.1 (876ded2e)

modular 0.3.1 (589ce200)

@ematejska
Copy link
Collaborator

Thank you for the nice reproducer!

@ematejska ematejska added the mojo-lang Tag for all issues related to language. label Jan 3, 2024
@Mogball Mogball closed this as completed Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-lang Tag for all issues related to language.
Projects
None yet
Development

No branches or pull requests

3 participants