metaworm/luac-parser-rs

Block layout bug

Opened this issue · 0 comments

When given the following script:

if RUN_CHECK then
    if VIOLATED then
        while true do
        end
    end
    print("passed violated check")
    if VIOLATED2 then
    	while true do
        end
    end
    print("passed violated2 check")
    if VIOLATED3 then
    	while true do
        end
    end
    print("passed violated3 check")
end

Metaworm's luadec incorrectly lays out the basic blocks in such a fashion:

if RUN_CHECK then
  if VIOLATED then
    while true do
    end
    print("passed violated check")
    if VIOLATED2 then
      while true do
      end
      print("passed violated2 check")
      if VIOLATED3 then
        while true do
        end
        print("passed violated3 check")
      else
        goto label_21	-- block#7 is visited secondly
      end
    else
      goto label_14	-- block#5 is visited secondly
    end
  else
    goto label_7	-- block#3 is visited secondly
  end
end

The while true do end loops do not have fallthrough edges, yet the block layout does not that into account.
Note that basic blocks are generated correctly here:
image