Skip to content

Commit

Permalink
Merge pull request #3447 from fulldecent/patch-7
Browse files Browse the repository at this point in the history
Fix new Solidity warnings, for #3379
  • Loading branch information
chriseth authored Jan 29, 2018
2 parents bd3692f + b517ebb commit cc1c461
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ idea is that assembly libraries will be used to enhance the language in such way
pragma solidity ^0.4.0;
library GetCode {
function at(address _addr) public returns (bytes o_code) {
function at(address _addr) public view returns (bytes o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
Expand All @@ -78,20 +78,20 @@ you really know what you are doing.

.. code::
pragma solidity ^0.4.12;
pragma solidity ^0.4.16;
library VectorSum {
// This function is less efficient because the optimizer currently fails to
// remove the bounds checks in array access.
function sumSolidity(uint[] _data) public returns (uint o_sum) {
function sumSolidity(uint[] _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i)
o_sum += _data[i];
}
// We know that we only access the array in bounds, so we can avoid the check.
// 0x20 needs to be added to an array because the first slot contains the
// array length.
function sumAsm(uint[] _data) public returns (uint o_sum) {
function sumAsm(uint[] _data) public view returns (uint o_sum) {
for (uint i = 0; i < _data.length; ++i) {
assembly {
o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
Expand All @@ -100,7 +100,7 @@ you really know what you are doing.
}
// Same as above, but accomplish the entire code within inline assembly.
function sumPureAsm(uint[] _data) public returns (uint o_sum) {
function sumPureAsm(uint[] _data) public view returns (uint o_sum) {
assembly {
// Load the length (first 32 bytes)
let len := mload(_data)
Expand Down Expand Up @@ -459,10 +459,10 @@ be just ``0``, but it can also be a complex functional-style expression.

.. code::
pragma solidity ^0.4.0;
pragma solidity ^0.4.16;
contract C {
function f(uint x) public returns (uint b) {
function f(uint x) public view returns (uint b) {
assembly {
let v := add(x, 1)
mstore(0x80, v)
Expand Down Expand Up @@ -710,10 +710,10 @@ Example:
We will follow an example compilation from Solidity to desugared assembly.
We consider the runtime bytecode of the following Solidity program::

pragma solidity ^0.4.0;
pragma solidity ^0.4.16;

contract C {
function f(uint x) public returns (uint y) {
function f(uint x) public pure returns (uint y) {
y = 1;
for (uint i = 0; i < x; i++)
y = 2 * y;
Expand Down

0 comments on commit cc1c461

Please sign in to comment.