swiftlang / swift

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

[SR-1850] Compiler crashes when using statement labels while code coverage is enabled #44459

Closed marcomasser closed 8 years ago

marcomasser commented 8 years ago
Previous ID SR-1850
Radar None
Original Reporter @marcomasser
Type Bug
Status Resolved
Resolution Done
Environment OS X 10.11.6 Beta 1 Xcode 7.3.1 with Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31) Xcode 8 Beta 1 with Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CodeCoverage, CompilerCrash | |Assignee | @vedantk | |Priority | Medium | md5: 11952f74cf5007014189cb0b7fe02d6c

Issue Description:

In Xcode, when compiling a unit testing target that has “Gather coverage data” enabled (Edit Scheme > Test > Info), the Swift 2.2 and 3.0 compiler crash when the compiled code contains statement labels that are actually used.

A minimal test is a file with the following contents (“test.swift”):

func foo() {
    testLabel: do {
        break testLabel
    }
}

Compile it with the following command to get the same crash as in Xcode:

swiftc -enable-testing -profile-generate -profile-coverage-mapping test.swift

Here’s the complete output of that command:

0  swift                    0x000000010d37e34b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010d37d636 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010d37e99f SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff916be52a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff54df9f00 _sigtramp + 3279141360
5  swift                    0x000000010b58e91f swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 351
6  swift                    0x000000010b58ec93 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 1235
7  swift                    0x000000010b58e8f5 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 309
8  swift                    0x000000010b5908a5 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 1045
9  swift                    0x000000010b58c07e (anonymous namespace)::Traversal::doIt(swift::Decl*) + 254
10 swift                    0x000000010b58bf6b swift::Decl::walk(swift::ASTWalker&) + 27
11 swift                    0x000000010afe4869 walkForProfiling(swift::AbstractFunctionDecl*, swift::ASTWalker&) + 25
12 swift                    0x000000010afe43c9 swift::Lowering::SILGenProfiling::assignRegionCounters(swift::AbstractFunctionDecl*) + 553
13 swift                    0x000000010af6ca69 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 249
14 swift                    0x000000010af6c1db swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 747
15 swift                    0x000000010af6ce22 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 818
16 swift                    0x000000010af6d293 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 115
17 swift                    0x000000010ae3e8bb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 13131
18 swift                    0x000000010ae3a619 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2873
19 swift                    0x000000010ae086c4 main + 2852
20 libdyld.dylib            0x00007fff8e5435ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -enable-testing -profile-generate -profile-coverage-mapping -color-diagnostics -module-name test -o /var/folders/w0/g3nlt5f14w9cy_shkddr9l800000gn/T/test-0d29ed.o 
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
belkadan commented 8 years ago

@vedantk, who should look at this?

vedantk commented 8 years ago

I'll grab this one.

vedantk commented 8 years ago

Fixed on swift/master (348b78a4). We should have this ready for the upcoming betas of swift 2.3 and 3.0. I don't think this will be backported to swift 2.2.

marcomasser commented 8 years ago

Awesome, thanks!