You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users report their app is crashing due to a use-after-free when modifying a nonmutating property defined on a protocol extension. Test case project here:
The problem can be worked around by separating the `get` and `set` of the nonmutating property into their own statements:
letsomeObject = SomeClass()
vartemp = someObject.someGetter// first get the propertytemp.x = 42// update the valuesomeObject.someGetter = temp// then set the property
If I compile this with swiftc -emit-sil-ownership -emit-silgen foo.swift, I see the following SIL:
silhidden@$S3foo4test1yy12CoreGraphics7CGFloatV_tF : $@convention(thin) (CGFloat) -> () {
...
// the result of SomeClass()
%4 = apply %3(%2) : $@convention(method) (@thickSomeClass.Type) -> @ownedSomeClass// users: %20, %7
...
store %4to [init] %6 : $*SomeClass// id: %7
...
store %4to [init] %19 : $*SomeClass// id: %20
...
}
indicating that the value gets moved into a temporary buffer and thence consumed twice, once while invoking the getter and again while invoking the setter. There's no intervening control flow between the two stores—everything is one basic block—so I'm surprised the ownership verifier doesn't catch this. cc @gottesmm
JoeG and I spoke about this. I explained to him the ownership verifier is compiled out when assertions are disabled. So the flag will do nothing.
To confirm what the reporter ran into, I ran the test program against a 4-2 convergence snapshot and we hit a SILGen is forwarding a cleanup twice (i.e. two consumes of the same value) assert. See attached 4.2-convergence.log.
Activity
jckarter commentedon Oct 15, 2018
Possibly another report of a similar bug: https://forums.swift.org/t/semantics-of-on-class-type/16990/2
jckarter commentedon Oct 15, 2018
Here's a version of the test program from the Github discussion:
If I compile this with
swiftc -emit-sil-ownership -emit-silgen foo.swift, I see the following SIL:indicating that the value gets moved into a temporary buffer and thence consumed twice, once while invoking the getter and again while invoking the setter. There's no intervening control flow between the two stores—everything is one basic block—so I'm surprised the ownership verifier doesn't catch this. cc @gottesmm
gottesmm commentedon Oct 15, 2018
JoeG and I spoke about this. I explained to him the ownership verifier is compiled out when assertions are disabled. So the flag will do nothing.
To confirm what the reporter ran into, I ran the test program against a 4-2 convergence snapshot and we hit a SILGen is forwarding a cleanup twice (i.e. two consumes of the same value) assert. See attached 4.2-convergence.log.
jckarter commentedon Oct 16, 2018
Hopefully this fixes it: #19902