Constant evaluation breaks function argument substitution
Removes division by zero exception
For the following operators and arithmetic functions, the compiler carries out optimizations during constant evaluation that removes the expected division by zero exception.Multiplication/division built-ins
Issue page: #1678 For functionsmuldiv, muldivc and muldivr,
if any of their first two arguments is zero at compilation time, the compiler replaces the function call with 0, irrespective of the function’s
third argument, i.e., the divisor. This means that the function calls get replaced by 0 even when the divisor is 0,
effectively removing the expected division by zero exception.
Examples:
Operators /, % combined with comparison operators
Issue pages: #1659, #1660, #1661, #1662. The compiler simplifies the division/ and modulo % operators when their left argument is 0,
but only when / and % are used in tandem with comparison operators like >=, >, ==, etc.
For example, the following expressions are not simplified to 0 at compile-time, which is the correct behavior:
z:
z = 0.
The following are further examples where the left operand of / and % is simplified to 0 by FunC, resulting in a final
expression that the compiler simplifies to true, irrespective of the value of z:
Removes integer overflow exception
Issue pages: #1656, #1657, #1658. The following expressions should produce overflows for particular values ofz,
but the FunC compiler simplifies them irrespective of z:
true irrespective of the value of z:
MIN_INT = -115792089237316195423570985008687907853269984665640564039457584007913129639936 and
MAX_INT = 115792089237316195423570985008687907853269984665640564039457584007913129639935.
Incorrect results
Involving operator ~%
Issue Page: #1670
In the following code:
calc(1) produces -1. But calling calc3(1,-3,0) produces 0. But the expected behavior is calc(1) = calc3(1,-3,0), since calc is just a specialization of calc3.
The same happens with comparison operators: <=>, !=, and ==, i.e., the following expressions also produce differing results:
((x ~% -3) <=> 1)incalcfunction, and((x ~% y) <=> z)incal3function. Producescalc(1) = -1, andcalc3(1,-3,1) = 0.((x ~% -3) != 1)incalcfunction, and((x ~% y) != z)incal3function. Producescalc(1) = -1, andcalc3(1,-3,1) = 0.((x ~% -3) == 1)incalcfunction, and((x ~% y) == z)incal3function. Producescalc(1) = 0, andcalc3(1,-3,1) = -1.
Involving operator ^%
Issue Page: #1669
In the following code:
calc(1) produces -1. But calling calc3(1,-2,0) produces 0. But the expected behavior is calc(1) = calc3(1,-2,0), since calc is just a specialization of calc3.
The same happens with comparison operators: <=>, !=, and ==. The following expressions also produce differing results:
((x ^% -2) <=> 1)incalcfunction, and((x ^% y) <=> z)incal3function. Producescalc(1) = -1, andcalc3(1,-2,1) = 0.((x ^% -2) != 1)incalcfunction, and((x ^% y) != z)incal3function. Producescalc(1) = -1, andcalc3(1,-2,1) = 0.((x ^% -2) == 1)incalcfunction, and((x ^% y) == z)incal3function. Producescalc(1) = 0, andcalc3(1,-2,1) = -1.
Stack underflow in run_methodX functions
Issue Page: #1883.
The following code produces a stack underflow when run_method3 executes:
test function prints 100, 200, and 300 in the debug logs when run_method3 executes.
The functions run_method0, run_method1, and run_method2 have similar problems with stack underflow.