-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make a temporary existential when reflecting weak properties #4397
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
Make a temporary existential when reflecting weak properties #4397
Conversation
@swift-ci Please test. |
@rjmccall Can you review? |
|
||
// First create a temporary existential. | ||
auto valueSize = type->getValueWitnesses()->getSize(); | ||
auto temporaryValue = static_cast<void*>(malloc(valueSize)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably more efficient to use vw_allocBuffer here.
When getting a mirror child that is a class existential, there may be witness tables for the protocol composition to copy. Don't just take the address of a class instance pointer from the stack - make a temporary existential-like before calling into the Mirror constructor. This now correctly covers reflecting weak optional class types, and weak optional class existential types, along with fixing a stack buffer overflow reported by the Address Sanitizer (thanks, ASan!). Tests were also updated to check for the validity of the child's data. rdar://problem/27348445
@swift-ci Please test. |
@swift-ci Please test OS X Platform. |
@swift-ci Smoke test OS X Platform. |
Smoke test didn't respond, but the full OS X platform test passed, so I'll merge. |
@@ -2337,11 +2339,15 @@ struct ClassExistentialContainer { | |||
return reinterpret_cast<const WitnessTable* const *>(this + 1); | |||
} | |||
|
|||
void copyTypeInto(ClassExistentialContainer *dest, unsigned numTables) const { | |||
void copyTypeInto(ClassExistentialContainerImpl *dest, | |||
unsigned numTables) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor request (totally unnecessary for 3.0): you could make this templated over the dest's value type, since it doesn't touch that field at all.
LGTM, thanks! |
Thanks John! |
When getting a mirror child that is a class existential, there
may be witness tables for the protocol composition to copy. Don't
just take the address of a class instance pointer from the stack -
make a temporary existential-like before calling into the Mirror
constructor.
This now correctly covers reflecting weak optional class types, and weak
optional class existential types, along with fixing a stack buffer
overflow reported by the Address Sanitizer (thanks, ASan!).
Tests were also updated to check for the validity of the child's data.
rdar://problem/27348445