Skip to content

FunC incorrectly optimizes away division by zero for double application of operator % #1662

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

Open
jeshecdom opened this issue May 9, 2025 · 0 comments

Comments

@jeshecdom
Copy link

Based on tact-lang/tact#3019

Code to reproduce

int calc(int x) {
    return (((-1 % x) % 1) <= 0);
}

() main() {
    throw_if(16, calc(0));
}

Output Fift

// automatically generated from `func_test.fc` 
DECLPROC calc
DECLPROC main
calc PROC:<{
  DROP
  TRUE
}>
main PROC:<{
  0 PUSHINT
  calc CALLDICT
  16 THROWIF
}>

Actual behavior when executed

calc always returns true.

Expected behavior when executed

Exit code 4, since -1 % x should produce a division by zero when x = 0.

Side note 1: The related expression ((-1 % x) % 1) == 0 also gets mapped to TRUE.
Side note 2: Interestingly enough, the shorter expression (x % 1) <= 0 gets translated the expected way:

calc PROC:<{
  1 PUSHINT
  MOD
  1 LESSINT
}>
@JohnnyGoGoGo JohnnyGoGoGo closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2025
@EmelyanenkoK EmelyanenkoK reopened this May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants