mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	[FunC] Fix a bug with << operator to zero value (#1262)
This commit is contained in:
		
							parent
							
								
									b69214b6af
								
							
						
					
					
						commit
						fd1735f6ec
					
				
					 3 changed files with 56 additions and 3 deletions
				
			
		
							
								
								
									
										53
									
								
								crypto/func/auto-tests/tests/bit-operators.fc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								crypto/func/auto-tests/tests/bit-operators.fc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,53 @@
 | 
			
		|||
 | 
			
		||||
int lshift() {
 | 
			
		||||
    return (1 << 0) == 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int rshift() {
 | 
			
		||||
    return (1 >> 0) == 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int lshift_var(int i) {
 | 
			
		||||
    return (1 << i) == 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int rshift_var(int i) {
 | 
			
		||||
    return (1 >> i) == 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int x) {
 | 
			
		||||
    if (x == 0) {
 | 
			
		||||
        return lshift();
 | 
			
		||||
    } elseif (x == 1) {
 | 
			
		||||
        return rshift();
 | 
			
		||||
    } elseif (x == 2) {
 | 
			
		||||
        return lshift_var(0);
 | 
			
		||||
    } elseif (x == 3) {
 | 
			
		||||
        return rshift_var(0);
 | 
			
		||||
    } elseif (x == 4) {
 | 
			
		||||
        return lshift_var(1);
 | 
			
		||||
    } else {
 | 
			
		||||
        return rshift_var(1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int is_claimed(int index) method_id(11) {
 | 
			
		||||
    int claim_bit_index = index % 256;
 | 
			
		||||
    int mask = 1 << claim_bit_index;
 | 
			
		||||
    return (255 & mask) == mask;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
{-
 | 
			
		||||
    method_id | in  | out
 | 
			
		||||
TESTCASE | 0  | 0   | -1
 | 
			
		||||
TESTCASE | 0  | 1   | -1
 | 
			
		||||
TESTCASE | 0  | 2   | -1
 | 
			
		||||
TESTCASE | 0  | 3   | -1
 | 
			
		||||
TESTCASE | 0  | 4   |  0
 | 
			
		||||
TESTCASE | 0  | 5   |  0
 | 
			
		||||
TESTCASE | 11 | 0   | -1
 | 
			
		||||
TESTCASE | 11 | 1   | -1
 | 
			
		||||
TESTCASE | 11 | 256 | -1
 | 
			
		||||
TESTCASE | 11 | 8   |  0
 | 
			
		||||
-}
 | 
			
		||||
| 
						 | 
				
			
			@ -264,7 +264,7 @@ int emulate_lshift(int a, int b) {
 | 
			
		|||
  }
 | 
			
		||||
  int t = ((b & VarDescr::_NonZero) ? VarDescr::_Even : 0);
 | 
			
		||||
  t |= b & VarDescr::_Finite;
 | 
			
		||||
  return emulate_mul(a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | VarDescr::_Even | t);
 | 
			
		||||
  return emulate_mul(a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int emulate_div(int a, int b) {
 | 
			
		||||
| 
						 | 
				
			
			@ -310,7 +310,7 @@ int emulate_rshift(int a, int b) {
 | 
			
		|||
  }
 | 
			
		||||
  int t = ((b & VarDescr::_NonZero) ? VarDescr::_Even : 0);
 | 
			
		||||
  t |= b & VarDescr::_Finite;
 | 
			
		||||
  return emulate_div(a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | VarDescr::_Even | t);
 | 
			
		||||
  return emulate_div(a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int emulate_mod(int a, int b, int round_mode = -1) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ extern std::string generated_from;
 | 
			
		|||
 | 
			
		||||
constexpr int optimize_depth = 20;
 | 
			
		||||
 | 
			
		||||
const std::string func_version{"0.4.4"};
 | 
			
		||||
const std::string func_version{"0.4.5"};
 | 
			
		||||
 | 
			
		||||
enum Keyword {
 | 
			
		||||
  _Eof = -1,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue