Open junweizeng opened 8 months ago
Here's another test case that seems to trigger the same bug.
Steps to reproduce
$ cat test.mojo
fn a() : if 2 : struct b
$
$ mojo build test.mojo
/path/to/test.mojo:1:10: error: 'if' statement must be on its own line
fn a() : if 2 : struct b
^
/path/to/test.mojo:1:17: error: 'struct' statement must be on its own line
fn a() : if 2 : struct b
^
/path/to/test.mojo:1:17: error: struct inside a function not supported here
fn a() : if 2 : struct b
^
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:4)
>> fn a() : if 2 : struct b
^....................
>>
<
2. Crash parsing statement at loc("/path/to/test.mojo":1:10)
>> fn a() : if 2 : struct b
^..............
>>
<
3. Crash parsing statement at loc("/path/to/test.mojo":1:17)
>> fn a() : if 2 : struct b
^.......
>>
<
#0 0x000055a62ce92347 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x128d347)
#1 0x000055a62ce9019e llvm::sys::RunSignalHandlers() (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x128b19e)
#2 0x000055a62ce929df SignalHandler(int) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x128d9df)
#3 0x00007f797cd9f520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000055a62d22fabf M::KGEN::LIT::ASTDecl::getContext() const (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x162aabf)
#5 0x000055a62d2651c8 M::KGEN::LIT::DeclResolver::addErroneousDecl(llvm::StringRef, llvm::SMLoc, M::KGEN::LIT::ASTDecl*) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16601c8)
#6 0x000055a62d2bd764 (anonymous namespace)::StmtParser::parseSuite(long)::$_7::operator()(bool, unsigned long) const (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16b8764)
#7 0x000055a62d2b83d7 (anonymous namespace)::StmtParser::parseSuite(long) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16b33d7)
#8 0x000055a62d2bdccf (anonymous namespace)::StmtParser::parseSuite(long)::$_7::operator()(bool, unsigned long) const (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16b8ccf)
#9 0x000055a62d2b83d7 (anonymous namespace)::StmtParser::parseSuite(long) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16b33d7)
#10 0x000055a62d2b8106 M::KGEN::LIT::ParserBase::parseSuite(M::KGEN::LIT::ASTDecl&) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16b3106)
#11 0x000055a62d255677 M::KGEN::LIT::DeclResolver::resolveBody(M::KGEN::LIT::FuncOp, M::KGEN::LIT::Lexer&, M::KGEN::LIT::ASTDecl&) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x1650677)
#12 0x000055a62d2670bf M::KGEN::LIT::DeclResolver::resolve(M::KGEN::LIT::ASTDecl&, M::KGEN::LIT::DeclResolvedness, llvm::SMLoc) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x16620bf)
#13 0x000055a62d26755d M::KGEN::LIT::DeclResolver::resolveAllReferencedFrom(M::KGEN::LIT::ASTDecl&, bool) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x166255d)
#14 0x000055a62d26fcc6 importMojoImpl(M::LLCL::Runtime&, llvm::StringRef, llvm::SourceMgr&, M::KGEN::LIT::SharedState&, mlir::TimingScope&, llvm::SmallVectorImpl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, llvm::function_ref<M::KGEN::LIT::ASTDecl& (mlir::ModuleOp)>) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x166acc6)
#15 0x000055a62d27012d M::KGEN::LIT::importMojoFile(M::LLCL::Runtime&, llvm::SourceMgr&, M::KGEN::LIT::ParserConfig&, mlir::TimingScope&, llvm::SmallVectorImpl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x166b12d)
#16 0x000055a62cdc513c mlir::OwningOpRef<mlir::ModuleOp> llvm::function_ref<mlir::OwningOpRef<mlir::ModuleOp> (M::KGEN::LIT::ParserConfig&, mlir::TimingScope&)>::callback_fn<build(M::State const&)::$_0>(long, M::KGEN::LIT::ParserConfig&, mlir::TimingScope&) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x11c013c)
#17 0x000055a62cdc68f4 M::invokeMojoParser(M::State const&, llvm::opt::InputArgList const&, M::KGEN::CompilationOptions&, mlir::MLIRContext*, M::LLCL::Runtime&, llvm::opt::OptSpecifier, llvm::opt::OptSpecifier, llvm::opt::OptSpecifier, llvm::function_ref<mlir::OwningOpRef<mlir::ModuleOp> (M::KGEN::LIT::ParserConfig&, mlir::TimingScope&)>) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x11c18f4)
#18 0x000055a62cdc2c29 build(M::State const&) (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x11bdc29)
#19 0x000055a62cdc15ec main (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x11bc5ec)
#20 0x00007f797cd86d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#21 0x00007f797cd86e40 call_init ./csu/../csu/libc-start.c:128:20
#22 0x00007f797cd86e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#23 0x000055a62cdc0fae _start (/home/jwzeng/.modular/pkg/packages.modular.com_nightly_mojo/bin/mojo+0x11bbfae)
mojo crashed!
Please file a bug report.
Segmentation fault
System information
$ lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy
$ mojo -v
mojo 2024.4.2923 (f54d89e3)
$ modular -v
modular 0.7.2 (d0adc668)
The first example doesn't seem to reproduce the crash anymore, but the second example does (I ran them on the Mojo playground as of 5th July 2024).
Bug description
mojo crashes on the following code (i.e. test.mojo).
Steps to reproduce
System information