Skip to content

[SR-4497] Memory issue causes crash when application built with optimization turned on. #47074

@swift-ci

Description

@swift-ci
Previous ID SR-4497
Radar rdar://problem/31459425
Original Reporter anaglik (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, OptimizedOnly, RunTimeCrash
Assignee @eeckstein
Priority Medium

md5: baaae3d56f01cbf35295f4840f3516f5

duplicates:

  • SR-4393 Miscompilation: object modified after being freed (Swift 3.1 regression)

Issue Description:

I've noticed crashes after I upgraded Swift to version 3.1. It happens only when optimization is set to "-O" or "-O whole-module-optimization"
Here is an example code (Example app crashes when following method is called a few times (usually two is enough).

fileprivate func funWithWords(_ words: [String]) -> [String] {        
        var resultArray = [String]()
        
        for index in 0..<words.count {
            // This will crash
            let pre = words[0...index].reduce("", +)
            resultArray.append(pre)
            
            // This version is ok
//            let pre = words[0...index].reduce("", +)
//            resultArray = resultArray + [pre]
            
            // This version is ok too
//            let pre = words[0...index].joined()
//            resultArray.append(pre)
            
            // This version is ok too
//            let pre = words[0...index]
//            let reduced = pre.reduce("", +)
//            resultArray.append(reduced)
        }
        return resultArray
}

Instruments also detects leak in that code. I am attaching screenshot of stack trace from Instruments and Xcode.
I will verify if issue exists on swift-master as well.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareoptimized onlyFlag: An issue whose reproduction requires optimized compilationrun-time crashBug → crash: Swift code crashed during execution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions