Note this doesn't actually work yet... and I need help fixing it.
With this patch I get:
Assertion failed: (cast<DISubprogram>(Scope)->describes(MF->getFunction())), function getOrCreateRegularScope, file /Users/jroelofs/workdir/mento/llvm/lib/CodeGen/LexicalScopes.cpp, line 160.
0 llc 0x000000010cd6f6ee llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
1 llc 0x000000010cd71389 PrintStackTraceSignalHandler(void*) + 25
2 llc 0x000000010cd6d989 llvm::sys::RunSignalHandlers() + 425
3 llc 0x000000010cd716c9 SignalHandler(int) + 345
4 libsystem_platform.dylib 0x00007fff9585f52a _sigtramp + 26
5 llc 0x000000010de14046 llvm::initializeUnifyFunctionExitNodesPass(llvm::PassRegistry&)::initialized + 84870
6 llc 0x000000010cd713ab raise + 27
7 llc 0x000000010cd71462 abort + 18
8 llc 0x000000010cd71441 __assert_rtn + 129
9 llc 0x000000010bf4a9ca llvm::LexicalScopes::getOrCreateRegularScope(llvm::DILocalScope const*) + 1930
10 llc 0x000000010bf49212 llvm::LexicalScopes::getOrCreateLexicalScope(llvm::DILocalScope const*, llvm::DILocation const*) + 98
11 llc 0x000000010bf4b3bc llvm::LexicalScopes::getOrCreateLexicalScope(llvm::DILocation const*) + 76
12 llc 0x000000010bf4ab0e llvm::LexicalScopes::getMachineBasicBlocks(llvm::DILocation const*, llvm::SmallPtrSetImpl<llvm::MachineBasicBlock const*>&) + 62
13 llc 0x000000010bf5859a (anonymous namespace)::UserValueScopes::dominates(llvm::MachineBasicBlock*) + 106
14 llc 0x000000010bf57744 (anonymous namespace)::UserValue::extendDef(llvm::SlotIndex, unsigned int, llvm::LiveRange*, llvm::VNInfo const*, llvm::SmallVectorImpl<llvm::SlotIndex>*, llvm::LiveIntervals&, llvm::MachineDominatorTree&, (anonymous namespace)::UserValueScopes&) + 1300
15 llc 0x000000010bf56a8c (anonymous namespace)::UserValue::computeIntervals(llvm::MachineRegisterInfo&, llvm::TargetRegisterInfo const&, llvm::LiveIntervals&, llvm::MachineDominatorTree&, (anonymous namespace)::UserValueScopes&) + 1404
16 llc 0x000000010bf540a6 (anonymous namespace)::LDVImpl::computeIntervals() + 742
17 llc 0x000000010bf525b4 (anonymous namespace)::LDVImpl::runOnMachineFunction(llvm::MachineFunction&) + 292
18 llc 0x000000010bf5230b llvm::LiveDebugVariables::runOnMachineFunction(llvm::MachineFunction&) + 187
19 llc 0x000000010c02472e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 110
20 llc 0x000000010c59fdad llvm::FPPassManager::runOnFunction(llvm::Function&) + 413
21 llc 0x000000010c5a00e5 llvm::FPPassManager::runOnModule(llvm::Module&) + 117
22 llc 0x000000010c5a0e3a (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 2010
23 llc 0x000000010c5a03cb llvm::legacy::PassManagerImpl::run(llvm::Module&) + 347
24 llc 0x000000010c5a1a81 llvm::legacy::PassManager::run(llvm::Module&) + 33
25 llc 0x000000010a8b9107 compileModule(char**, llvm::LLVMContext&) + 19239
26 llc 0x000000010a8b4576 main + 230
27 libdyld.dylib 0x00007fff96b215ad start + 1
28 libdyld.dylib 0x0000000000000012 start + 1766713958
But I don't know how to get ahold of the DIScope that it wants.
Also this feels really awkward... so if there's a better way to do this, please let me know.
What happens in insertDelcare when this ^ is nullptr?