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

segment fault when compiling nqueen.c #11

Open
choleraehyq opened this issue Sep 3, 2018 · 1 comment
Open

segment fault when compiling nqueen.c #11

choleraehyq opened this issue Sep 3, 2018 · 1 comment

Comments

@choleraehyq
Copy link

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.

@RadioGu
Copy link

RadioGu commented Apr 29, 2019

I got the same question,i tried your solution,but i cant get the right tmp-nqueen.s ,it has the segment fault...So after fix this question by your way, did you have the right tmp-nqueen.s? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants