@@ -5005,6 +5005,33 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
5005
5005
BOOST_CHECK_EQUAL (balanceAt (libraryAddress), 0 );
5006
5006
}
5007
5007
5008
+ BOOST_AUTO_TEST_CASE (create_memory_array_allocation_size)
5009
+ {
5010
+ // Check allocation size of byte array. Should be 32 plus length rounded up to next
5011
+ // multiple of 32
5012
+ char const * sourceCode = R"(
5013
+ contract C {
5014
+ function f() public pure returns (uint d1, uint d2, uint d3, uint memsize) {
5015
+ bytes memory b1 = new bytes(31);
5016
+ bytes memory b2 = new bytes(32);
5017
+ bytes memory b3 = new bytes(256);
5018
+ bytes memory b4 = new bytes(31);
5019
+ assembly {
5020
+ d1 := sub(b2, b1)
5021
+ d2 := sub(b3, b2)
5022
+ d3 := sub(b4, b3)
5023
+ memsize := msize()
5024
+ }
5025
+ }
5026
+ }
5027
+ )" ;
5028
+ if (!m_optimiserSettings.runYulOptimiser )
5029
+ {
5030
+ compileAndRun (sourceCode);
5031
+ ABI_CHECK (callContractFunction (" f()" ), encodeArgs (0x40 , 0x40 , 0x20 + 256 , 0x260 ));
5032
+ }
5033
+ }
5034
+
5008
5035
BOOST_AUTO_TEST_CASE (using_for_function_on_int)
5009
5036
{
5010
5037
char const * sourceCode = R"(
@@ -5202,6 +5229,36 @@ BOOST_AUTO_TEST_CASE(failed_create)
5202
5229
ABI_CHECK (callContractFunction (" x()" ), encodeArgs (u256 (1 )));
5203
5230
}
5204
5231
5232
+ BOOST_AUTO_TEST_CASE (correctly_initialize_memory_array_in_constructor)
5233
+ {
5234
+ // Memory arrays are initialized using calldatacopy past the size of the calldata.
5235
+ // This test checks that it also works in the constructor context.
5236
+ char const * sourceCode = R"(
5237
+ contract C {
5238
+ bool public success;
5239
+ constructor() public {
5240
+ // Make memory dirty.
5241
+ assembly {
5242
+ for { let i := 0 } lt(i, 64) { i := add(i, 1) } {
5243
+ mstore(msize(), not(0))
5244
+ }
5245
+ }
5246
+ uint16[3] memory c;
5247
+ require(c[0] == 0 && c[1] == 0 && c[2] == 0);
5248
+ uint16[] memory x = new uint16[](3);
5249
+ require(x[0] == 0 && x[1] == 0 && x[2] == 0);
5250
+ success = true;
5251
+ }
5252
+ }
5253
+ )" ;
5254
+ // Cannot run against yul optimizer because of msize
5255
+ if (!m_optimiserSettings.runYulOptimiser )
5256
+ {
5257
+ compileAndRun (sourceCode, 0 , " C" );
5258
+ ABI_CHECK (callContractFunction (" success()" ), encodeArgs (u256 (1 )));
5259
+ }
5260
+ }
5261
+
5205
5262
BOOST_AUTO_TEST_CASE (mutex)
5206
5263
{
5207
5264
char const * sourceCode = R"(
0 commit comments