mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
30 lines
533 B
Solidity
30 lines
533 B
Solidity
|
function safe() pure returns (uint256 x) {
|
||
|
assembly { x := 42 }
|
||
|
/// @solidity memory-safe-assembly
|
||
|
assembly { mstore(0, 0) }
|
||
|
}
|
||
|
function unsafe() pure returns (uint256 x) {
|
||
|
assembly { pop(mload(0)) }
|
||
|
}
|
||
|
contract C {
|
||
|
constructor() {
|
||
|
unsafe();
|
||
|
}
|
||
|
function f() public pure {
|
||
|
safe();
|
||
|
}
|
||
|
}
|
||
|
contract D {
|
||
|
constructor() {
|
||
|
safe();
|
||
|
}
|
||
|
function f() public pure {
|
||
|
unsafe();
|
||
|
}
|
||
|
}
|
||
|
// ----
|
||
|
// :C(creation) false
|
||
|
// :C(runtime) true
|
||
|
// :D(creation) true
|
||
|
// :D(runtime) false
|