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-13462] Existentials needlessly copied #55904

Open
dabrahams opened this issue Aug 27, 2020 · 2 comments
Open

[SR-13462] Existentials needlessly copied #55904

dabrahams opened this issue Aug 27, 2020 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-13462
Radar rdar://problem/68116209
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @eeckstein
Priority Medium

md5: 4dd324f44e59e9bba4cd43da818fb481

Issue Description:

This program prints

true
false

but should print

true
true

`X` and `Y` are identical except that `Y` stores an `Any`.

struct X {
  var a: Int = 3

  func test() {
    let p0 = withUnsafePointer(to: self) { UnsafeRawPointer($0) }
    let p1 = withUnsafePointer(to: a) { UnsafeRawPointer($0) }
    print(p0 == p1)
    withExtendedLifetime(self) {}
  }
}

struct Y {
  var a: Any = 3

  func test() {
    let p0 = withUnsafePointer(to: self) { UnsafeRawPointer($0) }
    let p1 = withUnsafePointer(to: a) { UnsafeRawPointer($0) }
    print(p0 == p1)
    withExtendedLifetime(self) {}
  }
}

X().test()
Y().test()
@typesanitizer
Copy link

@swift-ci create

@eeckstein
Copy link
Member

Sorry for the delay.
This test program is actually undefined behavior because it let the pointers escape from the closures.
The optimizer tends to give up in case it sees "unsafe" code like this.
Also, with a recent compiler, the output for X.test is false.

Is this just an artificial test case to show the problem? Do you have a more realistic test case without undefined behavior?

@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

3 participants