Solidity has had a bug for a long time on MacOS that only occurs in release builds and is related to the move constructor or move-assignment operator of std::map. It might be related to some versions of the standard library only and migth also occur only for certain versions of the compiler. This bug report is one instance of it.
Original description:
Just about every contract I have tried with the --ast option has given sigsegv.
$ solc --ast node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
node_modules/zeppelin-solidity/contracts/math/SafeMath.sol:9:3: Warning: Function state mutability can be restricted to pure
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
^
Spanning multiple lines.
node_modules/zeppelin-solidity/contracts/math/SafeMath.sol:15:3: Warning: Function state mutability can be restricted to pure
function div(uint256 a, uint256 b) internal constant returns (uint256) {
^
Spanning multiple lines.
node_modules/zeppelin-solidity/contracts/math/SafeMath.sol:22:3: Warning: Function state mutability can be restricted to pure
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
^
Spanning multiple lines.
node_modules/zeppelin-solidity/contracts/math/SafeMath.sol:27:3: Warning: Function state mutability can be restricted to pure
function add(uint256 a, uint256 b) internal constant returns (uint256) {
^
Spanning multiple lines.
Segmentation fault: 11
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.4.20+commit.3155dd80.Darwin.appleclang
Trying on 0.4.21
I have confirmed it still happens on 0.4.21.
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.4.21+commit.dfe3193c.Darwin.appleclang
$ solc --ast ../pub/contracts/pub.sol
Segmentation fault: 11
@wjmelements Can you give us more information about your setup? OS version, C++ compiler version used to build solc, etc.? So far I cannot reproduce your issue.
$ clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ uname -a
Darwin Williams-MacBook-Pro.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64
@wjmelements Thanks! Would it be possible for to update your XCode version to 9.0.0 and then try to reproduce again? That's the only obvious difference between your and my setup, and I couldn't reproduce this issue so far.
@wjmelements can you run it with lldb and paste the stack trace?
* thread #1: tid = 0x5d15, 0x00000001000188d3 solc`std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >::__move_assign(std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >&, std::__1::integral_constant<bool, true>) + 71, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00000001000188d3 solc`std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >::__move_assign(std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >&, std::__1::integral_constant<bool, true>) + 71
solc`std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >::__move_assign:
-> 0x1000188d3 <+71>: vmovaps %xmm0, (%rcx)
0x1000188d7 <+75>: jmp 0x1000188dc ; <+80>
0x1000188d9 <+77>: movq %r15, (%rbx)
0x1000188dc <+80>: addq $0x8, %rsp
(lldb) bt
* thread #1: tid = 0x793c, 0x00000001000188d3 solc`std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >::__move_assign(std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >&, std::__1::integral_constant<bool, true>) + 71, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
* frame #0: 0x00000001000188d3 solc`std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >::__move_assign(std::__1::__tree<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::__map_value_compare<dev::solidity::ASTNode const*, std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption>, std::__1::less<dev::solidity::ASTNode const*>, true>, std::__1::allocator<std::__1::__value_type<dev::solidity::ASTNode const*, dev::eth::GasMeter::GasConsumption> > >&, std::__1::integral_constant<bool, true>) + 71
frame #1: 0x000000010000b705 solc`dev::solidity::CommandLineInterface::handleAst(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 1467
frame #2: 0x000000010000c9dd solc`dev::solidity::CommandLineInterface::outputCompilationResults() + 57
frame #3: 0x000000010000c767 solc`dev::solidity::CommandLineInterface::actOnInput() + 65
frame #4: 0x000000010001a25a solc`main + 175
frame #5: 0x00007fff5badf115 libdyld.dylib`start + 1
__move_assign inside std::__tree - it is the heisenbug.
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__This issue now has a funding of 200.001 DAI (200.0 USD @ $1.0/DAI) attached to it.__
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__Work has been started__.
has committed to working on this project to be completed 4Â months, 4Â weeks from now.
@gdipri01, __please see the below comments / questions regarding approach for this ticket from the bounty hunter(s):__
solc --ast node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
Warning: This is a pre-release compiler version, please do not use it in production.
[1] 97139 segmentation fault solc --ast node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
Will investigate on my environment first.
@alibabe Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days
@chriseth could you give some more explanation on
__move_assign inside std::__tree - it is the heisenbu
@alibabe it might be related to a different version of the standard library being used at compile time (for the headers) and at link time. It only happens on mac os and only for a release build. I cannot tell much more apart from this, we investigated this bug for a long time but could not find anything.
To clarify more, I got seg fault on all of the files I tested. Does this happen to you as well? Or it only happens on node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
Just about every contract I have tried with the --ast option has given sigsegv.
Seems not only --ast has this issue, this bug happens to --ast-json and --ast-compact-json for me as well
Yes, the bug is either a linking / compiler configuration problem, a bug in the stdlib of macos or a fundamental problem about how we use std::map in general.
This issue seems is a very similar bug: https://github.com/CleverRaven/Cataclysm-DDA/issues/17714
Any insights?
From that issue:
This diff fixes #17898, wherein the release (but not debug) build would crash if compiled with Clang on OS X. Apparently Clang, if made to optimize for release, doesn't auto-generate a function that is expected to exist (and that GCC does generate in release); the diff just manually implements that function to ensure that it's present.
In their case, it is a copy assignment operator, so it could help to manually add move assignment operators for some of our classes, but somehow I have the feeling that if that is really the problem, a compiler update should have been made in the meantime...
I tried adding customized move assignment operator and copy assignment operator to GasConsumption and ASTNode with no luck. However, I am able to fix the issue by assigning the result of breakToStatementLevel to a local variable, then assign it back to gasCosts.
Let me know if this is enough
@alibabe Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days
@chriseth @alibabe Please ignore the notice from @weberV, it's a bug on our side we're actively tracking! Apologies for the inconvenience.
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
@alibabe due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days
Still WIP. Also updated the pull request.
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__Work for 200.001 DAI (200.0 USD @ $1.0/DAI) has been submitted by__:
@gdipri01 please take a look at the submitted work:
Hey,
I am trying to use solc --ast contracts/GnosisSafe.sol (https://www.github.com/gnosis/safe-contract) and receive a segmentation fault.
I am using solc 0.5.0+commit.1d4f565a.Darwin.appleclang (installed via brew) and other outputs work(e.g. solc --bin or solc --asm). Also for other contracts it is possible to perform this action (tested with solc --ast /=/ contracts/base/BaseSafe.sol).
I am running MacOS Mojave (10.14.1)
Is this related to this bug or should I open a new one?
Most helpful comment
Issue Status: 1. Open 2. Started 3. Submitted 4. Done
__Work has been started__.
@alibabe
has committed to working on this project to be completed 4Â months, 4Â weeks from now.
@gdipri01, __please see the below comments / questions regarding approach for this ticket from the bounty hunter(s):__
solc --ast node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
Warning: This is a pre-release compiler version, please do not use it in production.
[1] 97139 segmentation fault solc --ast node_modules/zeppelin-solidity/contracts/math/SafeMath.sol
Will investigate on my environment first.