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]: mojo crash: Assertion `!failed && "we know this should always work because we lexed it"' failed. #1913

Closed
junweizeng opened this issue Mar 8, 2024 · 4 comments
Labels
bug Something isn't working mojo Issues that are related to mojo mojo-lang Tag for all issues related to language. mojo-repo Tag all issues with this label

Comments

@junweizeng
Copy link
Contributor

Bug description

mojo crashes on the following code (i.e. test.mojo).

0__init__

Steps to reproduce

$ mojo build test.mojo
/path/to/test.mojo:1:1: error: TODO: expressions are not yet supported at the file scope level
0__init__
^
mojo: /__w/modular/modular/KGEN/lib/MojoParser/Lexer.cpp:842: static llvm::APInt M::KGEN::LIT::Lexer::getIntegerLiteralValue(llvm::StringRef): Assertion `!failed && "we know this should always work because we lexed it"' 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 build test.mojo
1.      Crash resolving decl body at loc("/path/to/test.mojo":1:1)
    >> 0__init__
       ^..<     
2.      Crash parsing statement at loc("/path/to/test.mojo":1:1)
    >> 0__init__
       ^..<     
 #0 0x0000562981aace47 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62ae47)
 #1 0x0000562981aaaa1e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x628a1e)
 #2 0x0000562981aad51f (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x62b51f)
 #3 0x00007f205c275520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f205c2c9a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f205c2c9a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f205c2c9a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f205c275476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f205c25b7f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f205c25b71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f205c26ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000562981e9e8d7 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa1c8d7)
#12 0x0000562981f02e01 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa80e01)
#13 0x0000562981efd709 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa7b709)
#14 0x0000562981f331b0 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xab11b0)
#15 0x0000562981f2d558 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaab558)
#16 0x0000562981f2d406 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xaab406)
#17 0x0000562981ed1443 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa4f443)
#18 0x0000562981ee883e (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa6683e)
#19 0x0000562981ee8fc8 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa66fc8)
#20 0x0000562981e96cfb (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa14cfb)
#21 0x0000562981e97059 (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0xa15059)
#22 0x0000562981a55e0f (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d3e0f)
#23 0x0000562981a5823b (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d623b)
#24 0x0000562981a52ddf (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5d0ddf)
#25 0x0000562981a5165d (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5cf65d)
#26 0x00007f205c25cd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#27 0x00007f205c25ce40 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007f205c25ce40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#29 0x0000562981a50fae (/home/jwzeng/.modular/pkg/packages.modular.com_mojo/bin/mojo+0x5cefae)
Aborted

System information

- Ubuntu 22.04 LTS
- mojo 24.1.0 (55ec12d6)
- modular 0.5.1 (1b608e3d)
@junweizeng junweizeng added bug Something isn't working mojo Issues that are related to mojo labels Mar 8, 2024
@Brian-M-J
Copy link

we know this should always work

Welp 😆

@akirchhoff-modular
Copy link
Contributor

Even shorter crashing code: 0__

@ematejska
Copy link
Collaborator

@Mogball Dup of global stuff or no?

@ematejska ematejska added the mojo-lang Tag for all issues related to language. label Mar 18, 2024
@Mogball
Copy link
Collaborator

Mogball commented Mar 18, 2024

no

arvindavoudi pushed a commit to arvindavoudi/mojo that referenced this issue Apr 13, 2024
There was an assumption that if a literal starts with `0` and is at
least 3 characters long, it has to be because it started with `0b`,
`0x`, etc., and hence was safe to strip off 2 characters. When you do
this with `0__`, you end up with `_`, which after filtering underscores,
is an empty string, which can't be parsed as an integer, causing an
assertion error. Instead, the first two characters only if it's one of
the prefixes we expect.

Fixes modularml#1913.

modular-orig-commit: 75cce9ad8716af3f950a5e36fa855a343f65ba16
patrickdoc pushed a commit that referenced this issue May 2, 2024
There was an assumption that if a literal starts with `0` and is at
least 3 characters long, it has to be because it started with `0b`,
`0x`, etc., and hence was safe to strip off 2 characters. When you do
this with `0__`, you end up with `_`, which after filtering underscores,
is an empty string, which can't be parsed as an integer, causing an
assertion error. Instead, the first two characters only if it's one of
the prefixes we expect.

Fixes #1913.

MODULAR_ORIG_COMMIT_REV_ID: 75cce9ad8716af3f950a5e36fa855a343f65ba16
@ematejska ematejska added the mojo-repo Tag all issues with this label label May 6, 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 mojo Issues that are related to mojo mojo-lang Tag for all issues related to language. mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

5 participants