Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12192] Compiler crash in SILGen in Xcode 11.4 beta 1 #54617

Open
BasThomas opened this issue Feb 12, 2020 · 2 comments
Open

[SR-12192] Compiler crash in SILGen in Xcode 11.4 beta 1 #54617

BasThomas opened this issue Feb 12, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage

Comments

@BasThomas
Copy link
Contributor

Previous ID SR-12192
Radar rdar://problem/59496033
Original Reporter @BasThomas
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, SILGen
Assignee None
Priority Medium

md5: 95ad63d11ff49c45c24b991bf48447d5

Issue Description:

The following code fixes a compiler crash in Xcode 11.4 beta 1, as seen in this project/pull request.

Code before, crashing

private func load(fromPath path: String) -> Loaded? {
    let url = CFURLCreateWithFileSystemPath(
        kCFAllocatorDefault,
        path as CFString,
        .cfurlposixPathStyle,
        false
    )

    guard let font = url.flatMap(CGDataProvider.init).flatMap(CGFont.init) else {
        return nil
    }

    return CTFontCreateWithGraphicsFont(font, CGFloat(size), nil, nil)
}

Code after, not crashing

private func load(fromPath path: String) -> Loaded? {
    guard
        let url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path as CFString, .cfurlposixPathStyle, false),
        let provider = CGDataProvider(url: url),
        let font = CGFont(provider)
    else {
        return nil
    }

    return CTFontCreateWithGraphicsFont(font, CGFloat(size), nil, nil)
}

Moving away from mapping from URL to provider to font, opting to use guard let constructs for each resolves the crash.

This is the segmentation fault:

1.  Apple Swift version 5.2 (swiftlang-1103.0.22 clang-1103.0.22)
2.  While emitting IR SIL function "@$sSo17CGDataProviderRefa3urlABSgSo8CFURLRefa_tcfcTO".
 for 'init(url:)' (in module 'CoreGraphics')
0  swift                    0x00000001073079b3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000107307170 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6b02c42d _sigtramp + 29
3  libsystem_malloc.dylib   0x00007fff6afeb656 tiny_malloc_should_clear + 272
4  swift                    0x0000000102c735fe swift::irgen::NativeConventionSchema::mapIntoNative(swift::irgen::IRGenModule&, swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::SILType, bool) const + 3758
5  swift                    0x0000000102c72417 swift::irgen::addNativeArgument(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SILParameterInfo, swift::irgen::Explosion&, bool) + 935
6  swift                    0x0000000102c760c1 swift::irgen::CallEmission::setArgs(swift::irgen::Explosion&, bool, swift::irgen::WitnessMetadata*) + 801
7  swift                    0x0000000102e3cd16 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2294
8  swift                    0x0000000102e1bb83 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9027
9  swift                    0x0000000102ccbde6 swift::irgen::IRGenerator::emitLazyDefinitions() + 8822
10 swift                    0x0000000102df8604 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1284
11 swift                    0x0000000102be2b5c performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4252
12 swift                    0x0000000102bd920e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 61406
13 swift                    0x0000000102b4a283 main + 1299
14 libdyld.dylib            0x00007fff6ae337fd start + 1
15 libdyld.dylib            0x000000000000005c start + 2501691488
error: Segmentation fault: 11 (in target 'Splash' from project 'Splash')
@theblixguy
Copy link
Collaborator

On master:

Assertion failed: (fn->getLoweredFunctionType() == constantType), function getOrCreateFunction, file /Users/suyashsrijan/Documents/swift-src/swift/lib/SIL/SILFunctionBuilder.cpp, line 115.
Stack dump:
0.  Program arguments: /Users/suyashsrijan/Documents/swift-src/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/Debug/bin/swift -frontend -interpret /Users/suyashsrijan/Desktop/test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test -- -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
1.  Swift version 5.2-dev (LLVM 88d1013b2e, Swift 8e8d195752)
2.  While evaluating request SILGenWholeModuleRequest(SIL Generation for module test)
3.  While emitting SIL for 'load(fromPath:)' (at /Users/suyashsrijan/Desktop/test.swift:5:9)
4.  While silgen emitFunction SIL function "@$s4test4load33_83378C430F65473055F1BD53F3ADCDB7LL8fromPathypSgSS_tF".
 for 'load(fromPath:)' (at /Users/suyashsrijan/Desktop/test.swift:5:9)
5.  While silgen emitCurryThunk SIL function "@$sSo17CGDataProviderRefa3urlABSgSo8CFURLRefa_tcfCTc".
 for 'init(url:)' (in module 'CoreGraphics')
6.  While silgen emitConstructor SIL function "@CGDataProviderCreateWithURL".
 for 'init(url:)' (in module 'CoreGraphics')
7.  While silgen emitForeignToNativeThunk SIL function "@$sSo17CGDataProviderRefa3urlABSgSo8CFURLRefa_tcfcTO".
 for 'init(url:)' (in module 'CoreGraphics')
0  swift                    0x0000000104581075 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000104580285 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000104581666 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff70da242d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000004c80 _sigtramp + 2401642608
5  libsystem_c.dylib        0x00007fff70c77a1c abort + 120
6  libsystem_c.dylib        0x00007fff70c76cd6 err + 0
7  swift                    0x0000000104899531 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) (.cold.3) + 33
8  swift                    0x000000010118d749 swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 1481
9  swift                    0x0000000100c1823d swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 381
10 swift                    0x0000000100cf3d04 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 532
11 swift                    0x0000000100c4f632 swift::Lowering::SILGenFunction::emitForeignToNativeThunk(swift::SILDeclRef) + 4242
12 swift                    0x0000000100cf2754 swift::Lowering::SILGenModule::emitForeignToNativeThunk(swift::SILDeclRef) + 324
13 swift                    0x0000000100cf3ce2 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 498
14 swift                    0x0000000100c9f103 swift::Lowering::SILGenFunction::emitSiblingMethodRef(swift::SILLocation, swift::SILValue, swift::SILDeclRef, swift::SubstitutionMap) + 435
15 swift                    0x0000000100c608af swift::Lowering::SILGenFunction::emitClassConstructorAllocator(swift::ConstructorDecl*) + 1519
16 swift                    0x0000000100c209ad swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_1::operator()(swift::SILFunction*) const + 237
17 swift                    0x0000000100c19051 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 1249
18 swift                    0x0000000100c18628 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 1384
19 swift                    0x0000000100cf3d04 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 532
20 swift                    0x0000000100cf2fdf swift::Lowering::SILGenFunction::emitCurryThunk(swift::SILDeclRef) + 2111
21 swift                    0x0000000100cf391e swift::Lowering::SILGenModule::emitCurryThunk(swift::SILDeclRef) + 254
22 swift                    0x0000000100cf3cf2 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 514
23 swift                    0x0000000100c2da6b (anonymous namespace)::Callee::getFnValue(swift::Lowering::SILGenFunction&, bool, llvm::Optional<swift::Lowering::ManagedValue>) const & + 955
24 swift                    0x0000000100c2a430 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3408
25 swift                    0x0000000100c29648 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2408
26 swift                    0x0000000100c8814c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 92
27 swift                    0x0000000100c7db96 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 54
28 swift                    0x0000000100c8eff0 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 28416
29 swift                    0x0000000100c7db96 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 54
30 swift                    0x0000000100c072c4 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 436
31 swift                    0x0000000100c68077 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 343
32 swift                    0x0000000100c0745f swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 159
33 swift                    0x0000000100c3a67b (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3627
34 swift                    0x0000000100c2715d (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 461
35 swift                    0x0000000100c394a3 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 147
36 swift                    0x0000000100c443b9 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 713
37 swift                    0x0000000100c43d1b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1787
38 swift                    0x0000000100c2a352 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3186
39 swift                    0x0000000100c29648 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2408
40 swift                    0x0000000100c8814c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 92
41 swift                    0x0000000100c7db96 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 54
42 swift                    0x0000000100c3a4e6 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3222
43 swift                    0x0000000100c2715d (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 461
44 swift                    0x0000000100c394a3 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 147
45 swift                    0x0000000100c443b9 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 713
46 swift                    0x0000000100c43d1b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1787
47 swift                    0x0000000100c2a352 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3186
48 swift                    0x0000000100c29648 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2408
49 swift                    0x0000000100c8814c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 92
50 swift                    0x0000000100c7ae6f swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 303
51 swift                    0x0000000100c6d24b swift::Lowering::SILGenFunction::emitStmtCondition(llvm::MutableArrayRef<swift::StmtConditionElement>, swift::Lowering::JumpDest, swift::SILLocation, swift::ProfileCounter, swift::ProfileCounter) + 459
52 swift                    0x0000000100ced3ba swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 11162
53 swift                    0x0000000100cf02e8 (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 232
54 swift                    0x0000000100cea815 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
55 swift                    0x0000000100ca10d4 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 372
56 swift                    0x0000000100c2048d swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_0::operator()(swift::SILFunction*) const + 237
57 swift                    0x0000000100c189d1 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 609
58 swift                    0x0000000100c1db63 (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 883
59 swift                    0x0000000100c1eb14 swift::SILGenWholeModuleRequest::evaluate(swift::Evaluator&, swift::SILGenDescriptor) const + 180
60 swift                    0x0000000100cea3d1 swift::SimpleRequest<swift::SILGenWholeModuleRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::SILGenDescriptor), (swift::CacheKind)0>::evaluateRequest(swift::SILGenWholeModuleRequest const&, swift::Evaluator&) + 33
61 swift                    0x0000000100c21d57 llvm::Expected<swift::SILGenWholeModuleRequest::OutputType> swift::Evaluator::getResultUncached<swift::SILGenWholeModuleRequest>(swift::SILGenWholeModuleRequest const&) + 343
62 swift                    0x0000000100c1ec8d swift::performSILGeneration(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 109
63 swift                    0x0000000100938889 performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 8681
64 swift                    0x0000000100935718 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4120
65 swift                    0x00000001008ceade main + 734
66 libdyld.dylib            0x00007fff70ba97fd start + 1
zsh: abort      ./swift ~/Desktop/test.swift -sdk $(xcrun --show-sdk-path)

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

4 participants