c2lang / c2compiler

the c2 programming language
c2lang.org
Apache License 2.0
704 stars 49 forks source link

Segmentation fault: 11 during generating c code #113

Closed luarockr closed 4 years ago

luarockr commented 4 years ago

getting a Segmentation fault 11 when compiling attached source (macos). The c2libcurses is a symbolic link in the c2compiler/c2libs directory curses -> /c2/c2libcurse.

c2GameOfLife.tar.gz c2libcurse.tar.gz

gdb output: (gdb) run Starting program: /Users/ceekay/Projects/c2/c2compiler/build/c2c/c2c [New Thread 0x1903 of process 1122] [New Thread 0x2703 of process 1122] warning: unhandled dyld version (16) building target GameOfLife

Thread 2 received signal SIGSEGV, Segmentation fault. 0x00000001000bc9d7 in C2::CCodeGenerator::EmitDecl(C2::Decl const*, C2::StringBuilder&) () (gdb) where

0 0x00000001000bc9d7 in C2::CCodeGenerator::EmitDecl(C2::Decl const*, C2::StringBuilder&) ()

1 0x00000001000bc125 in C2::CCodeGenerator::EmitTypePostName(C2::QualType, C2::StringBuilder&) ()

2 0x00000001000bc104 in C2::CCodeGenerator::EmitTypePostName(C2::QualType, C2::StringBuilder&) ()

3 0x00000001000bec4b in C2::CCodeGenerator::EmitDeclStmt(C2::Stmt const*, unsigned int) ()

4 0x00000001000bb382 in C2::CCodeGenerator::EmitFunction(C2::FunctionDecl const*) ()

5 0x00000001000ba45d in C2::CCodeGenerator::EmitAll() ()

6 0x00000001000b9c13 in C2::CCodeGenerator::generate(bool, std::1::basic_string<char, std::__1::char_traits, std::1::allocator > const&) ()

7 0x00000001000c27c1 in C2::CGenerator::generate() ()

8 0x00000001000cf800 in C2::C2Builder::generateOptionalC() ()

9 0x00000001000cdcb0 in C2::C2Builder::build() ()

10 0x0000000100002edf in main ()

(gdb) quit

bvdberg commented 4 years ago

I can reproduce the issue with just a small fragment. It appears multi-dimension array that are non-global (in your case copyBoard) are not correctly resolved. I'll look into it.. thx!

bvdberg commented 4 years ago

I'll have to shuffle quite some code, so that'll take some time. If you want to work around this issue for now, you can change 'i32[BSize][BSize] copyboard;' into 'i32[20][20] copyboard;'. Then it compiles and appears to work when I run it...

bvdberg commented 4 years ago

fixed