swiftlang / swift

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

[SR-12310] Segmentation fault when "Running pass 'Module Verifier'" #54740

Open JaviSoto opened 4 years ago

JaviSoto commented 4 years ago
Previous ID SR-12310
Radar rdar://problem/60230377
Original Reporter @JaviSoto
Type Bug
Environment Xcode 11.4 / Swift 5.2
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug, CompilerCrash | |Assignee | None | |Priority | Medium | md5: f883833f3f98ed1026f712d62e5145bd

Issue Description:

I've been seeing this since Xcode 11.4 Beta 1, and I'm still seeing it with Beta 3. I didn't have time until now to diagnose a bit more and file the bug report. This is also an intermittent issue. It seems that deleting derived data, closing Xcode and reopening it, and compiling again sometimes makes it work. Which makes me wonder whether this is an issue with having build artifacts in Derived Data produced by Xcode 11.3, and then try to build with 11.4?

It also doesn't seem related to the specific file that it fails on, because if I comment out the code in it, it will just happen on the next one.

This is the build command:

CompileSwift normal x86_64 /Users/username/Documents/Projects/twitch-iphone/Foo/Bar.swift (in target 'Twitch' from project 'Twitch')
    cd /Users/username/Documents/Projects/twitch-iphone/Twitch.tv
    /Applications/Xcode11.4-beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -filelist /var/folders/c5/64y8nyjn051cbc0j37xhg3w00000gn/T/sources-603ea0 -primary-file /Users/username/Documents/Projects/twitch-iphone/Foo/Bar.swift -emit-module-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar\~partial.swiftmodule -emit-module-doc-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar\~partial.swiftdoc -emit-module-source-info-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar\~partial.swiftsourceinfo -serialize-diagnostics-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar.dia -emit-dependencies-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar.d -emit-reference-dependencies-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar.swiftdeps -target x86_64-apple-ios11.4-simulator -enable-objc-interop -sdk /Applications/Xcode11.4-beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -I /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Products/Debug-iphonesimulator -F <A bunch of linked frameworks> -assert-config Debug -enable-testing -g -module-cache-path /Users/username/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D XARTH -D DEBUG -D COCOAPODS -warn-long-function-bodies=1000 -warn-long-expression-type-checking=400 -serialize-debugging-options -Xcc -working-directory -Xcc /Users/username/Documents/Projects/twitch-iphone/Twitch.tv -enable-anonymous-context-mangled-names -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-generated-files.hmap -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-own-target-headers.hmap -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-project-headers.hmap -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Products/Debug-iphonesimulator/include -Xcc - -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources-normal/x86_64 -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources/x86_64 -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DCOCOAPODS=1 -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DGPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DPB_FIELD_32BIT=1 -Xcc -DPB_NO_PACKED_STRUCTS=1 -Xcc -DPB_ENABLE_MALLOC=1 -import-objc-header /Users/username/Documents/Projects/twitch-iphone/Twitch.tv/Twitch-Bridging-Header.h -pch-output-dir /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/PrecompiledHeaders -pch-disable-validation -module-name Twitch -o /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar.o -index-store-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Index/DataStore -index-system-modules

Call parameter type does not match function signature!
x86_fp80 0xK3FFD8000000000000000
i64*  %34 = call swiftcc double @swift_intToFloat64(x86_fp80 0xK3FFD8000000000000000, half Stack dump:
0. Program arguments: /Applications/Xcode11.4-beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -filelist /var/folders/c5/64y8nyjn051cbc0j37xhg3w00000gn/T/sources-603ea0 -primary-file <all_paths_to_swift_files_in_target> -supplementary-output-file-map /var/folders/c5/64y8nyjn051cbc0j37xhg3w00000gn/T/supplementaryOutputs-8e49c3 -target x86_64-apple-ios11.4-simulator -enable-objc-interop -sdk /Applications/Xcode11.4-beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -I <a bunch of linked frameworks> -assert-config Debug -enable-testing -g -module-cache-path /Users/username/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D XARTH -D DEBUG -D COCOAPODS -warn-long-function-bodies=1000 -warn-long-expression-type-checking=400 -serialize-debugging-options -Xcc -working-directory -Xcc /Users/username/Documents/Projects/twitch-iphone/Twitch.tv -enable-anonymous-context-mangled-names -Xcc -I /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-generated-files.hmap -Xcc -I /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-own-target-headers.hmap -Xcc -I /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Xarth-project-headers.hmap -Xcc -iquote -Xcc /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources -Xcc -I <a bunch of linked frameworks>
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources-normal/x86_64 -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources/x86_64 -Xcc -I / 
Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DCOCOAPODS=1 -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DGPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 -Xcc -DDEBUG=1 -Xcc -DXARTH=1 -Xcc -DTWITCH_APPGROUP_NAME=group.twitch.SharedAppResources -Xcc -DPB_FIELD_32BIT=1 -Xcc -DPB_NO_PACKED_STRUCTS=1 -Xcc -DPB_ENABLE_MALLOC=1 -import-objc-header /Users/username/Documents/Projects/twitch-iphone/Twitch.tv/Twitch-Bridging-Header.h -pch-output-dir /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/PrecompiledHeaders -module-name Twitch -o /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Build/Intermediates.noindex/Twitch.build/Debug-iphonesimulator/Twitch.build/Objects-normal/x86_64/Bar.o <a bunch of file paths> -index-store-path /Users/username/Library/Developer/Xcode/DerivedData/Twitch-giqbfvxagxgvqlasymliromwjowp/Index/DataStore -index-system-modules
1. Apple Swift version 5.2 (swiftlang-1103.0.30 clang-1103.0.30)
2. Contents of /var/folders/c5/64y8nyjn051cbc0j37xhg3w00000gn/T/sources-603ea0:
---
<List of all Swift files in target>
---
3. Running pass 'Module Verifier' on function '@"$s6Twitch13ChatInputViewC25sendOrCancelButtonVisible33_C04E56FD3AAC83881997DAF21B26CBB6LLSbvW"'
0  swift                    0x00000001087a04ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010879fcc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6416442d _sigtramp + 29
3  libsystem_platform.dylib 0x00007f8386c6ce60 _sigtramp + 581995088
4  swift                    0x000000010855fe68 WriteAsOperandInternal(llvm::raw_ostream&, llvm::Value const*, (anonymous namespace)::TypePrinting*, llvm::SlotTracker*, llvm::Module const*) + 1544
5  swift                    0x000000010856617c (anonymous namespace)::AssemblyWriter::writeParamOperand(llvm::Value const*, llvm::AttributeSet) + 300
6  swift                    0x0000000108563f62 (anonymous namespace)::AssemblyWriter::printInstruction(llvm::Instruction const&) + 11858
7  swift                    0x000000010857f6b0 llvm::Value::print(llvm::raw_ostream&, llvm::ModuleSlotTracker&, bool) const + 1536
8  swift                    0x000000010867f126 llvm::VerifierSupport::Write(llvm::Value const&) + 38
9  swift                    0x000000010868c45f (anonymous namespace)::Verifier::visitCallInst(llvm::CallInst&) + 31
10 swift                    0x000000010867ce8b (anonymous namespace)::Verifier::verify(llvm::Function const&) + 5499
11 swift                    0x000000010869d3c6 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 22
12 swift                    0x000000010863d7e9 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1609
13 swift                    0x0000000108646e60 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 112
14 swift                    0x0000000108646d8d llvm::legacy::FunctionPassManager::run(llvm::Function&) + 365
15 swift                    0x0000000104701c28 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 5816
16 swift                    0x000000010450051b 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*) + 12923
17 swift                    0x00000001044f3790 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48416
18 swift                    0x000000010446b4a3 main + 1283
19 libdyld.dylib            0x00007fff63f6b7fd start + 1
error: Segmentation fault: 11 (in target 'Twitch' from project 'Twitch')
beccadax commented 4 years ago

@swift-ci create

JaviSoto commented 4 years ago

I tried to see if it was reproducible with an Xcode snapshot from Swift.org, but it seems those have been broken since January: https://forums.swift.org/t/swift-5-2-snapshot-error/32544/8

JaviSoto commented 4 years ago

(Still an issue on Beta 3)

JaviSoto commented 4 years ago

The final build of Xcode 11.4 still has this issue, albeit it happens way less frequently.

But I realized it always happens in the same property. Here's the code of such property:

 private var sendOrCancelButtonVisible = false {
    didSet {
        guard oldValue != sendOrCancelButtonVisible else {
            return
        }

        UIView.animate(withDuration: sendOrCancelButtonVisible ? TWViewAppearanceAnimationDuration : TWViewDismissalAnimationDuration) {
            self.sendOrCancelButton.alpha = self.sendOrCancelButtonVisible ? 1.0 : 0.0
            self.activeSendOrCancelButtonConstraint = self.sendOrCancelButtonVisible
                ? self.sendOrCancelButtonConstraints.visible
                : self.sendOrCancelButtonConstraints.hidden
            self.layoutIfNeeded()
        }
    }
}

TWViewAppearanceAnimationDuration is a #define in a header imported through the bridging header. TWViewDismissalAnimationDuration is an extern const defined in another header.

JaviSoto commented 4 years ago

We hit another seg fault 11 in a different file, only when building against an iOS device instead of simulator. Also pointing to a method that references a #define declared in a header imported in the bridging header. If we change the #define to a extern const, the crash goes away. I'm not able to repro in an empty project though 🙁 Here's the crash details of that one:

---
3.  While emitting IR SIL function "@$sSo10UITextViewC6TwitchE11applyEmotes33_ACB92AEF86377123BBFC1EFCF6DB010ELL5using20withPlaceholderTheme20consideringSelectionSbAC16ChatEmoteManagerC_So7TWTheme_pSbtFySS_So8_NSRangeVSbztXEfU_".
 for expression at [/Users/jsbustos/Documents/Projects/twitch-iphone/Twitch.tv/Code/Controllers/Chat/ChatViewController.swift:992:73 - line:1050:9] RangeText="" /* some code here */
0  swift                    0x00000001115174ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000111516cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6ee1942d _sigtramp + 29
3  libsystem_platform.dylib 0x00007fb62a76b1a8 _sigtramp + 3147111832
4  swift                    0x000000010d2e29ea llvm::CallInst::Create(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, llvm::Twine const&, llvm::Instruction*) + 490
5  swift                    0x000000010d2f990e llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, llvm::Twine const&, llvm::MDNode*) + 62
6  swift                    0x000000010d2f95fa swift::irgen::IRBuilder::CreateCall(swift::irgen::FunctionPointer const&, llvm::ArrayRef<llvm::Value*>) + 378
7  swift                    0x000000010d2f7a9d swift::irgen::CallEmission::emitCallSite() + 157
8  swift                    0x000000010d2faa50 swift::irgen::CallEmission::emitToExplosion(swift::irgen::Explosion&, bool) + 2624
9  swift                    0x000000010d4be1c0 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2352
10 swift                    0x000000010d49e8e3 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
11 swift                    0x000000010d352032 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
12 swift                    0x000000010d47ced9 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**) + 1097
13 swift                    0x000000010d27436f 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*) + 4255
14 swift                    0x000000010d2697c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48416
15 swift                    0x000000010d1e14d3 main + 1283
16 libdyld.dylib            0x00007fff6ec207fd start + 1
17 libdyld.dylib            0x000000000000016f start + 2436757875
error: Segmentation fault: 11 (in target 'Twitch' from project 'Twitch')