Assertion error string ends up in SSA output
takikawa opened this issue · 2 comments
takikawa commented
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
Nice catch.