swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.69k stars 10.39k forks source link

[SR-7072] Swift 4.1: Segmentation Fault 11 when optimization is set to -O or -Osize #49620

Open swift-ci opened 6 years ago

swift-ci commented 6 years ago
Previous ID SR-7072
Radar rdar://problem/37904576
Original Reporter svb (JIRA User)
Type Bug
Environment Xcode 9.3 beta 3 (9Q117m)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | Bug, 4.1Regression, OptimizedOnly | |Assignee | None | |Priority | Medium | md5: 49f01903f0f37bd0f10c2b2bc5e55005

Issue Description:

The following example results in a Segmentation fault: 11 when built with Xcode 9.3 Beta 3, Swift 4.1 and Optimization Level set to -O or -Osize. A sample project can be found here.

import Foundation
import RealmSwift

class Foo: Object {
    let bars = LinkingObjects(fromType: Bar.self, property: "foo")
}

class Bar: Object {
    @objc dynamic var foo: Foo?
    @objc dynamic var string: String?
}

extension Foo {
    var crash: Bool {
        return Array(bars.filter { $0.string == nil }).isEmpty // --> segmentation fault 11
        // return bars.filter { $0.string == nil }.isEmpty --> does not crash
    }
}

Crash Log:

/Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/Swift.swift
    cd /Users/sven/Desktop/SwiftCrash
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/ViewController.swift -primary-file /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/Swift.swift /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/AppDelegate.swift -target x86_64-apple-ios11.3 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -I /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator -F /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator -F /Users/sven/Desktop/SwiftCrash/Carthage/Build/iOS -enable-testing -g -module-cache-path /Users/sven/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 4 -O -D DEBUG -serialize-debugging-options -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-generated-files.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-own-target-headers.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-project-headers.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/DerivedSources/x86_64 -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/sven/Desktop/SwiftCrash -emit-module-doc-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift~partial.swiftdoc -serialize-diagnostics-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.dia -module-name SwiftCrash -emit-module-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift~partial.swiftmodule -emit-dependencies-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.d -emit-reference-dependencies-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.swiftdeps -o /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.o

0  swift                    0x000000010b70765a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010b706a16 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff664fcf5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fa94001a644 _sigtramp + 3652310788
4  swift                    0x0000000108b81e60 (anonymous namespace)::SILTypeSubstituter::visitType(swift::CanType) + 128
5  swift                    0x0000000108b81b05 swift::CanType swift::CanTypeVisitor<(anonymous namespace)::SILTypeSubstituter, swift::CanType>::visit<>(swift::CanType) + 453
6  swift                    0x0000000108b82054 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 356
7  swift                    0x0000000108b826e3 swift::SILFunctionType::substGenericArgs(swift::SILModule&, llvm::ArrayRef<swift::Substitution>) + 275
8  swift                    0x0000000107f6cd18 swift::SILBuilder::createApply(swift::SILLocation, swift::SILValue, llvm::ArrayRef<swift::Substitution>, llvm::ArrayRef<swift::SILValue>, bool, swift::GenericSpecializationInformation const*) + 184
9  swift                    0x00000001087c8aca swift::SILInstructionVisitor<swift::GenericCloner, void>::visit(swift::SILInstruction*) + 37514
10 swift                    0x00000001087becc3 swift::SILCloner<swift::GenericCloner>::visitSILBasicBlock(swift::SILBasicBlock*) + 83
11 swift                    0x00000001087bf39b swift::SILCloner<swift::GenericCloner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1835
12 swift                    0x00000001087bf39b swift::SILCloner<swift::GenericCloner>::visitSILBasicBlock(swift::SILBasicBlock*) + 1835
13 swift                    0x00000001087be8f5 swift::GenericCloner::populateCloned() + 2005
14 swift                    0x00000001088137f3 swift::GenericFuncSpecializer::tryCreateSpecialization() + 1411
15 swift                    0x0000000108955be9 (anonymous namespace)::GenericSpecializer::run() + 3305
16 swift                    0x0000000108867387 swift::SILPassManager::runOneIteration() + 6711
17 swift                    0x0000000107d6bb15 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 37781
18 swift                    0x0000000107d60d04 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
19 swift                    0x0000000107d15745 main + 18917
20 libdyld.dylib            0x00007fff6627b115 start + 1
21 libdyld.dylib            0x0000000000000042 start + 2581090094
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/ViewController.swift -primary-file /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/Swift.swift /Users/sven/Desktop/SwiftCrash/SwiftCrash/Controller/AppDelegate.swift -target x86_64-apple-ios11.3 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -I /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator -F /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator -F /Users/sven/Desktop/SwiftCrash/Carthage/Build/iOS -enable-testing -g -module-cache-path /Users/sven/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 4 -O -D DEBUG -serialize-debugging-options -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-generated-files.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-own-target-headers.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/SwiftCrash-project-headers.hmap -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/DerivedSources/x86_64 -Xcc -I/Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/sven/Desktop/SwiftCrash -emit-module-doc-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift~partial.swiftdoc -serialize-diagnostics-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.dia -module-name SwiftCrash -emit-module-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift~partial.swiftmodule -emit-dependencies-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.d -emit-reference-dependencies-path /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.swiftdeps -o /Users/sven/Library/Developer/Xcode/DerivedData/SwiftCrash-dzppebeguerqwcasjkswhqfrqtwq/Build/Intermediates.noindex/SwiftCrash.build/Debug-iphonesimulator/SwiftCrash.build/Objects-normal/x86_64/Swift.o 
1.  While running pass #&#8203;3531 SILFunctionTransform "Generic Function Specialization on Static Types" on SILFunction "@_T0s20LazyFilterCollectionVyxGs8SequencessADP22_copyToContiguousArrays0gH0Vy7ElementQzGyFTW10RealmSwift14LinkingObjectsCy0K5Crash3BarCG_Tg5".
belkadan commented 6 years ago

@swift-ci create