Igalia / pflua

Packet filtering in Lua
Other
313 stars 39 forks source link

Assertion error string ends up in SSA output #259

Closed takikawa closed 7 years ago

takikawa commented 7 years ago

If you turn PF_VERBOSE on for certain expressions with a duplicated arithmetic expression, you can get some invalid blocks like the following:

    { "block",
      { "label",
        "L6" },
      { "bindings",
        { "v1",
          { "[]",
            16,
            1 } } },
      { "control",
        { "return",
          { "=",
            { "+",
              "v1",
              "v1",
              "unbound variable: var2" },
            1 } } } }

Note the "unbound variable: var2". This doesn't seem to cause any errors down the line because the third operand to + is just ignored in later passes, but it suggests there may be a bug in the ANF pass. If you add the following assertion:

assert(expr[4] == nil)

right after line 257 in pf.backend, it will trigger some failures because of the extra operand. Here's the full SSA output from running pflua-compile "ip[2:1] + ip[2:1] == 1":

{ "ssa",
  { "start",
    "L1" },
  { "blocks",
    { "block",
      { "label",
        "L1" },
      { "bindings" },
      { "control",
        { "if",
          { ">=",
            "len",
            34 },
          "L4",
          "L5" } } },
    { "block",
      { "label",
        "L4" },
      { "bindings" },
      { "control",
        { "if",
          { "=",
            { "[]",
              12,
              2 },
            8 },
          "L6",
          "L7" } } },
    { "block",
      { "label",
        "L6" },
      { "bindings",
        { "v1",
          { "[]",
            16,
            1 } } },
      { "control",
        { "return",
          { "=",
            { "+",
              "v1",
              "v1",
              "unbound variable: var2" },
            1 } } } },
    { "block",
      { "label",
        "L7" },
      { "bindings" },
      { "control",
        { "return",
          { "false" } } } },
    { "block",
      { "label",
        "L5" },
      { "bindings" },
      { "control",
        { "return",
          { "false" } } } } } }
kbara commented 7 years ago

Nice catch.

takikawa commented 7 years ago

Fixed by PR #262.