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

Suboptimal compilation of window-scaling pflang from jsnellman #215

Open
wingo opened this issue May 18, 2015 · 8 comments
Open

Suboptimal compilation of window-scaling pflang from jsnellman #215

wingo opened this issue May 18, 2015 · 8 comments

Comments

@wingo
Copy link
Contributor

wingo commented May 18, 2015

The following pflang is from Juho Snellman's blog post, and looks for the window-scaling option among the first 6 TCP options. I think it miscompiles though, because it looks like the whole ip6 block folds for some reason.

./env tools/pflang-compile "tcp and ((tcp[tcpflags] & tcp-syn) != 0) and ((tcp[20] == 3) or ((tcp[20] != 1) and ((tcp[20 + tcp[21]] == 3) or ((tcp[20 + tcp[21]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] + 1]] == 3))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1]] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] + 1] == 3))))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1]] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 2]] == 3))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 2] == 3))))))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1]] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] + 1]] == 3))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2]] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] + 1] == 3))))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2 + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 3]] == 3))) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 2] == 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 3] == 3))))))))) or ((tcp[20 + tcp[21]] == 1) and ((tcp[20 + tcp[21] + 1] == 3) or ((tcp[20 + tcp[21] + 1] != 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2]] == 3) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2]] != 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1]] == 3) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1]] != 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] + 1]] == 3))) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1]] == 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] + 1] == 3))))) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2]] == 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] == 3) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] != 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1 + tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 2]] == 3))) or ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 1] == 1) and ((tcp[20 + tcp[21] + 1 + tcp[20 + tcp[21] + 2] + 2] == 3))))))) or ((tcp[20 + tcp[21] + 1] == 1) and ((tcp[20 + tcp[21] + 2] == 3) or ((tcp[20 + tcp[21] + 2] != 1) and ((tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3]] == 3) or ((tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3]] != 1) and ((tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3] + tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3] + 1]] == 3))) or ((tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3]] == 1) and ((tcp[20 + tcp[21] + 2 + tcp[20 + tcp[21] + 3] + 1] == 3))))) or ((tcp[20 + tcp[21] + 2] == 1) and ((tcp[20 + tcp[21] + 3] == 3) or ((tcp[20 + tcp[21] + 3] != 1) and ((tcp[20 + tcp[21] + 3 + tcp[20 + tcp[21] + 4]] == 3))) or ((tcp[20 + tcp[21] + 3] == 1) and ((tcp[20 + tcp[21] + 4] == 3))))))))))) or ((tcp[20] == 1) and ((tcp[21] == 3) or ((tcp[21] != 1) and ((tcp[21 + tcp[22]] == 3) or ((tcp[21 + tcp[22]] != 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1]] == 3) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1]] != 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1]] == 3) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1]] != 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] + 1]] == 3))) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1]] == 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] + 1] == 3))))) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1]] == 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] == 3) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] != 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1 + tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 2]] == 3))) or ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 1] == 1) and ((tcp[21 + tcp[22] + tcp[21 + tcp[22] + 1] + 2] == 3))))))) or ((tcp[21 + tcp[22]] == 1) and ((tcp[21 + tcp[22] + 1] == 3) or ((tcp[21 + tcp[22] + 1] != 1) and ((tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2]] == 3) or ((tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2]] != 1) and ((tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2] + tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2] + 1]] == 3))) or ((tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2]] == 1) and ((tcp[21 + tcp[22] + 1 + tcp[21 + tcp[22] + 2] + 1] == 3))))) or ((tcp[21 + tcp[22] + 1] == 1) and ((tcp[21 + tcp[22] + 2] == 3) or ((tcp[21 + tcp[22] + 2] != 1) and ((tcp[21 + tcp[22] + 2 + tcp[21 + tcp[22] + 3]] == 3))) or ((tcp[21 + tcp[22] + 2] == 1) and ((tcp[21 + tcp[22] + 3] == 3))))))))) or ((tcp[21] == 1) and ((tcp[22] == 3) or ((tcp[22] != 1) and ((tcp[22 + tcp[23]] == 3) or ((tcp[22 + tcp[23]] != 1) and ((tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1]] == 3) or ((tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1]] != 1) and ((tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1] + tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1] + 1]] == 3))) or ((tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1]] == 1) and ((tcp[22 + tcp[23] + tcp[22 + tcp[23] + 1] + 1] == 3))))) or ((tcp[22 + tcp[23]] == 1) and ((tcp[22 + tcp[23] + 1] == 3) or ((tcp[22 + tcp[23] + 1] != 1) and ((tcp[22 + tcp[23] + 1 + tcp[22 + tcp[23] + 2]] == 3))) or ((tcp[22 + tcp[23] + 1] == 1) and ((tcp[22 + tcp[23] + 2] == 3))))))) or ((tcp[22] == 1) and ((tcp[23] == 3) or ((tcp[23] != 1) and ((tcp[23 + tcp[24]] == 3) or ((tcp[23 + tcp[24]] != 1) and ((tcp[23 + tcp[24] + tcp[23 + tcp[24] + 1]] == 3))) or ((tcp[23 + tcp[24]] == 1) and ((tcp[23 + tcp[24] + 1] == 3))))) or ((tcp[23] == 1) and ((tcp[24] == 3) or ((tcp[24] != 1) and ((tcp[24 + tcp[25]] == 3))) or ((tcp[24] == 1) and ((tcp[25] == 3))))))))))))"
local lshift = require("bit").lshift
local band = require("bit").band
local cast = require("ffi").cast
return function(P,length)
   if length < 14 then return false end
   local var1 = cast("uint16_t*", P+12)[0]
   if var1 == 8 then
      if length < 54 then return false end
      if P[23] ~= 6 then return false end
      if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end
      local var7 = lshift(band(P[14],15),2)
      if (var7 + 28) > length then return false end
      if band(P[(var7 + 27)],2) == 0 then return false end
      local var18 = (var7 + 35)
      if var18 > length then return false end
      local var23 = P[(var7 + 34)]
      if var23 == 3 then return true end
      if var23 == 1 then goto L21 end
      do
         if (var7 + 36) > length then return false end
         local var36 = (var7 + 14)
         local var41 = P[var18]
         local var42 = (20 + var41)
         local var43 = (var36 + var42)
         if (var43 + 1) > length then return false end
         local var56 = P[var43]
         if var56 == 3 then return true end
         if var56 == 1 then goto L31 end
         do
            local var79 = (var36 + (21 + var41))
            if (var79 + 1) > length then return false end
            local var103 = (var42 + P[var79])
            local var104 = (var36 + var103)
            if (var104 + 1) > length then return false end
            local var130 = P[var104]
            if var130 == 3 then return true end
            if var130 == 1 then goto L41 end
            do
               local var180 = (var36 + (var103 + 1))
               if (var180 + 1) > length then return false end
               local var231 = (var103 + P[var180])
               local var232 = (var36 + var231)
               if (var232 + 1) > length then return false end
               local var285 = P[var232]
               if var285 == 3 then return true end
               if var285 == 1 then goto L51 end
               do
                  local var389 = (var36 + (var231 + 1))
                  if (var389 + 1) > length then return false end
                  local var494 = (var231 + P[var389])
                  local var495 = (var36 + var494)
                  if (var495 + 1) > length then return false end
                  local var602 = P[var495]
                  if var602 == 3 then return true end
                  if var602 == 1 then goto L61 end
                  do
                     local var814 = (var36 + (var494 + 1))
                     if (var814 + 1) > length then return false end
                     local var1028 = (var36 + (var494 + P[var814]))
                     if (var1028 + 1) > length then return false end
                     if P[var1028] == 3 then return true end
                     goto L61
                  end
::L61::
                  if var602 ~= 1 then goto L51 end
                  local var1455 = (var36 + (var494 + 1))
                  if (var1455 + 1) > length then return false end
                  if P[var1455] == 3 then return true end
                  goto L51
               end
::L51::
               if var285 ~= 1 then goto L41 end
               local var1666 = (var231 + 1)
               local var1667 = (var36 + var1666)
               if (var1667 + 1) > length then return false end
               local var1721 = P[var1667]
               if var1721 == 3 then return true end
               if var1721 == 1 then goto L79 end
               do
                  local var1826 = (var36 + (var231 + 2))
                  if (var1826 + 1) > length then return false end
                  local var1933 = (var36 + (var1666 + P[var1826]))
                  if (var1933 + 1) > length then return false end
                  if P[var1933] == 3 then return true end
                  goto L79
               end
::L79::
               if var1721 ~= 1 then goto L41 end
               local var2146 = (var36 + (var231 + 2))
               if (var2146 + 1) > length then return false end
               if P[var2146] == 3 then return true end
               goto L41
            end
::L41::
            if var130 ~= 1 then goto L31 end
            local var2249 = (var103 + 1)
            local var2250 = (var36 + var2249)
            if (var2250 + 1) > length then return false end
            local var2277 = P[var2250]
            if var2277 == 3 then return true end
            if var2277 == 1 then goto L97 end
            do
               local var2328 = (var36 + (var103 + 2))
               if (var2328 + 1) > length then return false end
               local var2380 = (var2249 + P[var2328])
               local var2381 = (var36 + var2380)
               if (var2381 + 1) > length then return false end
               local var2435 = P[var2381]
               if var2435 == 3 then return true end
               if var2435 == 1 then goto L107 end
               do
                  local var2541 = (var36 + (var2380 + 1))
                  if (var2541 + 1) > length then return false end
                  local var2649 = (var36 + (var2380 + P[var2541]))
                  if (var2649 + 1) > length then return false end
                  if P[var2649] == 3 then return true end
                  goto L107
               end
::L107::
               if var2435 ~= 1 then goto L97 end
               local var2864 = (var36 + (var2380 + 1))
               if (var2864 + 1) > length then return false end
               if P[var2864] == 3 then return true end
               goto L97
            end
::L97::
            if var2277 ~= 1 then goto L31 end
            local var2969 = (var103 + 2)
            local var2970 = (var36 + var2969)
            if (var2970 + 1) > length then return false end
            local var2997 = P[var2970]
            if var2997 == 3 then return true end
            if var2997 == 1 then goto L125 end
            do
               local var3048 = (var36 + (var103 + 3))
               if (var3048 + 1) > length then return false end
               local var3101 = (var36 + (var2969 + P[var3048]))
               if (var3101 + 1) > length then return false end
               if P[var3101] == 3 then return true end
               goto L125
            end
::L125::
            if var2997 ~= 1 then goto L31 end
            local var3206 = (var36 + (var103 + 3))
            if (var3206 + 1) > length then return false end
            if P[var3206] == 3 then return true end
            goto L31
         end
::L31::
         if var56 ~= 1 then goto L21 end
         local var3255 = (21 + var41)
         local var3256 = (var36 + var3255)
         if (var3256 + 1) > length then return false end
         local var3269 = P[var3256]
         if var3269 == 3 then return true end
         if var3269 == 1 then goto L143 end
         do
            local var3292 = (var36 + (22 + var41))
            if (var3292 + 1) > length then return false end
            local var3316 = (var3255 + P[var3292])
            local var3317 = (var36 + var3316)
            if (var3317 + 1) > length then return false end
            local var3343 = P[var3317]
            if var3343 == 3 then return true end
            if var3343 == 1 then goto L153 end
            do
               local var3393 = (var36 + (var3316 + 1))
               if (var3393 + 1) > length then return false end
               local var3444 = (var3316 + P[var3393])
               local var3445 = (var36 + var3444)
               if (var3445 + 1) > length then return false end
               local var3498 = P[var3445]
               if var3498 == 3 then return true end
               if var3498 == 1 then goto L163 end
               do
                  local var3602 = (var36 + (var3444 + 1))
                  if (var3602 + 1) > length then return false end
                  local var3708 = (var36 + (var3444 + P[var3602]))
                  if (var3708 + 1) > length then return false end
                  if P[var3708] == 3 then return true end
                  goto L163
               end
::L163::
               if var3498 ~= 1 then goto L153 end
               local var3919 = (var36 + (var3444 + 1))
               if (var3919 + 1) > length then return false end
               if P[var3919] == 3 then return true end
               goto L153
            end
::L153::
            if var3343 ~= 1 then goto L143 end
            local var4022 = (var3316 + 1)
            local var4023 = (var36 + var4022)
            if (var4023 + 1) > length then return false end
            local var4050 = P[var4023]
            if var4050 == 3 then return true end
            if var4050 == 1 then goto L181 end
            do
               local var4101 = (var36 + (var3316 + 2))
               if (var4101 + 1) > length then return false end
               local var4154 = (var36 + (var4022 + P[var4101]))
               if (var4154 + 1) > length then return false end
               if P[var4154] == 3 then return true end
               goto L181
            end
::L181::
            if var4050 ~= 1 then goto L143 end
            local var4259 = (var36 + (var3316 + 2))
            if (var4259 + 1) > length then return false end
            if P[var4259] == 3 then return true end
            goto L143
         end
::L143::
         if var3269 ~= 1 then goto L21 end
         local var4308 = (22 + var41)
         local var4309 = (var36 + var4308)
         if (var4309 + 1) > length then return false end
         local var4322 = P[var4309]
         if var4322 == 3 then return true end
         if var4322 == 1 then goto L199 end
         do
            local var4345 = (var36 + (23 + var41))
            if (var4345 + 1) > length then return false end
            local var4369 = (var4308 + P[var4345])
            local var4370 = (var36 + var4369)
            if (var4370 + 1) > length then return false end
            local var4396 = P[var4370]
            if var4396 == 3 then return true end
            if var4396 == 1 then goto L209 end
            do
               local var4446 = (var36 + (var4369 + 1))
               if (var4446 + 1) > length then return false end
               local var4498 = (var36 + (var4369 + P[var4446]))
               if (var4498 + 1) > length then return false end
               if P[var4498] == 3 then return true end
               goto L209
            end
::L209::
            if var4396 ~= 1 then goto L199 end
            local var4601 = (var36 + (var4369 + 1))
            if (var4601 + 1) > length then return false end
            if P[var4601] == 3 then return true end
            goto L199
         end
::L199::
         if var4322 ~= 1 then goto L21 end
         local var4650 = (23 + var41)
         local var4651 = (var36 + var4650)
         if (var4651 + 1) > length then return false end
         local var4664 = P[var4651]
         if var4664 == 3 then return true end
         if var4664 == 1 then goto L227 end
         do
            local var4687 = (var36 + (24 + var41))
            if (var4687 + 1) > length then return false end
            local var4712 = (var36 + (var4650 + P[var4687]))
            if (var4712 + 1) > length then return false end
            if P[var4712] == 3 then return true end
            goto L227
         end
::L227::
         if var4664 ~= 1 then goto L21 end
         local var4761 = (var36 + (24 + var41))
         if (var4761 + 1) > length then return false end
         if P[var4761] == 3 then return true end
         goto L21
      end
::L21::
      if var23 ~= 1 then return false end
      local var4783 = (var7 + 36)
      if var4783 > length then return false end
      local var4788 = P[var18]
      if var4788 == 3 then return true end
      if var4788 == 1 then goto L245 end
      do
         if (var7 + 37) > length then return false end
         local var4801 = (var7 + 14)
         local var4806 = P[var4783]
         local var4807 = (21 + var4806)
         local var4808 = (var4801 + var4807)
         if (var4808 + 1) > length then return false end
         local var4821 = P[var4808]
         if var4821 == 3 then return true end
         if var4821 == 1 then goto L255 end
         do
            local var4844 = (var4801 + (22 + var4806))
            if (var4844 + 1) > length then return false end
            local var4868 = (var4807 + P[var4844])
            local var4869 = (var4801 + var4868)
            if (var4869 + 1) > length then return false end
            local var4895 = P[var4869]
            if var4895 == 3 then return true end
            if var4895 == 1 then goto L265 end
            do
               local var4945 = (var4801 + (var4868 + 1))
               if (var4945 + 1) > length then return false end
               local var4996 = (var4868 + P[var4945])
               local var4997 = (var4801 + var4996)
               if (var4997 + 1) > length then return false end
               local var5050 = P[var4997]
               if var5050 == 3 then return true end
               if var5050 == 1 then goto L275 end
               do
                  local var5154 = (var4801 + (var4996 + 1))
                  if (var5154 + 1) > length then return false end
                  local var5260 = (var4801 + (var4996 + P[var5154]))
                  if (var5260 + 1) > length then return false end
                  if P[var5260] == 3 then return true end
                  goto L275
               end
::L275::
               if var5050 ~= 1 then goto L265 end
               local var5471 = (var4801 + (var4996 + 1))
               if (var5471 + 1) > length then return false end
               if P[var5471] == 3 then return true end
               goto L265
            end
::L265::
            if var4895 ~= 1 then goto L255 end
            local var5574 = (var4868 + 1)
            local var5575 = (var4801 + var5574)
            if (var5575 + 1) > length then return false end
            local var5602 = P[var5575]
            if var5602 == 3 then return true end
            if var5602 == 1 then goto L293 end
            do
               local var5653 = (var4801 + (var4868 + 2))
               if (var5653 + 1) > length then return false end
               local var5706 = (var4801 + (var5574 + P[var5653]))
               if (var5706 + 1) > length then return false end
               if P[var5706] == 3 then return true end
               goto L293
            end
::L293::
            if var5602 ~= 1 then goto L255 end
            local var5811 = (var4801 + (var4868 + 2))
            if (var5811 + 1) > length then return false end
            if P[var5811] == 3 then return true end
            goto L255
         end
::L255::
         if var4821 ~= 1 then goto L245 end
         local var5860 = (22 + var4806)
         local var5861 = (var4801 + var5860)
         if (var5861 + 1) > length then return false end
         local var5874 = P[var5861]
         if var5874 == 3 then return true end
         if var5874 == 1 then goto L311 end
         do
            local var5897 = (var4801 + (23 + var4806))
            if (var5897 + 1) > length then return false end
            local var5921 = (var5860 + P[var5897])
            local var5922 = (var4801 + var5921)
            if (var5922 + 1) > length then return false end
            local var5948 = P[var5922]
            if var5948 == 3 then return true end
            if var5948 == 1 then goto L321 end
            do
               local var5998 = (var4801 + (var5921 + 1))
               if (var5998 + 1) > length then return false end
               local var6050 = (var4801 + (var5921 + P[var5998]))
               if (var6050 + 1) > length then return false end
               if P[var6050] == 3 then return true end
               goto L321
            end
::L321::
            if var5948 ~= 1 then goto L311 end
            local var6153 = (var4801 + (var5921 + 1))
            if (var6153 + 1) > length then return false end
            if P[var6153] == 3 then return true end
            goto L311
         end
::L311::
         if var5874 ~= 1 then goto L245 end
         local var6202 = (23 + var4806)
         local var6203 = (var4801 + var6202)
         if (var6203 + 1) > length then return false end
         local var6216 = P[var6203]
         if var6216 == 3 then return true end
         if var6216 == 1 then goto L339 end
         do
            local var6239 = (var4801 + (24 + var4806))
            if (var6239 + 1) > length then return false end
            local var6264 = (var4801 + (var6202 + P[var6239]))
            if (var6264 + 1) > length then return false end
            if P[var6264] == 3 then return true end
            goto L339
         end
::L339::
         if var6216 ~= 1 then goto L245 end
         local var6313 = (var4801 + (24 + var4806))
         if (var6313 + 1) > length then return false end
         if P[var6313] == 3 then return true end
         goto L245
      end
::L245::
      if var4788 ~= 1 then return false end
      local var6335 = (var7 + 37)
      if var6335 > length then return false end
      local var6340 = P[var4783]
      if var6340 == 3 then return true end
      if var6340 == 1 then goto L357 end
      do
         if (var7 + 38) > length then return false end
         local var6353 = (var7 + 14)
         local var6358 = P[var6335]
         local var6359 = (22 + var6358)
         local var6360 = (var6353 + var6359)
         if (var6360 + 1) > length then return false end
         local var6373 = P[var6360]
         if var6373 == 3 then return true end
         if var6373 == 1 then goto L367 end
         do
            local var6396 = (var6353 + (23 + var6358))
            if (var6396 + 1) > length then return false end
            local var6420 = (var6359 + P[var6396])
            local var6421 = (var6353 + var6420)
            if (var6421 + 1) > length then return false end
            local var6447 = P[var6421]
            if var6447 == 3 then return true end
            if var6447 == 1 then goto L377 end
            do
               local var6497 = (var6353 + (var6420 + 1))
               if (var6497 + 1) > length then return false end
               local var6549 = (var6353 + (var6420 + P[var6497]))
               if (var6549 + 1) > length then return false end
               if P[var6549] == 3 then return true end
               goto L377
            end
::L377::
            if var6447 ~= 1 then goto L367 end
            local var6652 = (var6353 + (var6420 + 1))
            if (var6652 + 1) > length then return false end
            if P[var6652] == 3 then return true end
            goto L367
         end
::L367::
         if var6373 ~= 1 then goto L357 end
         local var6701 = (23 + var6358)
         local var6702 = (var6353 + var6701)
         if (var6702 + 1) > length then return false end
         local var6715 = P[var6702]
         if var6715 == 3 then return true end
         if var6715 == 1 then goto L395 end
         do
            local var6738 = (var6353 + (24 + var6358))
            if (var6738 + 1) > length then return false end
            local var6763 = (var6353 + (var6701 + P[var6738]))
            if (var6763 + 1) > length then return false end
            if P[var6763] == 3 then return true end
            goto L395
         end
::L395::
         if var6715 ~= 1 then goto L357 end
         local var6812 = (var6353 + (24 + var6358))
         if (var6812 + 1) > length then return false end
         if P[var6812] == 3 then return true end
         goto L357
      end
::L357::
      if var6340 ~= 1 then return false end
      local var6834 = (var7 + 38)
      if var6834 > length then return false end
      local var6839 = P[var6335]
      if var6839 == 3 then return true end
      if var6839 == 1 then goto L413 end
      do
         if (var7 + 39) > length then return false end
         local var6852 = (var7 + 14)
         local var6857 = P[var6834]
         local var6858 = (23 + var6857)
         local var6859 = (var6852 + var6858)
         if (var6859 + 1) > length then return false end
         local var6872 = P[var6859]
         if var6872 == 3 then return true end
         if var6872 == 1 then goto L423 end
         do
            local var6895 = (var6852 + (24 + var6857))
            if (var6895 + 1) > length then return false end
            local var6920 = (var6852 + (var6858 + P[var6895]))
            if (var6920 + 1) > length then return false end
            if P[var6920] == 3 then return true end
            goto L423
         end
::L423::
         if var6872 ~= 1 then goto L413 end
         local var6969 = (var6852 + (24 + var6857))
         if (var6969 + 1) > length then return false end
         if P[var6969] == 3 then return true end
         goto L413
      end
::L413::
      if var6839 ~= 1 then return false end
      local var6991 = (var7 + 39)
      if var6991 > length then return false end
      local var6996 = P[var6834]
      if var6996 == 3 then return true end
      if var6996 == 1 then goto L441 end
      do
         if (var7 + 40) > length then return false end
         local var7016 = ((var7 + 14) + (24 + P[var6991]))
         if (var7016 + 1) > length then return false end
         if P[var7016] == 3 then return true end
         goto L441
      end
::L441::
      if var6996 ~= 1 then return false end
      if (var7 + 40) > length then return false end
      return P[var6991] == 3
   else
      if var1 ~= 56710 then return false end
      if length < 54 then return false end
      local var7045 = P[20]
      return false
   end
end
@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

Or is this a failure? The --bpf-lua compilation also appears to reject IPv6 as well. Bizarre.

@jsnell
Copy link

jsnell commented May 18, 2015

Yeah, this doesn't really match my mental model of IPv6 support at all, but it's certainly present in libpcap too :-)

A more reasonable test case, 'ip6 and tcp and (tcp[tcpflags] != 0)'. This seems to be the offending code in libpcap, so seems like you're bug-compatible :-)

     * XXX - we should, if we're built with
     * IPv6 support, generate code to load either
     * IPv4, IPv6, or both, as appropriate.
     */
    s = gen_loadx_iphdrlen();

@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

@jsnell interesting :)

$ ./env tools/pflua-compile --bpf-lua 'ip6 and tcp and (tcp[tcpflags] != 0)'
return function (P, length)
   do return false end
   error("end of bpf")
end

Passing --bpf-lua means using libpcap to parse, optimize, and emit BPF, then we compile that BPF to Lua. Here we see that the whole thing folds. Using pflua to compile also produces code that will never match, but somehow it doesn't manage to actually fold. Thanks for the optimizer test case :-)

@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

(in case it's not clear, the example from my above comment means that libpcap sees the given expression as always false, so it might not be a pflua bug.)

@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

...and the reason why 'ip6 and tcp[tcpflags] != 0" doesn't match is because accessing packet data via tcp[] only succeeds if the packet is ipv4. Quoth the "specification":

The expression ‘ip[6:2] & 0x1fff = 0’ catches only unfragmented IPv4 datagrams and frag zero of fragmented IPv4 datagrams. This check is implicitly applied to the tcp and udp index operations. For instance, tcp[0] always means the first byte of the TCP header, and never means the first byte of an intervening fragment.

https://www.wireshark.org/docs/man-pages/pcap-filter.html

@wingo wingo changed the title Optimization failure in window-scaling pflang from jsnellman Suboptimal compilation of window-scaling pflang from jsnellman May 18, 2015
@wingo
Copy link
Contributor Author

wingo commented May 18, 2015

Edited title to indicate that what I thought was a correctness bug is actually a "feature" of pflang. Leaving the bug open as a task to eventually compile this expression more optimally.

@wingo
Copy link
Contributor Author

wingo commented Jul 2, 2015

FWIW current compilation looks like this; haven't taken a look yet to figure out what could be better

local lshift = require("bit").lshift
local band = require("bit").band
local cast = require("ffi").cast
return function(P,length)
   if length < 54 then return false end
   if cast("uint16_t*", P+12)[0] ~= 8 then return false end
   if P[23] ~= 6 then return false end
   if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end
   local v1 = lshift(band(P[14],15),2)
   if (v1 + 28) > length then return false end
   if band(P[(v1 + 27)],2) == 0 then return false end
   local v2 = (v1 + 35)
   if v2 > length then return false end
   local v3 = P[(v1 + 34)]
   if v3 == 3 then return true end
   if v3 == 1 then goto L19 end
   do
      if (v1 + 36) > length then return false end
      local v4 = P[v2]
      local v5 = (v1 + v4)
      local v6 = (v5 + 35)
      if v6 > length then return false end
      local v7 = P[(v5 + 34)]
      if v7 == 3 then return true end
      if v7 == 1 then goto L29 end
      do
         if (v5 + 36) > length then return false end
         local v8 = (v4 + P[v6])
         local v9 = (v1 + v8)
         local v10 = (v9 + 35)
         if v10 > length then return false end
         local v11 = P[(v9 + 34)]
         if v11 == 3 then return true end
         if v11 == 1 then goto L39 end
         do
            if (v9 + 36) > length then return false end
            local v12 = (v8 + P[v10])
            local v13 = (v1 + v12)
            local v14 = (v13 + 35)
            if v14 > length then return false end
            local v15 = P[(v13 + 34)]
            if v15 == 3 then return true end
            if v15 == 1 then goto L49 end
            do
               if (v13 + 36) > length then return false end
               local v16 = (v12 + P[v14])
               local v17 = (v1 + v16)
               local v18 = (v17 + 35)
               if v18 > length then return false end
               local v19 = P[(v17 + 34)]
               if v19 == 3 then return true end
               if v19 == 1 then goto L59 end
               do
                  if (v17 + 36) > length then return false end
                  local v20 = (v1 + (v16 + P[v18]))
                  if (v20 + 35) > length then return false end
                  if P[(v20 + 34)] == 3 then return true end
                  goto L59
               end
::L59::
               if v19 ~= 1 then goto L49 end
               if (v17 + 36) > length then return false end
               if P[v18] == 3 then return true end
               goto L49
            end
::L49::
            if v15 ~= 1 then goto L39 end
            local v21 = (v13 + 36)
            if v21 > length then return false end
            local v22 = P[v14]
            if v22 == 3 then return true end
            if v22 == 1 then goto L77 end
            do
               if (v13 + 37) > length then return false end
               local v23 = (v1 + (v12 + P[v21]))
               if (v23 + 36) > length then return false end
               if P[(v23 + 35)] == 3 then return true end
               goto L77
            end
::L77::
            if v22 ~= 1 then goto L39 end
            if (v13 + 37) > length then return false end
            if P[v21] == 3 then return true end
            goto L39
         end
::L39::
         if v11 ~= 1 then goto L29 end
         local v24 = (v9 + 36)
         if v24 > length then return false end
         local v25 = P[v10]
         if v25 == 3 then return true end
         if v25 == 1 then goto L95 end
         do
            if (v9 + 37) > length then return false end
            local v26 = (v8 + P[v24])
            local v27 = (v1 + v26)
            local v28 = (v27 + 36)
            if v28 > length then return false end
            local v29 = P[(v27 + 35)]
            if v29 == 3 then return true end
            if v29 == 1 then goto L105 end
            do
               if (v27 + 37) > length then return false end
               local v30 = (v1 + (v26 + P[v28]))
               if (v30 + 36) > length then return false end
               if P[(v30 + 35)] == 3 then return true end
               goto L105
            end
::L105::
            if v29 ~= 1 then goto L95 end
            if (v27 + 37) > length then return false end
            if P[v28] == 3 then return true end
            goto L95
         end
::L95::
         if v25 ~= 1 then goto L29 end
         local v31 = (v9 + 37)
         if v31 > length then return false end
         local v32 = P[v24]
         if v32 == 3 then return true end
         if v32 == 1 then goto L123 end
         do
            if (v9 + 38) > length then return false end
            local v33 = (v1 + (v8 + P[v31]))
            if (v33 + 37) > length then return false end
            if P[(v33 + 36)] == 3 then return true end
            goto L123
         end
::L123::
         if v32 ~= 1 then goto L29 end
         if (v9 + 38) > length then return false end
         if P[v31] == 3 then return true end
         goto L29
      end
::L29::
      if v7 ~= 1 then goto L19 end
      local v34 = (v5 + 36)
      if v34 > length then return false end
      local v35 = P[v6]
      if v35 == 3 then return true end
      if v35 == 1 then goto L141 end
      do
         if (v5 + 37) > length then return false end
         local v36 = (v4 + P[v34])
         local v37 = (v1 + v36)
         local v38 = (v37 + 36)
         if v38 > length then return false end
         local v39 = P[(v37 + 35)]
         if v39 == 3 then return true end
         if v39 == 1 then goto L151 end
         do
            if (v37 + 37) > length then return false end
            local v40 = (v36 + P[v38])
            local v41 = (v1 + v40)
            local v42 = (v41 + 36)
            if v42 > length then return false end
            local v43 = P[(v41 + 35)]
            if v43 == 3 then return true end
            if v43 == 1 then goto L161 end
            do
               if (v41 + 37) > length then return false end
               local v44 = (v1 + (v40 + P[v42]))
               if (v44 + 36) > length then return false end
               if P[(v44 + 35)] == 3 then return true end
               goto L161
            end
::L161::
            if v43 ~= 1 then goto L151 end
            if (v41 + 37) > length then return false end
            if P[v42] == 3 then return true end
            goto L151
         end
::L151::
         if v39 ~= 1 then goto L141 end
         local v45 = (v37 + 37)
         if v45 > length then return false end
         local v46 = P[v38]
         if v46 == 3 then return true end
         if v46 == 1 then goto L179 end
         do
            if (v37 + 38) > length then return false end
            local v47 = (v1 + (v36 + P[v45]))
            if (v47 + 37) > length then return false end
            if P[(v47 + 36)] == 3 then return true end
            goto L179
         end
::L179::
         if v46 ~= 1 then goto L141 end
         if (v37 + 38) > length then return false end
         if P[v45] == 3 then return true end
         goto L141
      end
::L141::
      if v35 ~= 1 then goto L19 end
      local v48 = (v5 + 37)
      if v48 > length then return false end
      local v49 = P[v34]
      if v49 == 3 then return true end
      if v49 == 1 then goto L197 end
      do
         if (v5 + 38) > length then return false end
         local v50 = (v4 + P[v48])
         local v51 = (v1 + v50)
         local v52 = (v51 + 37)
         if v52 > length then return false end
         local v53 = P[(v51 + 36)]
         if v53 == 3 then return true end
         if v53 == 1 then goto L207 end
         do
            if (v51 + 38) > length then return false end
            local v54 = (v1 + (v50 + P[v52]))
            if (v54 + 37) > length then return false end
            if P[(v54 + 36)] == 3 then return true end
            goto L207
         end
::L207::
         if v53 ~= 1 then goto L197 end
         if (v51 + 38) > length then return false end
         if P[v52] == 3 then return true end
         goto L197
      end
::L197::
      if v49 ~= 1 then goto L19 end
      local v55 = (v5 + 38)
      if v55 > length then return false end
      local v56 = P[v48]
      if v56 == 3 then return true end
      if v56 == 1 then goto L225 end
      do
         if (v5 + 39) > length then return false end
         local v57 = (v1 + (v4 + P[v55]))
         if (v57 + 38) > length then return false end
         if P[(v57 + 37)] == 3 then return true end
         goto L225
      end
::L225::
      if v56 ~= 1 then goto L19 end
      if (v5 + 39) > length then return false end
      if P[v55] == 3 then return true end
      goto L19
   end
::L19::
   if v3 ~= 1 then return false end
   local v58 = (v1 + 36)
   if v58 > length then return false end
   local v59 = P[v2]
   if v59 == 3 then return true end
   if v59 == 1 then goto L243 end
   do
      if (v1 + 37) > length then return false end
      local v60 = P[v58]
      local v61 = (v1 + v60)
      local v62 = (v61 + 36)
      if v62 > length then return false end
      local v63 = P[(v61 + 35)]
      if v63 == 3 then return true end
      if v63 == 1 then goto L253 end
      do
         if (v61 + 37) > length then return false end
         local v64 = (v60 + P[v62])
         local v65 = (v1 + v64)
         local v66 = (v65 + 36)
         if v66 > length then return false end
         local v67 = P[(v65 + 35)]
         if v67 == 3 then return true end
         if v67 == 1 then goto L263 end
         do
            if (v65 + 37) > length then return false end
            local v68 = (v64 + P[v66])
            local v69 = (v1 + v68)
            local v70 = (v69 + 36)
            if v70 > length then return false end
            local v71 = P[(v69 + 35)]
            if v71 == 3 then return true end
            if v71 == 1 then goto L273 end
            do
               if (v69 + 37) > length then return false end
               local v72 = (v1 + (v68 + P[v70]))
               if (v72 + 36) > length then return false end
               if P[(v72 + 35)] == 3 then return true end
               goto L273
            end
::L273::
            if v71 ~= 1 then goto L263 end
            if (v69 + 37) > length then return false end
            if P[v70] == 3 then return true end
            goto L263
         end
::L263::
         if v67 ~= 1 then goto L253 end
         local v73 = (v65 + 37)
         if v73 > length then return false end
         local v74 = P[v66]
         if v74 == 3 then return true end
         if v74 == 1 then goto L291 end
         do
            if (v65 + 38) > length then return false end
            local v75 = (v1 + (v64 + P[v73]))
            if (v75 + 37) > length then return false end
            if P[(v75 + 36)] == 3 then return true end
            goto L291
         end
::L291::
         if v74 ~= 1 then goto L253 end
         if (v65 + 38) > length then return false end
         if P[v73] == 3 then return true end
         goto L253
      end
::L253::
      if v63 ~= 1 then goto L243 end
      local v76 = (v61 + 37)
      if v76 > length then return false end
      local v77 = P[v62]
      if v77 == 3 then return true end
      if v77 == 1 then goto L309 end
      do
         if (v61 + 38) > length then return false end
         local v78 = (v60 + P[v76])
         local v79 = (v1 + v78)
         local v80 = (v79 + 37)
         if v80 > length then return false end
         local v81 = P[(v79 + 36)]
         if v81 == 3 then return true end
         if v81 == 1 then goto L319 end
         do
            if (v79 + 38) > length then return false end
            local v82 = (v1 + (v78 + P[v80]))
            if (v82 + 37) > length then return false end
            if P[(v82 + 36)] == 3 then return true end
            goto L319
         end
::L319::
         if v81 ~= 1 then goto L309 end
         if (v79 + 38) > length then return false end
         if P[v80] == 3 then return true end
         goto L309
      end
::L309::
      if v77 ~= 1 then goto L243 end
      local v83 = (v61 + 38)
      if v83 > length then return false end
      local v84 = P[v76]
      if v84 == 3 then return true end
      if v84 == 1 then goto L337 end
      do
         if (v61 + 39) > length then return false end
         local v85 = (v1 + (v60 + P[v83]))
         if (v85 + 38) > length then return false end
         if P[(v85 + 37)] == 3 then return true end
         goto L337
      end
::L337::
      if v84 ~= 1 then goto L243 end
      if (v61 + 39) > length then return false end
      if P[v83] == 3 then return true end
      goto L243
   end
::L243::
   if v59 ~= 1 then return false end
   local v86 = (v1 + 37)
   if v86 > length then return false end
   local v87 = P[v58]
   if v87 == 3 then return true end
   if v87 == 1 then goto L355 end
   do
      if (v1 + 38) > length then return false end
      local v88 = P[v86]
      local v89 = (v1 + v88)
      local v90 = (v89 + 37)
      if v90 > length then return false end
      local v91 = P[(v89 + 36)]
      if v91 == 3 then return true end
      if v91 == 1 then goto L365 end
      do
         if (v89 + 38) > length then return false end
         local v92 = (v88 + P[v90])
         local v93 = (v1 + v92)
         local v94 = (v93 + 37)
         if v94 > length then return false end
         local v95 = P[(v93 + 36)]
         if v95 == 3 then return true end
         if v95 == 1 then goto L375 end
         do
            if (v93 + 38) > length then return false end
            local v96 = (v1 + (v92 + P[v94]))
            if (v96 + 37) > length then return false end
            if P[(v96 + 36)] == 3 then return true end
            goto L375
         end
::L375::
         if v95 ~= 1 then goto L365 end
         if (v93 + 38) > length then return false end
         if P[v94] == 3 then return true end
         goto L365
      end
::L365::
      if v91 ~= 1 then goto L355 end
      local v97 = (v89 + 38)
      if v97 > length then return false end
      local v98 = P[v90]
      if v98 == 3 then return true end
      if v98 == 1 then goto L393 end
      do
         if (v89 + 39) > length then return false end
         local v99 = (v1 + (v88 + P[v97]))
         if (v99 + 38) > length then return false end
         if P[(v99 + 37)] == 3 then return true end
         goto L393
      end
::L393::
      if v98 ~= 1 then goto L355 end
      if (v89 + 39) > length then return false end
      if P[v97] == 3 then return true end
      goto L355
   end
::L355::
   if v87 ~= 1 then return false end
   local v100 = (v1 + 38)
   if v100 > length then return false end
   local v101 = P[v86]
   if v101 == 3 then return true end
   if v101 == 1 then goto L411 end
   do
      if (v1 + 39) > length then return false end
      local v102 = P[v100]
      local v103 = (v1 + v102)
      local v104 = (v103 + 38)
      if v104 > length then return false end
      local v105 = P[(v103 + 37)]
      if v105 == 3 then return true end
      if v105 == 1 then goto L421 end
      do
         if (v103 + 39) > length then return false end
         local v106 = (v1 + (v102 + P[v104]))
         if (v106 + 38) > length then return false end
         if P[(v106 + 37)] == 3 then return true end
         goto L421
      end
::L421::
      if v105 ~= 1 then goto L411 end
      if (v103 + 39) > length then return false end
      if P[v104] == 3 then return true end
      goto L411
   end
::L411::
   if v101 ~= 1 then return false end
   local v107 = (v1 + 39)
   if v107 > length then return false end
   local v108 = P[v100]
   if v108 == 3 then return true end
   if v108 == 1 then goto L439 end
   do
      if (v1 + 40) > length then return false end
      local v109 = (v1 + P[v107])
      if (v109 + 39) > length then return false end
      if P[(v109 + 38)] == 3 then return true end
      goto L439
   end
::L439::
   if v108 ~= 1 then return false end
   if (v1 + 40) > length then return false end
   return P[v107] == 3
end

takikawa added a commit to takikawa/pflua that referenced this issue Dec 7, 2016
This test exercises spilling for the dynasm backend
pretty well and exposed a bug
takikawa added a commit that referenced this issue Dec 9, 2016
Fix spilling & add a big test from issue #215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants