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-7290] Segfault in "Lower Aggregate SIL Instructions to Multiple Scalar Operations" #49838

Open
tkrajacic opened this issue Mar 27, 2018 · 4 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 optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@tkrajacic
Copy link

Previous ID SR-7290
Radar None
Original Reporter @tkrajacic
Type Bug
Environment

Xcode 9.2, Swift 4.0.3

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, OptimizedOnly
Assignee None
Priority Medium

md5: 6ff76627c13d8bf3f16f74b0b3852774

Issue Description:

The following code produces a Segfault in optimized builds (Archiving an app)

extension Playload {
   public static func doSomething() -> (APIClient) -> Resource<Playload> {
      return { client in
         Resource<Playload>(…, parseJSON: { json in
            guard let dictionary = json as? JSONDictionary else { throw APIError.invalidData }
            do {
               var recoverableErrors: [SerializationError] = []
               let payload = Playload(json: dictionary)
               return .success(payload, withErrors: recoverableErrors)
            } catch let parsingError as JSONSerializableError {
               return .failure(parsingError)
            }
         })
      }
   }
}

with the error being

 1. While running pass #&#8203;7105 SILFunctionTransform ""Lower Aggregate SIL Instructions to Multiple Scalar Operations"" on SILFunction "@_T0s22_ContiguousArrayBufferV08_asCocoaB0s12_NSArrayCore_pyF22<redactedFrameworkName>18SerializationErrorO_Tg5".

I could narrow it down and the crash can be avoided by not passing out the actual array but an empty array instead:

return .success(payload, withErrors: [])

Oh, and the error type is

public enum SerializationError: LocalizedError {
    case missing(String)
    case invalid(String, Any)
    
    public var errorDescription: String? {
        switch self {
        case .missing(let key): return "Key '\(key)' is missing"
        case .invalid(let key, let value): return "Key '\(key)' has invalid value: '\(value)'"
        }
    }
}

Sorry I couldn't come up with a distilled test-case yet, as there are a lot of types to reduce away here.

UPDATE:

In Xcode 9.3 the compiler traps now with the log:

CompileSwift normal arm64 /Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared/<app>Shared/MTSync/Old/ActivityResponse.swift
cd /Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-bc -filelist /var/folders/7h/btk7zp2s6mv1d7sjr55q_vy80000gn/T/sources-1c9a94 -primary-file /Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared/<app>Shared/MTSync/Old/ActivityResponse.swift -target arm64-apple-ios9.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -I /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos -F /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos -application-extension -g -import-underlying-module -module-cache-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 3 -O -serialize-debugging-options -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-generated-files.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-own-target-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-project-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos/include -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/DerivedSources/arm64 -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/DerivedSources -Xcc -ivfsoverlay -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared -emit-module-doc-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse~partial.swiftdoc -serialize-diagnostics-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.dia -module-name <app>Shared -emit-module-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse~partial.swiftmodule -emit-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.d -o /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.bc

libc++abi.dylib: Pure virtual function called!
0 swift 0x0000000108a4cffa PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000108a4c3b6 SignalHandler(int) + 966
2 libsystem_platform.dylib 0x00007fff6c374f5a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000100020008 _sigtramp + 2479534280
4 libsystem_c.dylib 0x00007fff6c1121ae abort + 127
5 libc++abi.dylib 0x00007fff6a019f8f __cxa_bad_cast + 0
6 libc++abi.dylib 0x00007fff6a036952 __cxa_deleted_virtual + 0
7 swift 0x000000010527bda3 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 38931
8 swift 0x000000010526fff1 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9073
9 swift 0x000000010516748f swift::irgen::IRGenerator::emitLazyDefinitions() + 6111
10 swift 0x00000001052515c3 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1555
11 swift 0x00000001050acdce performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 38110
12 swift 0x00000001050a1e64 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
13 swift 0x00000001050568b5 main + 18917
14 libdyld.dylib 0x00007fff6c066015 start + 1
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-bc -filelist /var/folders/7h/btk7zp2s6mv1d7sjr55q_vy80000gn/T/sources-1c9a94 -primary-file /Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared/<app>Shared/MTSync/Old/ActivityResponse.swift -target arm64-apple-ios9.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -I /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos -F /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos -application-extension -g -import-underlying-module -module-cache-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 3 -O -serialize-debugging-options -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-generated-files.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-own-target-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/<app>Shared-project-headers.hmap -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/BuildProductsPath/Release-iphoneos/include -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/DerivedSources/arm64 -Xcc -I/Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/DerivedSources -Xcc -ivfsoverlay -Xcc /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared -emit-module-doc-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse~partial.swiftdoc -serialize-diagnostics-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.dia -module-name <app>Shared -emit-module-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse~partial.swiftmodule -emit-dependencies-path /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.d -o /Users/tkrajacic/Library/Developer/Xcode/DerivedData/<app>-dgvilvbgvcvqmpgjjllnaldsphsa/Build/Intermediates.noindex/ArchiveIntermediates/<app>/IntermediateBuildFilesPath/<app>Shared.build/Release-iphoneos/<app>Shared.build/Objects-normal/arm64/ActivityResponse.bc 
1. While emitting IR SIL function "@_T017<app>Shared16ActivityResponseV10activitiesAA8ResourceVyACGAA9APIClient_pcAA3APIO6FilterO04withJ0_AJ0D9TimeframeO9timeframeSiSg5limittFZAgaH_pcfU_AA18IntermediateResultOyACGypKcfU_".
for expression at [/Users/tkrajacic/Developer/Projects/<org>/<app>_ios/<app>Shared/<app>Shared/MTSync/Old/ActivityResponse.swift:93:110 - line:102:13] RangeText="{ json in
guard let dictionary = json as? JSONDictionary else { throw APIError.invalidData }
do {
var recoverableErrors: [SerializationError] = []
let response = try ActivityResponse(json: dictionary, recoverableErrors: &recoverableErrors)
return .success(response, withErrors: recoverableErrors)
} catch let parsingError as SerializationError {
return .failure(parsingError)
}
}"
@belkadan
Copy link
Contributor

shajrawi (JIRA User), sound familiar? Who might know?

@swift-ci
Copy link
Collaborator

Comment by Joe Shajrawi (JIRA)

Does not sound familiar to me.. I can't think of anything that might cause this. would need either a test-case or at the very least the full crash-log in that transformation

@tkrajacic
Copy link
Author

Archiving the app takes forever (well… it's a Swift app what can I say), and when I stop the build after the error occurs Xcode doesn't show the error in the log anymore (even when I go to the Report Navigator and Save the build log – by aborting this log becomes somehow neutered)

So I'll try tomorrow to further reduce this, but every build takes like 10 minutes and it is exhausting. Building up the error from a blank project has been fruitless so far.

@tkrajacic
Copy link
Author

@belkadan, shajrawi (JIRA User): the same code now traps `While emitting IR SIL function`. So I guess the title of the bug should be different now even though the problem is probably in the same area. I guess you can find a more appropriate one?

@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 optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

4 participants