{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/3133","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/3133/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/3133/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/3133/events","html_url":"https://github.com/nim-lang/Nim/issues/3133","id":95762572,"number":3133,"title":"Crash when echoing integers","user":{"login":"tn0502","id":4123478,"avatar_url":"https://avatars.githubusercontent.com/u/4123478?v=3","gravatar_id":"","url":"https://api.github.com/users/tn0502","html_url":"https://github.com/tn0502","followers_url":"https://api.github.com/users/tn0502/followers","following_url":"https://api.github.com/users/tn0502/following{/other_user}","gists_url":"https://api.github.com/users/tn0502/gists{/gist_id}","starred_url":"https://api.github.com/users/tn0502/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tn0502/subscriptions","organizations_url":"https://api.github.com/users/tn0502/orgs","repos_url":"https://api.github.com/users/tn0502/repos","events_url":"https://api.github.com/users/tn0502/events{/privacy}","received_events_url":"https://api.github.com/users/tn0502/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-17T23:17:19Z","updated_at":"2015-07-17T23:41:59Z","closed_at":null,"body":"I'm just playing around with calling Nim code from C++ when I got this:\r\n\r\n```\r\n* thread #1: tid = 0x32e943, 0x0000000100005bbe a.out`markstackandregisters_71040(Tgcheap48616&) + 622, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7fff5fc84000)\r\n    frame #0: 0x0000000100005bbe a.out`markstackandregisters_71040(Tgcheap48616&) + 622\r\na.out`markstackandregisters_71040(Tgcheap48616&):\r\n->  0x100005bbe <+622>: movq   0x30(%rax), %rsi\r\n    0x100005bc2 <+626>: callq  0x100005cf0               ; gcmark_69446(Tgcheap48616&, void*)\r\n    0x100005bc7 <+631>: leaq   0x17bc8(%rip), %rax       ; \"gc.nim\"\r\n    0x100005bce <+638>: movq   $0x3a6, -0xc0(%rbp)\r\n(lldb) bt\r\n* thread #1: tid = 0x32e943, 0x0000000100005bbe a.out`markstackandregisters_71040(Tgcheap48616&) + 622, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7fff5fc84000)\r\n  * frame #0: 0x0000000100005bbe a.out`markstackandregisters_71040(Tgcheap48616&) + 622\r\n    frame #1: 0x0000000100009841 a.out`collectctbody_73421(Tgcheap48616&) + 225\r\n    frame #2: 0x0000000100009db2 a.out`collectct_50610(Tgcheap48616&) + 498\r\n    frame #3: 0x0000000100009e28 a.out`rawnewobj_56404(TNimType*, long long, Tgcheap48616&) + 104\r\n    frame #4: 0x000000010000af2f a.out`newObj(TNimType*, long long) + 111\r\n    frame #5: 0x000000010000afce a.out`rawNewString(long long) + 94\r\n    frame #6: 0x000000010000b00d a.out`mnewString(long long) + 29\r\n    frame #7: 0x000000010000b113 a.out`nimIntToStr(long long) + 35\r\n    frame #8: 0x000000010001d251 a.out`hello() + 129\r\n    frame #9: 0x00000001000011c4 a.out`main + 20\r\n    frame #10: 0x00007fff86a015c9 libdyld.dylib`start + 1\r\n```\r\n\r\nThe code that causes this crash (both on 0.11.2 and latest `devel`)\r\n\r\n```\r\n$ cat main.cpp\r\n#include \"nimcache/main.h\"\r\n\r\nint main()\r\n{\r\n    hello();\r\n    return 0;\r\n}\r\n```\r\n\r\n```\r\n$ cat main.nim\r\nproc hello() {.exportc.} =\r\n  const greeting = \"Greetings from Nim\"\r\n  let x = 1\r\n  let y = 1\r\n  echo(greeting, x, y)\r\n```\r\n\r\nCompiled with:\r\n\r\n```\r\n$ nim cpp --app:staticlib --header --noMain main.nim\r\n$ clang++ -std=c++11 -w main.cpp libmain.nim.a\r\n```\r\n\r\nI'm a newb so I don't know if this is a misunderstanding on my part or if I've found a legitimate bug. This is on Mac OS X 10.10.4 with Clang version:\r\n\r\n```\r\n$ clang --version\r\nApple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)\r\nTarget: x86_64-apple-darwin14.4.0\r\nThread model: posix\r\n```"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/122452863","html_url":"https://github.com/nim-lang/Nim/issues/3133#issuecomment-122452863","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/3133","id":122452863,"user":{"login":"tn0502","id":4123478,"avatar_url":"https://avatars.githubusercontent.com/u/4123478?v=3","gravatar_id":"","url":"https://api.github.com/users/tn0502","html_url":"https://github.com/tn0502","followers_url":"https://api.github.com/users/tn0502/followers","following_url":"https://api.github.com/users/tn0502/following{/other_user}","gists_url":"https://api.github.com/users/tn0502/gists{/gist_id}","starred_url":"https://api.github.com/users/tn0502/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tn0502/subscriptions","organizations_url":"https://api.github.com/users/tn0502/orgs","repos_url":"https://api.github.com/users/tn0502/repos","events_url":"https://api.github.com/users/tn0502/events{/privacy}","received_events_url":"https://api.github.com/users/tn0502/received_events","type":"User","site_admin":false},"created_at":"2015-07-17T23:41:59Z","updated_at":"2015-07-17T23:41:59Z","body":"I got a different stack:\r\n\r\n```\r\n* thread #1: tid = 0x33120b, 0x0000000100002607 a.out`issmallchunk_30508(Tbasechunk27838*) + 87, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffff008)\r\n    frame #0: 0x0000000100002607 a.out`issmallchunk_30508(Tbasechunk27838*) + 87\r\na.out`issmallchunk_30508(Tbasechunk27838*):\r\n->  0x100002607 <+87>:  cmpq   $0xfc0, 0x8(%rax)\r\n    0x10000260f <+95>:  setle  %sil\r\n    0x100002613 <+99>:  andb   $0x1, %sil\r\n    0x100002617 <+103>: movb   %sil, -0x9(%rbp)\r\n(lldb) bt\r\n* thread #1: tid = 0x33120b, 0x0000000100002607 a.out`issmallchunk_30508(Tbasechunk27838*) + 87, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffff008)\r\n  * frame #0: 0x0000000100002607 a.out`issmallchunk_30508(Tbasechunk27838*) + 87\r\n    frame #1: 0x000000010000559c a.out`rawdealloc_42424(Tmemregion28610&, void*) + 124\r\n    frame #2: 0x00000001000058bb a.out`dealloc_45429(Tmemregion28610&, void*) + 123\r\n    frame #3: 0x0000000100005938 a.out`dealloc_6048(void*) + 104\r\n    frame #4: 0x0000000100008fab a.out`deinit_46888(Tcellset46760&) + 267\r\n    frame #5: 0x0000000100009118 a.out`cellsetreset_54801(Tcellset46760&) + 88\r\n    frame #6: 0x0000000100009473 a.out`collectcycles_69044(Tgcheap48616&) + 819\r\n    frame #7: 0x000000010000998e a.out`collectctbody_73421(Tgcheap48616&) + 558\r\n    frame #8: 0x0000000100009db2 a.out`collectct_50610(Tgcheap48616&) + 498\r\n    frame #9: 0x0000000100009e28 a.out`rawnewobj_56404(TNimType*, long long, Tgcheap48616&) + 104\r\n    frame #10: 0x000000010000af2f a.out`newObj(TNimType*, long long) + 111\r\n    frame #11: 0x000000010000afce a.out`rawNewString(long long) + 94\r\n    frame #12: 0x000000010000b00d a.out`mnewString(long long) + 29\r\n    frame #13: 0x000000010000b113 a.out`nimIntToStr(long long) + 35\r\n    frame #14: 0x000000010001d251 a.out`hello() + 129\r\n    frame #15: 0x00000001000011c3 a.out`main + 35\r\n    frame #16: 0x00007fff86a015c9 libdyld.dylib`start + 1\r\n```\r\n\r\nWith the following (`initStackBottomWith` was just calling `setStackBottom`):\r\n\r\n```\r\n$ cat main.cpp\r\n#include \"nimcache/main.h\"\r\n\r\nN_NOINLINE(void, setStackBottom)(void* thestackbottom);\r\n\r\nint main(void)\r\n{\r\n    setStackBottom((void*)&hello);\r\n    hello();\r\n    return 0;\r\n}\r\n```"}}