mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Tests.
This commit is contained in:
		
							parent
							
								
									5b73c2ae3b
								
							
						
					
					
						commit
						ace601b8f6
					
				| @ -250,6 +250,36 @@ BOOST_AUTO_TEST_CASE(to_string) | ||||
| 	BOOST_CHECK_EQUAL(asmStack.print(), expectation); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(arg_to_dataoffset_must_be_literal) | ||||
| { | ||||
| 	string code = R"( | ||||
| 		object "outer" { | ||||
| 			code { let x := "outer" let y := dataoffset(x) } | ||||
| 		} | ||||
| 	)"; | ||||
| 	CHECK_ERROR(code, TypeError, "Function expects direct literals as arguments."); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(arg_to_datasize_must_be_literal) | ||||
| { | ||||
| 	string code = R"( | ||||
| 		object "outer" { | ||||
| 			code { let x := "outer" let y := datasize(x) } | ||||
| 		} | ||||
| 	)"; | ||||
| 	CHECK_ERROR(code, TypeError, "Function expects direct literals as arguments."); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(args_to_datacopy_are_arbitrary) | ||||
| { | ||||
| 	string code = R"( | ||||
| 		object "outer" { | ||||
| 			code { let x := 0 let y := 2 let s := 3 datacopy(x, y, s) } | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(successParse(code)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_SUITE_END() | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,23 @@ | ||||
| { | ||||
|     // Arguments to ``datasize`` and ``dataoffset`` need to be | ||||
|     // literals. We cannot simplify their arguments, but we can | ||||
|     // simplify them as a full expression. | ||||
|     // ``datacopy`` does not have this restriction. | ||||
|     let r := "abc" | ||||
|     let a := datasize("abc") | ||||
|     let x := dataoffset("abc") | ||||
|     // should be replaced by a | ||||
|     let y := datasize("abc") | ||||
|     datacopy("abc", x, y) | ||||
|     mstore(a, x) | ||||
| } | ||||
| // ---- | ||||
| // commonSubexpressionEliminator | ||||
| // { | ||||
| //     let r := "abc" | ||||
| //     let a := datasize("abc") | ||||
| //     let x := dataoffset("abc") | ||||
| //     let y := a | ||||
| //     datacopy(r, x, a) | ||||
| //     mstore(a, x) | ||||
| // } | ||||
| @ -0,0 +1,21 @@ | ||||
| { | ||||
|     // We should never split arguments to ``dataoffset`` | ||||
|     // or ``datasize`` because they need to be literals | ||||
|     let x := dataoffset("abc") | ||||
|     let y := datasize("abc") | ||||
|     // datacopy is fine, though | ||||
|     datacopy(mload(0), mload(1), mload(2)) | ||||
| } | ||||
| // ---- | ||||
| // expressionSplitter | ||||
| // { | ||||
| //     let x := dataoffset("abc") | ||||
| //     let y := datasize("abc") | ||||
| //     let _1 := 2 | ||||
| //     let _2 := mload(_1) | ||||
| //     let _3 := 1 | ||||
| //     let _4 := mload(_3) | ||||
| //     let _5 := 0 | ||||
| //     let _6 := mload(_5) | ||||
| //     datacopy(_6, _4, _2) | ||||
| // } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user