Skip to content

Commit 3229b6c

Browse files
authored
Merge pull request #14810 from gottesmm/pr-1a89d0f11ea25e2736a635c92ac02835c1940be7
2 parents 80dabe9 + 2c19203 commit 3229b6c

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/SILGen/ManagedValue.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,40 @@ void ManagedValue::dump(raw_ostream &os, unsigned indent) const {
196196

197197
ManagedValue ManagedValue::ensurePlusOne(SILGenFunction &SGF,
198198
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)) {
200204
return copy(SGF, loc);
201205
}
202206
return *this;
203207
}
204208

205209
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)
210223
return true;
224+
211225
return hasCleanup();
212226
}
213227

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+
}

lib/SILGen/RValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ RValue RValue::copy(SILGenFunction &SGF, SILLocation loc) const & {
706706
}
707707

708708
RValue RValue::ensurePlusOne(SILGenFunction &SGF, SILLocation loc) && {
709-
if (SGF.getOptions().EnableGuaranteedNormalArguments && isPlusZero(SGF))
709+
if (!isPlusOne(SGF))
710710
return copy(SGF, loc);
711711
return std::move(*this);
712712
}

0 commit comments

Comments
 (0)