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

FunC incorreclty generate code for ifelse branches #374

Closed
EmelyanenkoK opened this issue May 17, 2022 · 0 comments
Closed

FunC incorreclty generate code for ifelse branches #374

EmelyanenkoK opened this issue May 17, 2022 · 0 comments

Comments

@EmelyanenkoK
Copy link
Member

The following code

() save (int a) impure inline {
  set_data(begin_cell().store_int(a,32).end_cell());
}

() main(int a) {
  int b = 3;
  if(a == 0) {
    return save(0);
  } elseif (a == 1) {
    b = 4;
    save(-1);
  }
  save(b);
}

will be compiled into

"Asm.fif" include
PROGRAM{
  DECLPROC save
  DECLPROC main
  save PROC:<{
    //  a
    NEWC	//  a _1
    32 STI	//  _3
    ENDC	//  _4
    c4 POP
  }>
  main PROC:<{
    //  a
    3 PUSHINT	//  a b=3
    OVER	//  a b=3 a
    0 EQINT	//  a b=3 _4
    IFJMP:<{	//  a b=3
      2DROP	// 
      0 PUSHINT	//  _5=0
      save INLINECALLDICT
    }>	//  a b=3
    SWAP	//  b=3 a
    1 EQINT	//  b=3 _8
    IF:<{	//  b=3
      DROP	// 
      4 PUSHINT	//  b=4
      -1 PUSHINT	//  b=4 _10=-1
      save INLINECALLDICT
    }>	//  b
  }>
}END>c

Which is incorrect: it not only forget to call save after ifelse branch but also leave b on the stack

EmelyanenkoK added a commit to EmelyanenkoK/ton that referenced this issue May 17, 2022
EmelyanenkoK added a commit that referenced this issue Aug 4, 2022
* Don't use IFJMP/IFNOTJMP in inline functions

* Fix incorrect ifelse branch code generation 

#374

* Make generate_code_all clearer

* Don't replace IFJMP with IF in inner blocks in inline functions

* Allow unbalance if/else by using RETALT

* Fix wrong PUSHCONT

* Bugfix in IF code generation for inline functions

* Fix unbalanced if/else

* Bugfix and improvements in code generation

* Fix analyzing while(0) in func

#377

* FunC and Asm.fif: Fix inlining large functions

#375

Co-authored-by: SpyCheese <[email protected]>
EmelyanenkoK added a commit that referenced this issue Aug 4, 2022
* Don't use IFJMP/IFNOTJMP in inline functions

* Fix incorrect ifelse branch code generation 

#374

* Make generate_code_all clearer

* Don't replace IFJMP with IF in inner blocks in inline functions

* Allow unbalance if/else by using RETALT

* Fix wrong PUSHCONT

* Bugfix in IF code generation for inline functions

* Fix unbalanced if/else

* Bugfix and improvements in code generation

* Fix analyzing while(0) in func

#377

* FunC and Asm.fif: Fix inlining large functions

#375

Co-authored-by: SpyCheese <[email protected]>
0XSNCRYPTO added a commit to 0XSNCRYPTO/ton that referenced this issue Aug 26, 2024
* Don't use IFJMP/IFNOTJMP in inline functions

* Fix incorrect ifelse branch code generation 

ton-blockchain/ton#374

* Make generate_code_all clearer

* Don't replace IFJMP with IF in inner blocks in inline functions

* Allow unbalance if/else by using RETALT

* Fix wrong PUSHCONT

* Bugfix in IF code generation for inline functions

* Fix unbalanced if/else

* Bugfix and improvements in code generation

* Fix analyzing while(0) in func

ton-blockchain/ton#377

* FunC and Asm.fif: Fix inlining large functions

ton-blockchain/ton#375

Co-authored-by: SpyCheese <[email protected]>
0XSNCRYPTO added a commit to 0XSNCRYPTO/ton that referenced this issue Aug 26, 2024
* Don't use IFJMP/IFNOTJMP in inline functions

* Fix incorrect ifelse branch code generation 

ton-blockchain/ton#374

* Make generate_code_all clearer

* Don't replace IFJMP with IF in inner blocks in inline functions

* Allow unbalance if/else by using RETALT

* Fix wrong PUSHCONT

* Bugfix in IF code generation for inline functions

* Fix unbalanced if/else

* Bugfix and improvements in code generation

* Fix analyzing while(0) in func

ton-blockchain/ton#377

* FunC and Asm.fif: Fix inlining large functions

ton-blockchain/ton#375

Co-authored-by: SpyCheese <[email protected]>
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

4 participants
@EmelyanenkoK and others