swiftlang / swift

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

[SR-5284] Reproducible segfault at swift::ModuleFile::getTypeChecked #47859

Closed swift-ci closed 7 years ago

swift-ci commented 7 years ago
Previous ID SR-5284
Radar rdar://problem/32926560
Original Reporter gwk (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment OSX 10.12...10.13b3; Xcode 9b1...9b3.
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, 4.0Regression, CompilerCrash, Serialization | |Assignee | @belkadan | |Priority | Medium | md5: ca543f0c1a4225dd18f7cee68a6331e5

Issue Description:

Repro as follows; let me know if there is something more useful I can provide.

$ git clone git@github.com:gwk/quilt.git
$ cd quilt
$ git checkout 6aa7a62
$ swift build --build-path _build
Compile Swift Module 'QuiltBridge' (23 sources)
0  swift                    0x000000010c2f23aa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010c2f17e6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x000000010d6ddb3a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff56faa250 _sigtramp + 1233962800
4  swift                    0x0000000109a15c6e swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 686
5  swift                    0x0000000109a16fad swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 5613
6  swift                    0x0000000109a0dad0 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 18288
7  swift                    0x0000000109a09324 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 84
8  swift                    0x0000000109a09008 swift::ModuleFile::readParameterList() + 264
9  swift                    0x0000000109a11352 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 32754
10 swift                    0x0000000109a21451 swift::ModuleFile::loadAllMembers(swift::Decl*, unsigned long long) + 657
11 swift                    0x0000000109e6b2a6 swift::IterableDeclContext::loadAllMembers() const + 134
12 swift                    0x0000000109ec4d1c swift::NominalTypeDecl::lookupDirect(swift::DeclName, bool) + 364
13 swift                    0x0000000109a1b61e swift::ModuleFile::resolveCrossReference(swift::ModuleDecl*, unsigned int) + 3294
14 swift                    0x0000000109a0cd65 swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 14853
15 swift                    0x0000000109a16a4d swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 4237
16 swift                    0x0000000109a15c32 swift::ModuleFile::getTypeChecked(llvm::PointerEmbeddedInt<unsigned int, 31>) + 626
17 swift                    0x0000000109a0e96b swift::ModuleFile::getDeclChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 22027
18 swift                    0x0000000109a4279e swift::ModuleFile::getTopLevelDecls(llvm::SmallVectorImpl<swift::Decl*>&) + 1982
19 swift                    0x00000001096f1680 swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 1504
20 swift                    0x00000001096f7cff swift::runSILDiagnosticPasses(swift::SILModule&) + 143
21 swift                    0x0000000108cc40f0 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13696
22 swift                    0x0000000108cbf304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7332
23 swift                    0x0000000108c75728 main + 12248
24 libdyld.dylib            0x000000010d423235 start + 1
25 libdyld.dylib            0x0000000000000032 start + 4072525310
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-module /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CG-vec~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGContext~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGImage~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGPath~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGPoint-generated~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGPoint~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGRect~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGSize~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGVector-generated~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CGVector~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRColor~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CREdgeInsets~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CREvent~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRFont~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRFontDescriptor~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRResponder~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRView~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRViewController~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRWindow~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/Flt~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/NSLayoutConstraint~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/QKResponder~partial.swiftmodule /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/layout~partial.swiftmodule -parse-as-library -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I /Users/gwk/work/ploy/quilt/_build/debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/gwk/work/ploy/quilt/_build/debug/ModuleCache -swift-version 3 -D SWIFT_PACKAGE -emit-module-doc-path /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.swiftdoc -module-name QuiltBridge -o /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.swiftmodule 
1.  While reading from /Users/gwk/work/ploy/quilt/_build/debug/QuiltBridge.build/CRView~partial.swiftmodule
2.  While deserializing 'CRFlex' (TypeAliasDecl #&#8203;14) in 'QuiltBridge'
3.  While deserializing 'AutoresizingMask' (StructDecl #&#8203;6) in 'QuiltBridge'
4.  Cross-reference to module 'AppKit'
    ... NSView
    ... in an extension in module 'AppKit'
    ... AutoresizingMask
5.  While loading members for extension of NSView in module 'QuiltBridge'
6.  While deserializing 'init' (ConstructorDecl #&#8203;68) in 'QuiltBridge'
7.  While deserializing 'flex' (ParamDecl #&#8203;178) in 'QuiltBridge'
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: merge-module command failed due to signal 11 (use -v to see invocation)
error: terminated(1): /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/gwk/work/ploy/quilt/_build/debug.yaml
belkadan commented 7 years ago

To confirm: this doesn't fail in Xcode 8.3?

belkadan commented 7 years ago

@swift-ci create

swift-ci commented 7 years ago

Comment by George King (JIRA)

Yes, this code used to compile fine using the XCode 8.3.2 toolchain.

swift-ci commented 7 years ago

Comment by George King (JIRA)

I tried this on Xcode 9b2 and it fails in the same way.

swift-ci commented 7 years ago

Comment by George King (JIRA)

Still failing on Xcode 9b3.

swift-ci commented 7 years ago

Comment by George King (JIRA)

I have produced a minimal repro of the bug, attached here. Just running the single file under the swift interpreter exits cleanly, but building the package crashes similarly to the initial trace above. swift-crflex-bug.zip

belkadan commented 7 years ago

Prospective fix at https://github.com/apple/swift/pull/10956.

belkadan commented 7 years ago

Follow-up work in https://github.com/apple/swift/pull/11018.

belkadan commented 7 years ago

4.0 branch: https://github.com/apple/swift/pull/11013

belkadan commented 7 years ago

Merged into swift-4.0-branch, will be in a future Xcode release.

swift-ci commented 7 years ago

Comment by George King (JIRA)

I'm still seeing this crash after installing Xcode 9 beta4 and the corresponding command line tools. Did this fix not make it into that release?

$ swift --version
Apple Swift version 4.0 (swiftlang-900.0.54.11 clang-900.0.31)
Target: x86_64-apple-macosx10.9

belkadan commented 7 years ago

It did not, sorry.

swift-ci commented 7 years ago

Comment by George King (JIRA)

OK, thanks - better than the alternative!