Skip to content

Basic: correct use-after-move on Windows #19099

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

Merged
merged 1 commit into from
Sep 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/swift/Basic/OwnedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ class OwnedString {
return makeUnowned(Str);
} else {
llvm::IntrusiveRefCntPtr<TextOwner> OwnedPtr(TextOwner::make(Str));
return OwnedString(StringRef(OwnedPtr->getText(), Str.size()),
std::move(OwnedPtr));
// Allocate the StringRef on the stack first. This is to ensure that the
// order of evaluation of the arguments is specified. The specification
// does not specify the order of evaluation for the arguments. Itanium
// chose to evaluate left to right, while Windows evaluates right to left.
// As such, it is possible that the OwnedPtr has already been `std::move`d
// by the time that the StringRef is attempted to be created. In such a
// case, the offset of the field (+4) is used instead of the pointer to
// the text, resulting in invalid memory references.
StringRef S(OwnedPtr->getText(), Str.size());
return OwnedString(S, std::move(OwnedPtr));
}
}

Expand Down