Bug 171 - LLVM build fails with assertion
Summary: LLVM build fails with assertion
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-08-04 02:47 UTC by rumination.xamarin
Modified: 2011-08-09 16:23 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Build output (148.90 KB, text/plain)
2011-08-04 02:47 UTC, rumination.xamarin
Details
MonoDevelop solution with LLVM-offending source code (10.09 KB, application/zip)
2011-08-08 10:13 UTC, rumination.xamarin
Details
assembly causing the LLVM crash (5.00 KB, application/octet-stream)
2011-08-08 10:50 UTC, Sebastien Pouliot
Details
unlinked monotouch.dll (2.22 MB, application/octet-stream)
2011-08-09 13:27 UTC, Sebastien Pouliot
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description rumination.xamarin 2011-08-04 02:47:45 UTC
Created attachment 64 [details]
Build output

From the build output pane:

Error 1: mtouch failed with the following message:
Assertion failed: (i*2 < getNumOperands() && "Invalid value number!"), function getIncomingValue, file /sources/llvm/include/llvm/Instructions.h, line 1849.
0  opt               0x004f4568 llvm::PrettyStackTraceString::~PrettyStackTraceString() + 12504
1  opt               0x004f5647 llvm::PrettyStackTraceString::~PrettyStackTraceString() + 16823
2  libSystem.B.dylib 0x974a605b _sigtramp + 43
3  libSystem.B.dylib 0xffffffff _sigtramp + 1756733391
4  opt               0x004f4abc llvm::PrettyStackTraceString::~PrettyStackTraceString() + 13868
5  opt               0x001cdab3 llvm::PredIteratorCache::GetPreds(llvm::BasicBlock*) + 11187
6  opt               0x001ce2da llvm::PredIteratorCache::GetPreds(llvm::BasicBlock*) + 13274
7  opt               0x001fe823 llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 62083
8  opt               0x001fd37b llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 56795
9  opt               0x001fdcee llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 59214
10 opt               0x00109fe9 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type const*, llvm::Twine const&) + 953
11 opt               0x0010b9b8 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type const*, llvm::Twine const&) + 7560
12 opt               0x0047422f llvm::BasicBlockPass::~BasicBlockPass() + 32447
13 opt               0x0047433c llvm::BasicBlockPass::~BasicBlockPass() + 32716
14 opt               0x00475ecf llvm::BasicBlockPass::~BasicBlockPass() + 39775
15 opt               0x0047619c llvm::BasicBlockPass::~BasicBlockPass() + 40492
16 opt               0x0047629b llvm::BasicBlockPass::~BasicBlockPass() + 40747
17 opt               0x0000f324 llvm::scc_iterator<llvm::CallGraphNode*, llvm::GraphTraits<llvm::CallGraphNode*> >::GetNextSCC() + 22084
18 opt               0x000022c5
Stack dump:
0.	Program arguments: /Developer/MonoTouch/LLVM/bin/opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -basiccg -prune-eh -inline -functionattrs -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -loopsimplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loopsimplify -lcssa -iv-users -indvars -loop-deletion -loopsimplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o /var/folders/mx/mxNdVu+1GWSEN888lPVUJ++++TI/-Tmp-/tmp34e17d49.tmp/Rumination.Crux.dll.6.s.opt.bc /var/folders/mx/mxNdVu+1GWSEN888lPVUJ++++TI/-Tmp-/tmp34e17d49.tmp/Rumination.Crux.dll.6.s.bc 
1.	Running pass 'Function Pass Manager' on module '/var/folders/mx/mxNdVu+1GWSEN888lPVUJ++++TI/-Tmp-/tmp34e17d49.tmp/Rumination.Crux.dll.6.s.bc'.
2.	Running pass 'Simplify the CFG' on function '@Rumination.Crux_Rumination_Crux_Puzzle_UnpackGrid_byte___System_Text_Encoding'
 (1) (Rumination.Crux.iOS.Universal)

This is in MonoTouch 4.0.4.1. As this is the first time I've tried building with LLVM I can't say whether it ever worked on my solution.

The method signature of what it appears to be choking on is:
public static GridCell[,] UnpackGrid(byte[] gridData, System.Text.Encoding encoding)
(where obviously GridCell is my own class)

I've attached the complete build output.
Comment 1 Sebastien Pouliot 2011-08-04 15:07:48 UTC
Can you share (privately if needed) the assembly that contain this method so we can try to duplicate the issue ?

Also have you tried different linking strategy (e.g. --linkskip=Rumination.Crux.dll) to see if this always occurs (or is linker-related) ?
Comment 2 rumination.xamarin 2011-08-04 17:32:56 UTC
The original attempt was with the linker setting at "Link SDK assemblies only". Per your suggestion I tried "Link all assemblies", and I also tried adding "--linkskip=Rumination.Crux.dll" to the mtouch args. Same result all around. I'm afraid I don't have enough knowledge of mtouch or LLVM under the hood to make informed decisions about changing linking strategies. If you have targeted suggestions for me to try I'd be more than happy to help work this out.

I sent you the assembly by email.
Comment 3 Sebastien Pouliot 2011-08-05 08:46:33 UTC
I'm beginning to suspect 4.0.4.1 was a bad build wrt the LLVM support. Could you try the next steps in a terminal window and post your result ?

$ mkdir tmp

$ cd tmp

$ cp /Developer/MonoTouch/usr/lib/mono/2.1/*.dll .

$ cp mscorlib-runtime.dll mscorlib.dll

$ cp '''path-to-your-code'''/Rumination.Crux.dll .

$ MONO_PATH=. /Developer/MonoTouch/usr/bin/arm-darwin-mono --llvm --aot=mtriple=armv6-darwin,nimt-trampolines=2048,full,static,asmonly,nodebug,llvm-path=/Developer/MonoTouch/LLVM/bin/,outfile=Rumination.Crux.dll.6.s Rumination.Crux.dll


Here's what I get (i.e. no crash). This should be identical to buiding with --nolink

Mono Ahead of Time compiler - compiling assembly /Users/sebastienpouliot/src/tmp/Rumination.Crux.dll
Executing opt: /Developer/MonoTouch/LLVM/bin/opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -basiccg -prune-eh -inline -functionattrs -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -loopsimplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loopsimplify -lcssa -iv-users -indvars -loop-deletion -loopsimplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o Rumination.Crux.dll.6.s.opt.bc Rumination.Crux.dll.6.s.bc
Executing llc: /Developer/MonoTouch/LLVM/bin/llc -mattr=+v6 -asm-verbose=false -mtriple=armv6-darwin -relocation-model=static -unwind-tables -disable-gnu-eh-frame -enable-mono-eh-frame -o Rumination.Crux.dll.6.s Rumination.Crux.dll.6.s.opt.bc
Code: 1900 Info: 1535 Ex Info: 1842 Unwind Info: 125 Class Info: 8778 PLT: 12 GOT Info: 771 GOT: 316 Offsets: 20388
Output file: 'Rumination.Crux.dll.6.s'.
Linking symbol: '_mono_aot_module_Rumination_Crux_info'.
Compiled 602 out of 2283 methods (26%)
Methods compiled with LLVM: 591 (25%)
Methods without GOT slots: 516 (22%)
Direct calls: 0 (100%)
JIT time: 93 ms, Generation time: 842 ms, Assembly+Link time: 0 ms.


If it works (like me) then try to rebuild your solution with "Don't link". Thanks!
Comment 4 rumination.xamarin 2011-08-08 09:23:49 UTC
I got the same result as you in reproducing those steps:

Mono Ahead of Time compiler - compiling assembly /Users/jrmorgan/Desktop/tmp/Rumination.Crux.dll
Executing opt: /Developer/MonoTouch/LLVM/bin/opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -basiccg -prune-eh -inline -functionattrs -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -loopsimplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loopsimplify -lcssa -iv-users -indvars -loop-deletion -loopsimplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o Rumination.Crux.dll.6.s.opt.bc Rumination.Crux.dll.6.s.bc
Executing llc: /Developer/MonoTouch/LLVM/bin/llc -mattr=+v6 -asm-verbose=false -mtriple=armv6-darwin -relocation-model=static -unwind-tables -disable-gnu-eh-frame -enable-mono-eh-frame -o Rumination.Crux.dll.6.s Rumination.Crux.dll.6.s.opt.bc
Code: 1900 Info: 1535 Ex Info: 1842 Unwind Info: 125 Class Info: 8778 PLT: 12 GOT Info: 771 GOT: 316 Offsets: 20388
Output file: 'Rumination.Crux.dll.6.s'.
Linking symbol: '_mono_aot_module_Rumination_Crux_info'.
Compiled 602 out of 2283 methods (26%)
Methods compiled with LLVM: 591 (25%)
Methods without GOT slots: 516 (22%)
Direct calls: 0 (100%)
JIT time: 119 ms, Generation time: 1206 ms, Assembly+Link time: 0 ms.

However, when I tried rebuilding the solution with "Don't link" I get the same error as initially reported.
Comment 5 rumination.xamarin 2011-08-08 10:11:38 UTC
I've distilled this to a test case. See attached solution.
Comment 6 rumination.xamarin 2011-08-08 10:13:36 UTC
Created attachment 86 [details]
MonoDevelop solution with LLVM-offending source code
Comment 7 Sebastien Pouliot 2011-08-08 10:33:49 UTC
ok, I do get a crash inside LLVM with the attached solution...


AOT Compilation exited with code 1, command:
MONO_PATH=/Users/sebastienpouliot/Downloads/TestApp/TestApp/bin/iPhone/Release/TestApp.app /Developer/MonoTouch/usr/bin/arm-darwin-mono --llvm --aot=mtriple=armv6-darwin,full,static,asmonly,nodebug,llvm-path=/Developer/MonoTouch/LLVM/bin/,outfile=/var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp70219873.tmp/TestApp.exe.6.s "/Users/sebastienpouliot/Downloads/TestApp/TestApp/bin/iPhone/Release/TestApp.app/TestApp.exe"
Assertion failed: (i*2 < getNumOperands() && "Invalid value number!"), function getIncomingValue, file /Developer/MonoTouch/Source/llvm/include/llvm/Instructions.h, line 1849.
0  opt               0x004f3ec8 llvm::PrettyStackTraceString::~PrettyStackTraceString() + 12504
1  opt               0x004f4fa7 llvm::PrettyStackTraceString::~PrettyStackTraceString() + 16823
2  libSystem.B.dylib 0x915ac05b _sigtramp + 43
3  libSystem.B.dylib 0xffffffff _sigtramp + 1856323535
4  opt               0x004f441c llvm::PrettyStackTraceString::~PrettyStackTraceString() + 13868
5  opt               0x001cd413 llvm::PredIteratorCache::GetPreds(llvm::BasicBlock*) + 11187
6  opt               0x001cdc3a llvm::PredIteratorCache::GetPreds(llvm::BasicBlock*) + 13274
7  opt               0x001fe183 llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 62083
8  opt               0x001fccdb llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 56795
9  opt               0x001fd64e llvm::SSAUpdaterImpl<llvm::SSAUpdater>::FindAvailableVals(llvm::SmallVectorImpl<llvm::SSAUpdaterImpl<llvm::SSAUpdater>::BBInfo*>*) + 59214
10 opt               0x00109949 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type const*, llvm::Twine const&) + 953
11 opt               0x0010b318 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type const*, llvm::Twine const&) + 7560
12 opt               0x00473b8f llvm::BasicBlockPass::~BasicBlockPass() + 32447
13 opt               0x00473c9c llvm::BasicBlockPass::~BasicBlockPass() + 32716
14 opt               0x0047582f llvm::BasicBlockPass::~BasicBlockPass() + 39775
15 opt               0x00475afc llvm::BasicBlockPass::~BasicBlockPass() + 40492
16 opt               0x00475bfb llvm::BasicBlockPass::~BasicBlockPass() + 40747
17 opt               0x0000ec84 llvm::scc_iterator<llvm::CallGraphNode*, llvm::GraphTraits<llvm::CallGraphNode*> >::GetNextSCC() + 22084
18 opt               0x00001c25
Stack dump:
0.	Program arguments: /Developer/MonoTouch/LLVM/bin/opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -basiccg -prune-eh -inline -functionattrs -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -loopsimplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loopsimplify -lcssa -iv-users -indvars -loop-deletion -loopsimplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o /var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp70219873.tmp/TestApp.exe.6.s.opt.bc /var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp70219873.tmp/TestApp.exe.6.s.bc 
1.	Running pass 'Function Pass Manager' on module '/var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp70219873.tmp/TestApp.exe.6.s.bc'.
2.	Running pass 'Simplify the CFG' on function '@TestApp_TestApp_Puzzle_UnpackGrid_byte___System_Text_Encoding'
Comment 8 Sebastien Pouliot 2011-08-08 10:50:05 UTC
Created attachment 87 [details]
assembly causing the LLVM crash
Comment 9 Sebastien Pouliot 2011-08-09 13:27:20 UTC
Created attachment 99 [details]
unlinked monotouch.dll
Comment 10 Zoltan Varga 2011-08-09 15:43:05 UTC
Should be fixed on the 2.10 branch by 7ae2112edc2b5651f121b6a5b3dcef38d00c279f.
Comment 11 Sebastien Pouliot 2011-08-09 15:49:10 UTC
will test and confirm, thanks!
Comment 12 Sebastien Pouliot 2011-08-09 16:23:37 UTC
The build works (without issue) using Zoltan's patch.
Thanks for the test case!

p.s. I don't think 4.1 has been branched before my commit (I'll update if I'm proven wrong ;-) so you should be able to use LLVM on your solution with MonoTouch 4.1.