Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12485] Code fails when run for -Onone optimization #54926

Open
swift-ci opened this issue Apr 1, 2020 · 1 comment
Open

[SR-12485] Code fails when run for -Onone optimization #54926

swift-ci opened this issue Apr 1, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 1, 2020

Previous ID SR-12485
Radar rdar://problem/62201610
Original Reporter Jaap (JIRA User)
Type Bug
Environment

macOS Catalina 10.15.3

`swift --version`

Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0

Xcode 11.4 (Not necessary it can be reproduced using the swiftc compiler)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: bdc1a101ab95f24062c16848738af624

Issue Description:

The following code crashes with a bad access error when compiled with the -Onone flag. It does work using the REPL or when compiled using -O and -Osize.

struct Transform {
    var position: SIMD3<Float>
}


class Node {
    private var transform: Transform
    
    var position: SIMD3<Float> {
        get { return transform.position }
        set { transform.position = newValue}
    }
    
    init() {
        transform = Transform(position: SIMD3<Float>(0, 0, 0))
    }
}


let node = Node()
print(node.position) //SIMD3<Float>(0.0, 0.0, 0.0)
node.position = SIMD3<Float>(1, 1, 1)
print(node.position) //SIMD3<Float>(1.0, 1.0, 1.0)
node.position.x = 3
print(node.position) //SIMD3<Float>(3.0, 1.0, 1.0)
node.position.y = node.position.y + 5
print(node.position) // SIMD3<Float>(3.0, 6.0, 1.0)
node.position.z += 9 // getting a bad access error here
print(node.position)
swiftc Sources/test/test.swift -O
./test

resulting in:

SIMD3<Float>(0.0, 0.0, 0.0)
SIMD3<Float>(1.0, 1.0, 1.0)
SIMD3<Float>(3.0, 1.0, 1.0)
SIMD3<Float>(3.0, 6.0, 1.0)
SIMD3<Float>(3.0, 6.0, 10.0)

Compared to:

swiftc Sources/test/test.swift -Onone
./test

resulting in:

SIMD3<Float>(0.0, 0.0, 0.0)
SIMD3<Float>(1.0, 1.0, 1.0)
SIMD3<Float>(3.0, 1.0, 1.0)
SIMD3<Float>(3.0, 6.0, 1.0)
Segmentation fault: 11
@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants