mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement uninitialized storage functions.
This commit is contained in:
parent
b6992d740a
commit
47794c1da4
@ -485,6 +485,7 @@ LinkerObject const& Assembly::assemble() const
|
|||||||
break;
|
break;
|
||||||
case Tag:
|
case Tag:
|
||||||
tagPos[(unsigned)i.data()] = ret.bytecode.size();
|
tagPos[(unsigned)i.data()] = ret.bytecode.size();
|
||||||
|
assertThrow(ret.bytecode.size() < 0xffffffffL, AssemblyException, "Tag too large.");
|
||||||
assertThrow(i.data() != 0, AssemblyException, "");
|
assertThrow(i.data() != 0, AssemblyException, "");
|
||||||
ret.bytecode.push_back((byte)Instruction::JUMPDEST);
|
ret.bytecode.push_back((byte)Instruction::JUMPDEST);
|
||||||
break;
|
break;
|
||||||
|
@ -44,6 +44,8 @@ namespace solidity {
|
|||||||
class CompilerContext
|
class CompilerContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
bool isCreationPhase() const { return m_mode == CompilationMode::Creation; }
|
||||||
|
|
||||||
void addMagicGlobal(MagicVariableDeclaration const& _declaration);
|
void addMagicGlobal(MagicVariableDeclaration const& _declaration);
|
||||||
void addStateVariable(VariableDeclaration const& _declaration, u256 const& _storageOffset, unsigned _byteOffset);
|
void addStateVariable(VariableDeclaration const& _declaration, u256 const& _storageOffset, unsigned _byteOffset);
|
||||||
void addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent = 0);
|
void addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent = 0);
|
||||||
|
@ -190,11 +190,11 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
|
|||||||
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
|
dynamic_cast<IntegerType const&>(*m_dataType).isSigned()
|
||||||
)
|
)
|
||||||
m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND;
|
m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND;
|
||||||
else if (
|
else if (FunctionType const* fun = dynamic_cast<decltype(fun)>(m_dataType))
|
||||||
m_dataType->category() == Type::Category::Function &&
|
{
|
||||||
dynamic_cast<FunctionType const&>(*m_dataType).location() == FunctionType::Location::External
|
if (fun->location() == FunctionType::Location::External)
|
||||||
)
|
|
||||||
CompilerUtils(m_context).splitExternalFunctionType(false);
|
CompilerUtils(m_context).splitExternalFunctionType(false);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
solAssert(m_dataType->sizeOnStack() == 1, "");
|
solAssert(m_dataType->sizeOnStack() == 1, "");
|
||||||
@ -236,12 +236,16 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
|
|||||||
// stack: value storage_ref cleared_value multiplier
|
// stack: value storage_ref cleared_value multiplier
|
||||||
utils.copyToStackTop(3 + m_dataType->sizeOnStack(), m_dataType->sizeOnStack());
|
utils.copyToStackTop(3 + m_dataType->sizeOnStack(), m_dataType->sizeOnStack());
|
||||||
// stack: value storage_ref cleared_value multiplier value
|
// stack: value storage_ref cleared_value multiplier value
|
||||||
if (
|
if (FunctionType const* fun = dynamic_cast<decltype(fun)>(m_dataType))
|
||||||
m_dataType->category() == Type::Category::Function &&
|
{
|
||||||
dynamic_cast<FunctionType const&>(*m_dataType).location() == FunctionType::Location::External
|
if (fun->location() == FunctionType::Location::External)
|
||||||
)
|
|
||||||
// Combine the two-item function type into a single stack slot.
|
// Combine the two-item function type into a single stack slot.
|
||||||
utils.combineExternalFunctionType(false);
|
utils.combineExternalFunctionType(false);
|
||||||
|
else
|
||||||
|
m_context <<
|
||||||
|
((u256(1) << (8 * m_dataType->storageBytes())) - 1) <<
|
||||||
|
Instruction::AND;
|
||||||
|
}
|
||||||
else if (m_dataType->category() == Type::Category::FixedBytes)
|
else if (m_dataType->category() == Type::Category::FixedBytes)
|
||||||
m_context
|
m_context
|
||||||
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(*m_dataType).numBytes()))
|
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(*m_dataType).numBytes()))
|
||||||
|
@ -7631,8 +7631,6 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail)
|
BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail)
|
||||||
{
|
{
|
||||||
// Storage default value of zero would be correct jump dest, this tests that
|
|
||||||
// that is properly handled.
|
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function() internal returns (uint) x;
|
function() internal returns (uint) x;
|
||||||
@ -7641,7 +7639,7 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function_in_detail)
|
|||||||
if (mutex > 0)
|
if (mutex > 0)
|
||||||
return 7;
|
return 7;
|
||||||
mutex = 1;
|
mutex = 1;
|
||||||
// If this test fails, it will jump to "0" and re-execute this function.
|
// Avoid re-executing this function if we jump somewhere.
|
||||||
x();
|
x();
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user