Skip to content

Commit

Permalink
Merge pull request swiftlang#19099 from compnerd/use-after-move
Browse files Browse the repository at this point in the history
Basic: correct use-after-move on Windows
  • Loading branch information
compnerd authored Sep 1, 2018
2 parents f752844 + 3f5c245 commit 361f8dd
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 361f8dd

Please sign in to comment.