File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -196,19 +196,40 @@ void ManagedValue::dump(raw_ostream &os, unsigned indent) const {
196
196
197
197
ManagedValue ManagedValue::ensurePlusOne (SILGenFunction &SGF,
198
198
SILLocation loc) const {
199
- if (!hasCleanup ()) {
199
+ // Undef can pair with any type of ownership, so it is effectively a +1 value.
200
+ if (isa<SILUndef>(getValue ()))
201
+ return *this ;
202
+
203
+ if (!isPlusOne (SGF)) {
200
204
return copy (SGF, loc);
201
205
}
202
206
return *this ;
203
207
}
204
208
205
209
bool ManagedValue::isPlusOne (SILGenFunction &SGF) const {
206
- // Ignore trivial values and objects with trivial value ownership kind.
207
- if (getType ().isTrivial (SGF.F .getModule ()) ||
208
- (getType ().isObject () &&
209
- getOwnershipKind () == ValueOwnershipKind::Trivial))
210
+ // If this value is SILUndef, return true. SILUndef can always be passed to +1
211
+ // APIs.
212
+ if (isa<SILUndef>(getValue ()))
213
+ return true ;
214
+
215
+ // Ignore trivial values since for our purposes they are always at +1 since
216
+ // they can always be passed to +1 APIs.
217
+ if (getType ().isTrivial (SGF.F .getModule ()))
218
+ return true ;
219
+
220
+ // If we have an object and the object has trivial ownership, the same
221
+ // property applies.
222
+ if (getType ().isObject () && getOwnershipKind () == ValueOwnershipKind::Trivial)
210
223
return true ;
224
+
211
225
return hasCleanup ();
212
226
}
213
227
214
- bool ManagedValue::isPlusZero () const { return hasCleanup (); }
228
+ bool ManagedValue::isPlusZero () const {
229
+ // SILUndef can always be passed to +0 APIs.
230
+ if (isa<SILUndef>(getValue ()))
231
+ return true ;
232
+
233
+ // Otherwise, just check if we have a cleanup.
234
+ return !hasCleanup ();
235
+ }
Original file line number Diff line number Diff line change @@ -706,7 +706,7 @@ RValue RValue::copy(SILGenFunction &SGF, SILLocation loc) const & {
706
706
}
707
707
708
708
RValue RValue::ensurePlusOne (SILGenFunction &SGF, SILLocation loc) && {
709
- if (SGF. getOptions (). EnableGuaranteedNormalArguments && isPlusZero (SGF))
709
+ if (! isPlusOne (SGF))
710
710
return copy (SGF, loc);
711
711
return std::move (*this );
712
712
}
You can’t perform that action at this time.
0 commit comments