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

Ampersand operator in for in loop causes a compiler crash #2161

Closed
kleeon opened this issue Oct 30, 2022 · 15 comments
Closed

Ampersand operator in for in loop causes a compiler crash #2161

kleeon opened this issue Oct 30, 2022 · 15 comments
Labels
replicated We were able to replicate the bug. triaged Bug has been looked at.

Comments

@kleeon
Copy link
Contributor

kleeon commented Oct 30, 2022

Version

λ odin version
odin version dev-2022-10:2cd895c5

OS: Windows 10

Context

I was just experimenting with syntax of the language and encountered this bug.

package main

main :: proc() {
  a := []byte{1, 2, 3}

  for &v in a {

  }
}

This code crashes the compiler for me.

@kleeon kleeon changed the title Dereference operator in for in loop causes a compiler crash Ampersand operator in for in loop causes a compiler crash Oct 30, 2022
@kleeon
Copy link
Contributor Author

kleeon commented Oct 30, 2022

Actually it seems like any unary operator causes a crash:

for ^v in a
for v^ in a
for -v in a
for ~v in a

@Kelimion
Copy link
Member

I cannot replicate this on the current Odin commit, also on Windows 10:

package main

main :: proc() {
  a := []byte{1, 2, 3}

  for &v in a {
  }

}

W:/Odin-other/Odin-test/foozle/foozle.odin(6:7) A variable declaration must be an identifier

@Kelimion
Copy link
Member

Kelimion commented Oct 30, 2022

for ^v in a
for v^ in a
for -v in a
for ~v in a

Every single one of these also give me the expected syntax error: A variable declaration must be an identifier.

@Kelimion Kelimion added cannot-replicate Unable to Replicate triaged Bug has been looked at. labels Oct 30, 2022
@kleeon
Copy link
Contributor Author

kleeon commented Oct 30, 2022

@Kelimion that's odd, it definitely crashes for me. According to JIT debugger, the crash occurs on this line:

GB_ASSERT(identifier->kind == Ast_Ident);

It also does display that syntax error before crashing.

Should I close the issue then?

@Kelimion
Copy link
Member

@Kelimion that's odd, it definitely crashes for me. According to JIT debugger, the crash occurs on this line:

GB_ASSERT(identifier->kind == Ast_Ident);

It also does display that syntax error before crashing.

Should I close the issue then?

Maybe someone else can replicate it, @kleeon. Leave it open for a bit.

2cd895c is the latest commit, but did you compile this yourself or is this from a downloaded nightly? If the former, can you tell us what version of Visual Studio and the SDK this was compiled against?

@kleeon
Copy link
Contributor Author

kleeon commented Oct 30, 2022

I compiled it myself by running build.bat script on the latest commit. I'm using Visual Studio 2019 and SDK 10.0.19041.0

@Kelimion
Copy link
Member

I'm on VS 2019 with 10.0.20348.0, but that shouldn't make a difference here. Very curious.

@jrfondren
Copy link
Contributor

The example segfaults odin for me, after A variable declaration must be an identifier:

        Odin: dev-2022-10:2cd895c5
        OS:   Manjaro Linux, Linux 5.10.148-1-MANJARO
        CPU:  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
        RAM:  15953 MiB

@Kelimion Kelimion added replicated We were able to replicate the bug. and removed cannot-replicate Unable to Replicate labels Oct 30, 2022
@Kelimion
Copy link
Member

The example segfaults odin for me, after A variable declaration must be an identifier:

        Odin: dev-2022-10:2cd895c5
        OS:   Manjaro Linux, Linux 5.10.148-1-MANJARO
        CPU:  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
        RAM:  15953 MiB

Cheers. Changed the bug to replicated.

@gingerBill
Copy link
Member

Can someone give me a stack trace as to how to replicate this?

gingerBill added a commit that referenced this issue Nov 1, 2022
@kleeon
Copy link
Contributor Author

kleeon commented Nov 1, 2022

Can someone give me a stack trace as to how to replicate this?

I ran it on a different Windows 10 PC and it still crashes. Here is the stack trace:

>	odin.exe!add_entity_and_decl_info(CheckerContext * c=0x000000e9d54fe650, Ast * identifier=0x0000000000000000, Entity * e=0x000001f1cf888010, DeclInfo * d=0x000001f1cf888190, bool is_exported=true) Строка 1676	
 	odin.exe!check_stmt_internal(CheckerContext * ctx=0x000000e9d54fe650, Ast * node=0x000001f1c6e2fc50, unsigned int flags=32) Строка 1993	
 	odin.exe!check_stmt(CheckerContext * ctx=0x000000e9d54fe650, Ast * node=0x000001f1c6e2fc50, unsigned int flags=32) Строка 509	
 	odin.exe!check_stmt_list(CheckerContext * ctx=0x000000e9d54fe650, const Slice<Ast *> & stmts={...}, unsigned int flags=32) Строка 107	
 	odin.exe!check_proc_body(CheckerContext * ctx_=0x000000e9d54fe7d0, Token token={...}, DeclInfo * decl=0x000001f1c9eb6880, Type * type=0x000001f1ca3f0390, Ast * body=0x000001f1c6e2fd70) Строка 1549	
 	odin.exe!check_proc_info(Checker * c=0x000001f1c35857d0, ProcInfo * pi=0x000001f1ca3f04c0, PtrMap<Ast *,ExprInfo *> * untyped=0x000000e9d54fecd0, MPMCQueue<ProcInfo *> * procs_to_check_queue=0x000001f1c3586090) Строка 5174	
 	odin.exe!consume_proc_info_queue(Checker * c=0x000001f1c35857d0, ProcInfo * pi=0x000001f1ca3f04c0, MPMCQueue<ProcInfo *> * q=0x000001f1c3586090, PtrMap<Ast *,ExprInfo *> * untyped=0x000000e9d54fecd0) Строка 5288	
 	odin.exe!check_procedure_bodies(Checker * c=0x000001f1c35857d0) Строка 5337	
 	odin.exe!check_parsed_files(Checker * c=0x000001f1c35857d0) Строка 5727	
 	odin.exe!main(int arg_count=3, const char * * arg_ptr=0x000001f1c16f6680) Строка 2794	

@gingerBill
Copy link
Member

@kleeon on the latest commit with the new "fix" 411c0ad

@kleeon
Copy link
Contributor Author

kleeon commented Nov 1, 2022

@kleeon on the latest commit with the new "fix" 411c0ad

@gingerBill On the latest commit it crashes with assertion failure:

λ odin build .
C:/projects/odin/crash/main.odin(6:7) A variable declaration must be an identifier
C:\Program Files\Odin\src\checker.cpp(1676): Assertion Failure: `identifier != nullptr`

@gingerBill
Copy link
Member

I cannot replicate it on my end but I think I understand the problem now, @kleeon. An error has happened but it is trying to proceed as if there wasn't an error.

@kleeon
Copy link
Contributor Author

kleeon commented Nov 1, 2022

@gingerBill thank you, c18e98e fixed it for me:

λ odin build .
C:/projects/odin/crash/main.odin(6:7) A variable declaration must be an identifier

I think I can close the issue now.

@kleeon kleeon closed this as completed Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
replicated We were able to replicate the bug. triaged Bug has been looked at.
Projects
None yet
Development

No branches or pull requests

4 participants