My current (patched) build rebasd onto release/5.9
(built on Monterey macOS 12.6.5) of swift is failing to compile my custom standard library, trapping on the assertion...
Assertion failed: (Index < Length && "Invalid index!"), function operator[], file StringRef.h, line 231.
...building swift and llvm for debug, I see this stack trace...
* thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
frame #0: 0x00007ff81dffaffe libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007ff81e0311ff libsystem_pthread.dylib`pthread_kill + 263
frame #2: 0x00007ff81df7cd24 libsystem_c.dylib`abort + 123
frame #3: 0x00007ff81df7c0cb libsystem_c.dylib`__assert_rtn + 314
* frame #4: 0x00000001090bd743 swift-frontend`llvm::GlobalValue::getGlobalIdentifier(llvm::StringRef, llvm::GlobalValue::LinkageTypes, llvm::StringRef) (.cold.1) + 35
frame #5: 0x0000000107bc834d swift-frontend`llvm::GlobalValue::getGlobalIdentifier(llvm::StringRef, llvm::GlobalValue::LinkageTypes, llvm::StringRef) + 477
frame #6: 0x0000000107bc83b2 swift-frontend`llvm::GlobalValue::getGlobalIdentifier() const + 82
frame #7: 0x000000010595732c swift-frontend`llvm::GlobalValue::getGUID() const + 28
frame #8: 0x00000001076b0519 swift-frontend`llvm::ModuleSummaryIndex::getOrInsertValueInfo(llvm::GlobalValue const*) + 41
frame #9: 0x00000001076b02d4 swift-frontend`findRefEdges(llvm::ModuleSummaryIndex&, llvm::User const*, llvm::SetVector<llvm::ValueInfo, std::__1::vector<llvm::ValueInfo, std::__1::allocator<llvm::ValueInfo> >, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo, void> > >&, llvm::SmallPtrSet<llvm::User const*, 8u>&) + 820
frame #10: 0x00000001076ac2a9 swift-frontend`llvm::buildModuleSummaryIndex(llvm::Module const&, std::__1::function<llvm::BlockFrequencyInfo* (llvm::Function const&)>, llvm::ProfileSummaryInfo*, std::__1::function<llvm::StackSafetyInfo const* (llvm::Function const&)>) + 4841
frame #11: 0x00000001076af117 swift-frontend`llvm::ModuleSummaryIndexAnalysis::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 327
frame #12: 0x000000010565e2b8 swift-frontend`llvm::detail::AnalysisPassModel<llvm::Module, llvm::ModuleSummaryIndexAnalysis, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>::Invalidator>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 40
frame #13: 0x0000000107c55b1c swift-frontend`llvm::AnalysisManager<llvm::Module>::getResultImpl(llvm::AnalysisKey*, llvm::Module&) + 588
frame #14: 0x000000010595b4e2 swift-frontend`llvm::BitcodeWriterPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 130
frame #15: 0x0000000100a45487 swift-frontend`llvm::detail::PassModel<llvm::Module, llvm::BitcodeWriterPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(this=0x00006000002169c0, IR=0x000000014ac23d90, AM=0x0000000320d1d570) at PassManagerInternal.h:88:17
frame #16: 0x0000000107c52fdb swift-frontend`llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 347
frame #17: 0x00000001009e209a swift-frontend`swift::performLLVMOptimizations(Opts=0x0000000148821d48, Module=0x000000014ac23d90, TargetMachine=0x0000000178950000, out=0x0000000320d1ec68) at IRGen.cpp:406:20
frame #18: 0x00000001009e32ba swift-frontend`swift::performLLVM(Opts=0x0000000148821d48, Diags=0x00000001488223e8, DiagMutex=0x0000000320d1f308, HashGlobal=0x0000000000000000, Module=0x000000014ac23d90, TargetMachine=0x0000000178950000, OutputFilename=(Data = "bin/AVR/CoreFloatingPoint.bc\xff\xff\xff\xff", Length = 28), Stats=0x0000000000000000) at IRGen.cpp:595:3
frame #19: 0x0000000100a2308f swift-frontend`(anonymous namespace)::LLVMCodeGenThreads::Thread::run(this=0x0000000320d1ee50) at IRGen.cpp:1254:9
frame #20: 0x0000000100a20ab4 swift-frontend`(anonymous namespace)::LLVMCodeGenThreads::runMainThread(this=0x0000000320d1ef30) at IRGen.cpp:1313:16
frame #21: 0x00000001009e9d95 swift-frontend`performParallelIRGeneration(desc=IRGenDescriptor @ 0x0000000320d1fb10) at IRGen.cpp:1533:18
frame #22: 0x00000001009e8d0a swift-frontend`swift::performIRGeneration(M=0x000000014786de98, Opts=0x0000000148821d48, TBDOpts=0x00000001488221a8, SILMod=nullptr, ModuleName=(Data = "bin/AVR/CoreOperators.bc", Length = 24), PSPs=0x0000000320d20640, parallelOutputFilenames=(Data = "bin/AVR/CoreOperators.bc", Length = 94), outModuleHash=0x0000000320d1ff38) at IRGen.cpp:1557:5
frame #23: 0x00000001000e82b4 swift-frontend`generateIR(IRGenOpts=0x0000000148821d48, TBDOpts=0x00000001488221a8, SM=nullptr, PSPs=0x0000000320d20640, OutputFilename=(Data = "bin/AVR/CoreOperators.bc", Length = 24), MSF=swift::ModuleOrSourceFile @ 0x0000000320d1fdc8, HashGlobal=0x0000000320d1ff38, parallelOutputFilenames=(Data = "bin/AVR/CoreOperators.bc", Length = 94)) at FrontendTool.cpp:1457:12
frame #24: 0x00000001000e16fe swift-frontend`performCompileStepsPostSILGen(Instance=0x0000000148820e00, SM=nullptr, MSF=swift::ModuleOrSourceFile @ 0x0000000320d20050, PSPs=0x0000000320d20640, ReturnValue=0x0000000320d214e8, observer=0x0000000000000000) at FrontendTool.cpp:1780:19
frame #25: 0x00000001000e078c swift-frontend`swift::performCompileStepsPostSema(Instance=0x0000000148820e00, ReturnValue=0x0000000320d214e8, observer=0x0000000000000000) at FrontendTool.cpp:835:12
frame #26: 0x0000000100113eb3 swift-frontend`performAction(this=0x0000000320d212c0, Instance=0x0000000148820e00)::$_21::operator()(swift::CompilerInstance&) const at FrontendTool.cpp:1366:18
frame #27: 0x0000000100113e0d swift-frontend`bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(callable=13435540160, params=0x0000000148820e00)::$_21>(long, swift::CompilerInstance&) at STLFunctionalExtras.h:45:12
frame #28: 0x0000000100113249 swift-frontend`llvm::function_ref<bool (swift::CompilerInstance&)>::operator(this=0x0000000320d21218, params=0x0000000148820e00)(swift::CompilerInstance&) const at STLFunctionalExtras.h:68:12
frame #29: 0x00000001001123f8 swift-frontend`withSemanticAnalysis(Instance=0x0000000148820e00, observer=0x0000000000000000, cont=function_ref<bool (swift::CompilerInstance &)> @ 0x0000000320d21218, runDespiteErrors=false)>, bool) at FrontendTool.cpp:1236:10
frame #30: 0x000000010010ad68 swift-frontend`performAction(Instance=0x0000000148820e00, ReturnValue=0x0000000320d214e8, observer=0x0000000000000000) at FrontendTool.cpp:1362:12
frame #31: 0x00000001000e3767 swift-frontend`performCompile(Instance=0x0000000148820e00, ReturnValue=0x0000000320d214e8, observer=0x0000000000000000) at FrontendTool.cpp:1403:19
frame #32: 0x00000001000e25b0 swift-frontend`swift::performFrontend(Args=ArrayRef<const char *> @ 0x0000000320d216d0, Argv0="/Users/petoc01/Documents/Code/swift/build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-x86_64/bin/swift-frontend", MainAddr=0x0000000100035790, observer=0x0000000000000000) at FrontendTool.cpp:2325:19
frame #33: 0x00000001000369e4 swift-frontend`run_driver(ExecName=(Data = "swift-frontend", Length = 14), argv=ArrayRef<const char *> @ 0x0000000320d232c8, originalArgv=const llvm::ArrayRef<const char *> @ 0x0000000320d232b8) at driver.cpp:202:14
frame #34: 0x0000000100035e39 swift-frontend`swift::mainEntry(argc_=325, argv_=0x0000000320d25708) at driver.cpp:424:10
frame #35: 0x00000001000354b2 swift-frontend`main(argc_=325, argv_=0x0000000320d25708) at driver.cpp:20:10
frame #36: 0x000000021cc7552e dyld`start + 462
In GlobalValue::getGlobalIdentifier
it's easy to see the problem...
frame #5: 0x000000010bdd56ed swift-frontend`llvm::GlobalValue::getGlobalIdentifier(Name=(Data = "", Length = 0), Linkage=PrivateLinkage, FileName=(Data = "bin/AVR/CoreOperators.bc", Length = 24)) at Globals.cpp:163:7
160 // Value names may be prefixed with a binary '1' to indicate
161 // that the backend should not modify the symbols due to any platform
162 // naming convention. Do not include that '1' in the PGO profile name.
-> 163 if (Name[0] == '\1')
164 Name = Name.substr(1);
165
166 std::string NewName = std::string(Name);
(lldb) e Name
(llvm::StringRef) $0 = (Data = "", Length = 0)
...higher up the stack, somehow IRGen has created this rather broken looking GlobalValue
which is then crashing an llvm analysis pass...
frame #8: 0x000000010b165657 swift-frontend`llvm::ModuleSummaryIndex::getOrInsertValueInfo(this=0x000000033739edc0, GV=0x0000600002c6a2a0) at ModuleSummaryIndex.h:1352:39
1349 /// Return a ValueInfo for \p GV and mark it as belonging to GV.
1350 ValueInfo getOrInsertValueInfo(const GlobalValue *GV) {
1351 assert(HaveGVs);
-> 1352 auto VP = getOrInsertValuePtr(GV->getGUID());
1353 VP->second.U.GV = GV;
1354 return ValueInfo(HaveGVs, VP);
1355 }
(lldb) e GV->dump()
@0 = private unnamed_addr constant [1 x i16] [i16 1]
Can anyone give me some advice how I can track down what is creating this node in the IR higher up? Is there any valid reason to have a GlobalValue with an empty (""
) name? If not, can I add an extra assert somewhere to try and trap the code that's creating this? Or even a clever breakpoint in lldb?
I'm a bit stumped, sorry if I'm missing something obvious. Thank you for any help or advice that anyone can give.
Carl