Skip to content

segment fault when compiling nqueen.c #11

@choleraehyq

Description

@choleraehyq

macOS High Sierra 10.13.6

➜  9cc git:(master) ✗ cc --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
➜  9cc git:(master) ✗ ./9cc examples/nqueen.c
[1]    60186 segmentation fault  ./9cc examples/nqueen.c
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xc)
    frame #0: 0x000000010000c4b4 9cc`vec_push(v=0x0000000000000000, elem=0x0000000100207150) at util.c:29
  * frame #1: 0x00000001000052bc 9cc`add_lvar(ty=0x0000000100207110, name="board") at parse.c:81
    frame #2: 0x0000000100007f29 9cc`param_declaration at parse.c:717
    frame #3: 0x0000000100004eff 9cc`toplevel at parse.c:895
    frame #4: 0x0000000100004d79 9cc`parse(tokens_=0x0000000100206880) at parse.c:961
    frame #5: 0x00000001000049ba 9cc`main(argc=2, argv=0x00007ffeefbff858) at main.c:34
    frame #6: 0x00007fff6badf015 libdyld.dylib`start + 1
    frame #7: 0x00007fff6badf015 libdyld.dylib`start + 1

Seems because lvars is initialized at parse.c#L901, but used in param_declaration at parse.c#L895.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions