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-13180] withUnsafePointer should guarantee pointer stability for globals and class properties #55621

Open
atrick opened this issue Jul 8, 2020 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@atrick
Copy link
Member

atrick commented Jul 8, 2020

Previous ID SR-13180
Radar None
Original Reporter @atrick
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: f898da4d21aaa0b9abd17b57883351ec

Issue Description:

We should provide a guarantee of pointer stability not just within the `withUnsafePointer` closure, but also with across multiple calls with `withUnsafePointer`, `@inout` arguments, and C functions that access the same global.

For example:

C code:

struct MyStruct {
 int field;
};
extern const struct MyStruct myGlobal;
void takePointer(const struct MyStruct *);

Swift code

withUnsafePointer(to: myGlobal) {
 takePointer($0)
}

The implementation should guarantee that the pointer passed to `takePointer` is the address of `myGlobal`:

$0 == &myGlobal

I think this rule should apply to globals and class properties. @lorentey also proposed a "stable storage" language extension, so there might be some overlap with that.

@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

1 participant