File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -87,8 +87,16 @@ class OwnedString {
87
87
return makeUnowned (Str);
88
88
} else {
89
89
llvm::IntrusiveRefCntPtr<TextOwner> OwnedPtr (TextOwner::make (Str));
90
- return OwnedString (StringRef (OwnedPtr->getText (), Str.size ()),
91
- std::move (OwnedPtr));
90
+ // Allocate the StringRef on the stack first. This is to ensure that the
91
+ // order of evaluation of the arguments is specified. The specification
92
+ // does not specify the order of evaluation for the arguments. Itanium
93
+ // chose to evaluate left to right, while Windows evaluates right to left.
94
+ // As such, it is possible that the OwnedPtr has already been `std::move`d
95
+ // by the time that the StringRef is attempted to be created. In such a
96
+ // case, the offset of the field (+4) is used instead of the pointer to
97
+ // the text, resulting in invalid memory references.
98
+ StringRef S (OwnedPtr->getText (), Str.size ());
99
+ return OwnedString (S, std::move (OwnedPtr));
92
100
}
93
101
}
94
102
You can’t perform that action at this time.
0 commit comments