{"action":"created","issue":{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/112","labels_url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/112/comments","events_url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/112/events","html_url":"https://github.com/LuaJIT/LuaJIT/issues/112","id":119082364,"number":112,"title":"Crash with union containing 64bit integer","user":{"login":"stepelu","id":6617696,"avatar_url":"https://avatars.githubusercontent.com/u/6617696?v=3","gravatar_id":"","url":"https://api.github.com/users/stepelu","html_url":"https://github.com/stepelu","followers_url":"https://api.github.com/users/stepelu/followers","following_url":"https://api.github.com/users/stepelu/following{/other_user}","gists_url":"https://api.github.com/users/stepelu/gists{/gist_id}","starred_url":"https://api.github.com/users/stepelu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stepelu/subscriptions","organizations_url":"https://api.github.com/users/stepelu/orgs","repos_url":"https://api.github.com/users/stepelu/repos","events_url":"https://api.github.com/users/stepelu/events{/privacy}","received_events_url":"https://api.github.com/users/stepelu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/labels/2.0","name":"2.0","color":"fef2c0"},{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/labels/2.1","name":"2.1","color":"fbca04"},{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/labels/x86","name":"x86","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-26T17:20:58Z","updated_at":"2015-11-26T19:28:53Z","closed_at":null,"body":"The following code should never complete (the break condition in the `while true do...` loop is never true), but often it result in a crash following the first print statement (i.e. the second print statement is never executed).\r\n\r\nTested on LuaJIT 2.1 HEAD, the issue appears on Windows x86, I don't seem to be able to replicate it on Windows x64.\r\n\r\n```\r\nlocal ffi  = require \"ffi\"\r\n\r\nlocal d_ct = ffi.typeof(\"struct { int64_t _ticks; }\")\r\n\r\nffi.cdef[[\r\ntypedef unsigned long    DWORD;\r\ntypedef unsigned __int64 ULONGLONG;\r\n\r\ntypedef union _ULARGE_INTEGER {\r\n  struct {\r\n    DWORD LowPart;\r\n    DWORD HighPart;\r\n  };\r\n  struct {\r\n    DWORD LowPart;\r\n    DWORD HighPart;\r\n  } u;\r\n  ULONGLONG QuadPart;\r\n} ULARGE_INTEGER, *PULARGE_INTEGER;\r\n]]\r\n\r\nlocal ul = ffi.new(\"ULARGE_INTEGER\")\r\n\r\nlocal nowutc = function()\r\n   return ffi.new(d_ct, ul.QuadPart)\r\nend\r\n\r\nlocal start, finish = nowutc()\r\nfor i=1,1e7 do\r\n  finish = nowutc()\r\nend\r\nprint(tostring(finish))\r\n\r\nlocal start, finish = nowutc()\r\nwhile true do\r\n  finish = nowutc()\r\n  if start._ticks ~= finish._ticks then break end\r\nend\r\nprint(tostring(finish))\r\n```\r\n\r\nIn case it helps, I attach the following IR info (code above saved as time2.lua):\r\n\r\n```\r\nluajit -jdump=+rsx time2.lua\r\n---- TRACE 37 start time2.lua:29\r\n0020  MOV     10   3\r\n0021  CALL    10   2   1\r\n0000  . FUNCF    3          ; time2.lua:24\r\n0001  . UGET     0   0      ; ffi\r\n0002  . TGETS    0   0   0  ; \"new\"\r\n0003  . UGET     1   1      ; d_ct\r\n0004  . UGET     2   2      ; ul\r\n0005  . TGETS    2   2   1  ; \"QuadPart\"\r\n0000  . . . FUNCC               ; ffi.meta.__index\r\n0006  . CALLT    0   3\r\n0000  . FUNCC               ; ffi.new\r\n0022  MOV      5  10\r\n0023  FORL     6 => 0020\r\n---- TRACE 37 IR\r\n....              SNAP   #0   [ ---- ]\r\n0001 edi      int SLOAD  #7    CI\r\n0002       >  fun SLOAD  #4    T\r\n0003       >  fun EQ     0002  time2.lua:24\r\n0004 ebx   >  tab SLOAD  #1    T\r\n0005          int FLOAD  0004  tab.hmask\r\n0006       >  int EQ     0005  +31\r\n0007 edx      p32 FLOAD  0004  tab.node\r\n0008       >  p32 HREFK  0007  \"new\" @3\r\n0009       >  fun HLOAD  0008\r\n0010 eax      int XLOAD  [0x004348f0]\r\n0011 ecx      int XLOAD  [0x004348f4]\r\n0013       >  fun EQ     0009  ffi.new\r\n0014  {sink}+ cdt CNEW   +96\r\n0015          p32 ADD    0014  +8\r\n0016  {0014}  int XSTORE 0015  0010\r\n0017          int HIOP   0015  0011\r\n0018 edi    + int ADD    0001  +1\r\n....              SNAP   #1   [ ---- ---- ---- ---- ---- ---- 0014 ]\r\n0019       >  int LE     0018  +10000000\r\n....              SNAP   #2   [ ---- ---- ---- ---- ---- ---- 0014 0018 ---- ---- 0018 ]\r\n0020 ------------ LOOP ------------\r\n0021  {sink}+ cdt CNEW   +96\r\n0022          p32 ADD    0021  +8\r\n0023  {0021}  int XSTORE 0022  0010\r\n0024          int HIOP   0022  0011\r\n0025 edi    + int ADD    0018  +1\r\n....              SNAP   #3   [ ---- ---- ---- ---- ---- ---- 0021 ]\r\n0026       >  int LE     0025  +10000000\r\n0027 edi      int PHI    0018  0025\r\n0028  {sink}  cdt PHI    0014  0021\r\n---- TRACE 37 mcode 148\r\n7efacc8c  mov dword [0x002a023c], 0x25\r\n7efacc96  cvttsd2si edi, [edx+0x30]\r\n7efacc9b  cmp dword [edx+0x1c], -0x09\r\n7efacc9f  jnz 0x7efa0008        ->0\r\n7efacca5  cmp dword [edx+0x18], 0x004355f8\r\n7efaccac  jnz 0x7efa0008        ->0\r\n7efaccb2  cmp dword [edx+0x4], -0x0c\r\n7efaccb6  jnz 0x7efa0008        ->0\r\n7efaccbc  mov ebx, [edx]\r\n7efaccbe  cmp dword [ebx+0x1c], +0x1f\r\n7efaccc2  jnz 0x7efa0008        ->0\r\n7efaccc8  mov edx, [ebx+0x14]\r\n7efacccb  cmp dword [edx+0x54], -0x05\r\n7efacccf  jnz 0x7efaccd8\r\n7efaccd1  cmp dword [edx+0x50], 0x002ab288\r\n7efaccd8  jnz 0x7efa0008        ->0\r\n7efaccde  cmp dword [edx+0x4c], -0x09\r\n7efacce2  jnz 0x7efa0008        ->0\r\n7efacce8  mov eax, [0x004348f0]\r\n7efaccee  mov ecx, [0x004348f4]\r\n7efaccf4  cmp dword [edx+0x48], 0x002afe68\r\n7efaccfb  jnz 0x7efa0008        ->0\r\n7efacd01  add edi, +0x01\r\n7efacd04  cmp edi, 0x00989680\r\n7efacd0a  jg 0x7efa000c ->1\r\n->LOOP:\r\n7efacd10  add edi, +0x01\r\n7efacd13  cmp edi, 0x00989680\r\n7efacd19  jle 0x7efacd10        ->LOOP\r\n7efacd1b  jmp 0x7efa0014        ->3\r\n---- TRACE 37 stop -> loop\r\n\r\n---- TRACE 37 exit 3\r\ncdata<struct 96>: 0x00413480\r\n---- TRACE 38 start time2.lua:35\r\n0032  MOV      8   3\r\n0033  CALL     8   2   1\r\n0000  . FUNCF    3          ; time2.lua:24\r\n0001  . UGET     0   0      ; ffi\r\n0002  . TGETS    0   0   0  ; \"new\"\r\n0003  . UGET     1   1      ; d_ct\r\n0004  . UGET     2   2      ; ul\r\n0005  . TGETS    2   2   1  ; \"QuadPart\"\r\n0000  . . . FUNCC               ; ffi.meta.__index\r\n0006  . CALLT    0   3\r\n0000  . FUNCC               ; ffi.new\r\n0034  MOV      7   8\r\n0035  TGETS    8   6  11  ; \"_ticks\"\r\n0000  . . FUNCC               ; ffi.meta.__index\r\n0036  TGETS    9   7  11  ; \"_ticks\"\r\n0000  . . FUNCC               ; ffi.meta.__index\r\n0037  ISEQV    8   9\r\n0038  JMP      8 => 0031\r\n0000  . . FUNCC               ; ffi.meta.__eq\r\n0031  LOOP     8 => 0041\r\n```"},"comment":{"url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/comments/159982218","html_url":"https://github.com/LuaJIT/LuaJIT/issues/112#issuecomment-159982218","issue_url":"https://api.github.com/repos/LuaJIT/LuaJIT/issues/112","id":159982218,"user":{"login":"stepelu","id":6617696,"avatar_url":"https://avatars.githubusercontent.com/u/6617696?v=3","gravatar_id":"","url":"https://api.github.com/users/stepelu","html_url":"https://github.com/stepelu","followers_url":"https://api.github.com/users/stepelu/followers","following_url":"https://api.github.com/users/stepelu/following{/other_user}","gists_url":"https://api.github.com/users/stepelu/gists{/gist_id}","starred_url":"https://api.github.com/users/stepelu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stepelu/subscriptions","organizations_url":"https://api.github.com/users/stepelu/orgs","repos_url":"https://api.github.com/users/stepelu/repos","events_url":"https://api.github.com/users/stepelu/events{/privacy}","received_events_url":"https://api.github.com/users/stepelu/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T19:28:53Z","updated_at":"2015-11-26T19:28:53Z","body":"Thank you!\r\n\r\nI am glad LuaJIT has maintained its impressive bug-fixing timings :)"}}