swiftlang / swift

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

[SR-10622] Crash in swift_arrayDestroy #53022

Open swift-ci opened 5 years ago

swift-ci commented 5 years ago
Previous ID SR-10622
Radar rdar://problem/50501400
Original Reporter joplunien (JIRA User)
Type Bug
Environment - Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5), Target: x86_64-apple-darwin18.5.0 - MacBook Pro (15-inch, 2017) - Xcode 10.2.1, Build version 10E1001 - iPhone X Simulator, 11.4 - macOS Mojave, 10.14.4 (18E226)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, RunTimeCrash | |Assignee | None | |Priority | Medium | md5: 1e61a629e5650d8fc01ee777878a07d5

Issue Description:

Description

The example project demonstrates some crash. Reason for the crash is unknown, could be a project misconfiguration, or a bug in the compiler.

The full example project can be found here: https://github.com/plu/SR-10622

Notes

What are these UnrelatedClass....swift?

They are the result of trying to reduce to a minimal amount of code. At first it was possible to delete whole files from the project while still being able to reproduce the crash. Only later on a simple removal of some unrelated file resulted in the crash to disappear suddenly.

Why does removing some of these UnrelatedClass....swift fix the crash?

No idea. But it's simple to "reproduce", just remove a few and execute ./test.sh.

There's other unrelated changes that magically fixes the issue, for example:

diff --git a/ECGMessageBox/Classes/Internal/ConversationListViewController.swift b/ECGMessageBox/Classes/Internal/ConversationListViewController.swift
index 0ab8986..f625306 100644
--- a/ECGMessageBox/Classes/Internal/ConversationListViewController.swift
+++ b/ECGMessageBox/Classes/Internal/ConversationListViewController.swift
@@ -1,11 +1,4 @@
 import UIKit

 class ConversationListViewController: UIViewController {
-    init(messageBox: MessageBox) {
-        super.init(nibName: nil, bundle: nil)
-    }
-    
-    required init?(coder aDecoder: NSCoder) {
-        fatalError("init(coder:) has not been implemented")
-    }
 }

How to reproduce

./test.sh

Crash

Process:               AppHost-ECGMessageBox-Unit-Tests [30484]
Path:                  /Users/USER/Library/Developer/CoreSimulator/Devices/B76B70FC-B112-4113-8C2B-4A19F004A17A/data/Containers/Bundle/Application/4807BFE9-8D0E-41D0-9E9F-7A1C686BA990/AppHost-ECGMessageBox-Unit-Tests.app/AppHost-ECGMessageBox-Unit-Tests
Identifier:            AppHost-ECGMessageBox-Unit-Tests
Version:               1.0.0 (1)
Code Type:             X86-64 (Native)
Parent Process:        launchd_sim [51797]
Responsible:           AppHost-ECGMessageBox-Unit-Tests [30484]
User ID:               110263014

Date/Time:             2019-05-03 12:59:20.326 +0200
OS Version:            Mac OS X 10.14.4 (18E226)
Report Version:        12
Bridge OS Version:     3.0 (14Y677)
Anonymous UUID:        E229F090-9D6F-B707-595D-05E8C82D19F1

Sleep/Wake UUID:       18E91450-19C4-4A54-B3E4-5D21C2DFF48C

Time Awake Since Boot: 200000 seconds
Time Since Wake:       26000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [30484]

Application Specific Information:
CoreSimulator 587.35 - Device: iPhone X (B76B70FC-B112-4113-8C2B-4A19F004A17A) - Runtime: iOS 11.4 (15F79) - DeviceType: iPhone X

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x0000000100d33d0b objc_release + 11
1   libswiftCore.dylib              0x0000000114d5a64b swift_arrayDestroy + 59
2   libswiftCore.dylib              0x0000000114af770a _ContiguousArrayStorage.__deallocating_deinit + 42
3   libswiftCore.dylib              0x0000000114d64690 _swift_release_dealloc + 16
4   libswiftFoundation.dylib        0x00000001152aaed7 specialized Array._copyToNewBuffer(oldCount:) + 71
5   libswiftFoundation.dylib        0x00000001152aab54 specialized Array._makeUniqueAndReserveCapacityIfNotUnique() + 100
6   libswiftFoundation.dylib        0x0000000115204a8b specialized RangeReplaceableCollection<>.popLast() + 107
7   libswiftFoundation.dylib        0x0000000115203017 __JSONEncoder.box_(_:) + 7751
8   libswiftFoundation.dylib        0x000000011520096c JSONEncoder.encode<A>(_:) + 476
9   libswiftFoundation.dylib        0x00000001153092ae dispatch thunk of JSONEncoder.encode<A>(_:) + 14
10  org.cocoapods.ECGMessageBox     0x00000001149e1136 PersistentDataStorage.write(data:) + 374 (PersistentDataStorage.swift:6)
11  org.cocoapods.ECGMessageBox-Unit-Tests  0x00000001149cabaf PersistentDataStorageTests.testCrash() + 511 (PersistentDataStorageTests.swift:12)
12  org.cocoapods.ECGMessageBox-Unit-Tests  0x00000001149cb184 @objc PersistentDataStorageTests.testCrash() + 36
13  com.apple.CoreFoundation        0x0000000103e85ccc __invoking___ + 140
14  com.apple.CoreFoundation        0x0000000103e85b84 -[NSInvocation invoke] + 308
15  com.apple.dt.XCTest             0x0000000110983b74 __24-[XCTestCase invokeTest]_block_invoke.194 + 78
16  com.apple.dt.XCTest             0x00000001109db8a4 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
17  com.apple.dt.XCTest             0x00000001109db7c2 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
18  com.apple.dt.XCTest             0x0000000110983804 __24-[XCTestCase invokeTest]_block_invoke + 848
19  com.apple.dt.XCTest             0x00000001109e1d01 -[XCUITestContext performInScope:] + 128
20  com.apple.dt.XCTest             0x00000001109833f1 -[XCTestCase testContextPerformInScope:] + 116
21  com.apple.dt.XCTest             0x00000001109834a7 -[XCTestCase invokeTest] + 137
22  com.apple.dt.XCTest             0x0000000110984f73 __26-[XCTestCase performTest:]_block_invoke_2 + 43
23  com.apple.dt.XCTest             0x00000001109db8a4 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
24  com.apple.dt.XCTest             0x00000001109db7c2 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
25  com.apple.dt.XCTest             0x0000000110984e8a __26-[XCTestCase performTest:]_block_invoke.316 + 88
26  com.apple.dt.XCTest             0x00000001109ec3b7 +[XCTContext runInContextForTestCase:block:] + 225
27  com.apple.dt.XCTest             0x00000001109845f8 -[XCTestCase performTest:] + 676
28  com.apple.dt.XCTest             0x00000001109c7d6c -[XCTest runTest] + 57
29  com.apple.dt.XCTest             0x000000011097f0d7 __27-[XCTestSuite performTest:]_block_invoke + 365
30  com.apple.dt.XCTest             0x000000011097e8b3 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
31  com.apple.dt.XCTest             0x000000011097eb6f -[XCTestSuite performTest:] + 290
32  com.apple.dt.XCTest             0x00000001109c7d6c -[XCTest runTest] + 57
33  com.apple.dt.XCTest             0x000000011097f0d7 __27-[XCTestSuite performTest:]_block_invoke + 365
34  com.apple.dt.XCTest             0x000000011097e8b3 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
35  com.apple.dt.XCTest             0x000000011097eb6f -[XCTestSuite performTest:] + 290
36  com.apple.dt.XCTest             0x00000001109c7d6c -[XCTest runTest] + 57
37  com.apple.dt.XCTest             0x000000011097f0d7 __27-[XCTestSuite performTest:]_block_invoke + 365
38  com.apple.dt.XCTest             0x000000011097e8b3 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
39  com.apple.dt.XCTest             0x000000011097eb6f -[XCTestSuite performTest:] + 290
40  com.apple.dt.XCTest             0x00000001109c7d6c -[XCTest runTest] + 57
41  com.apple.dt.XCTest             0x00000001109f6986 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
42  com.apple.dt.XCTest             0x00000001109f6a57 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.80 + 68
43  com.apple.dt.XCTest             0x0000000110996474 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 588
44  com.apple.dt.XCTest             0x00000001109f673d -[XCTTestRunSession runTestsAndReturnError:] + 623
45  com.apple.dt.XCTest             0x000000011096341c -[XCTestDriver runTestsAndReturnError:] + 446
46  com.apple.dt.XCTest             0x00000001109e856f _XCTestMain + 2333
47  libXCTestBundleInject.dylib     0x00000001004fcbf1 __RunTests_block_invoke_2 + 13
48  com.apple.CoreFoundation        0x0000000103ea4b0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
49  com.apple.CoreFoundation        0x0000000103e892db __CFRunLoopDoBlocks + 331
50  com.apple.CoreFoundation        0x0000000103e88a84 __CFRunLoopRun + 1284
51  com.apple.CoreFoundation        0x0000000103e8830b CFRunLoopRunSpecific + 635
52  com.apple.GraphicsServices      0x00000001067eea73 GSEventRunModal + 62
53  com.apple.UIKit                 0x00000001015bc057 UIApplicationMain + 159
54  org.cocoapods.AppHost-ECGMessageBox-Unit-Tests  0x000000010046f9c0 main + 112 (main.m:28)
55  libdyld.dylib                   0x00000001050da955 start + 1
belkadan commented 5 years ago

Thank you for the thorough report!

swift-ci commented 5 years ago

Comment by Johannes Plunien (JIRA)

@belkadan do you maybe have some tip for us how to work around this issue until the next Xcode/Swift version is released?

swift-ci commented 5 years ago

Comment by Johannes Plunien (JIRA)

It seems that switching to SWIFT_COMPILATION_MODE=wholemodule works around the issue. I have not verified this in the given example project, but in our "real" project.

belkadan commented 5 years ago

Sorry, I don't know what's going on yet either.