“http://forums.swift.org/” “http://forums.swift.org/”——————|—————–|

Attachment: [Download](https://user-images.githubusercontent.com/2727770/164963035-2fd77d6b-9cbd-42bd-8d00-6e657896471f.gz)

Environment

Linux with release no-assertions build of swift with the above mentioned patches applied.Makefile

Additional Detail from JIRA

“http://forums.swift.org/” “http://forums.swift.org/”——————|—————–“http://forums.swift.org/”Votes | 1 “http://forums.swift.org/”Component/s | Compiler “http://forums.swift.org/”Labels | Bug, CompilerCrash “http://forums.swift.org/”Assignee | None “http://forums.swift.org/”Priority | Medium |

md5: f3b2ee52855e03d9f071a263a4b97f47

**Issue Description:**

I am trying to compile a large array (70.000 elements) with a release no-assertions build.

Swift stops with:

:0: error: unable to execute command: Segmentation fault
:0: error: compile command failed due to signal 11 (use -v to see invocation)

The stack trace is:

– thread #1, name = ‘swift’, stop reason = signal SIGSEGV: invalid address (fault address: 0xffffffffffffff22)

– frame #0: 0x0000000000d0c321 swift`(anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2017
frame #1: 0x0000000000d0d1b0 swift`(anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 816
frame #2: 0x0000000000d0bce0 swift`(anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 416
frame #3: 0x0000000000d075a0 swift`(anonymous namespace)::ArgEmitter::emitTopLevel(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 4656
frame #4: 0x0000000000d156c6 swift`(anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional const&, swift::ImportAsMemberStatus) && + 710
frame #5: 0x0000000000d15130 swift`(anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper, llvm::Optional const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl&, llvm::Optional&, swift::CanTypeWrapper&) + 1200
frame #6: 0x0000000000d00a42 swift`(anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3202
frame #7: 0x0000000000cffd1a swift`swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 2218
frame #8: 0x0000000000ca8a83 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 83
frame #9: 0x0000000000caae08 swift`swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 9176
frame #10: 0x0000000000c9eba1 swift`swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional) + 289
frame #11: 0x0000000000c93288 swift`swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 280
frame #12: 0x0000000000c9333d swift`swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
frame #13: 0x0000000000c724af swift`swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 255
frame #14: 0x0000000000c72b3b swift`swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 811
frame #15: 0x0000000000c736d1 swift`swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 273
frame #16: 0x0000000000c73b77 swift`swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&) + 23
frame #17: 0x00000000004ca182 swift`performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7410
frame #18: 0x00000000004c77be swift`swift::performFrontend(llvm::ArrayRef, char const*, void*, swift::FrontendObserver*) + 3454
frame #19: 0x000000000047f01e swift`main + 670
frame #20: 0x00007ffff73f009b libc.so.6`__libc_start_main(main=(swift`main), argc=13, argv=0x00007fffffffdd88, init=, fini=, rtld_fini=, stack_end=0x00007fffffffdd78) at libc-start.c:308:16
frame #21: 0x000000000047d5aa swift`_start + 42

I applied the two patches from @atrick fixing quadratic behaviour in the inliner:

His comment was:

This is the SILGen assert for the initialization of 70k array elements:
Assertion failed: (params.size() == labels.size()), function relabelParams, file /s/sown/swift/lib/AST/ASTContext.cpp, line 3784.
This should be filed as a separate bug against SILGen. Someone may have thought it was ok to use 16 bits for a param index.

@slavapestov might be interested since he added this assertion.

I used the attached Makefile to generate the source.

Read More