Skip to content

Commit b008bfc

Browse files
committed
[+0-all-args] Ensure that we always return an enum at +1 from enum constructors.
This was exposed by a test in the SILGen filecheck tests that I am updating out of tree. What is basically happening here is that we construct an enum from a guaranteed argument and then return that enum. We need to ensure in such a case that the return value is still at +1. This commit fixes the issue by using an ensurePlusOne, ensuring that in normal cases we do not emit an extra copy, but in a world where we have +0 arguments, ensures we insert a copy before we return. rdar://34222540
1 parent cfca329 commit b008bfc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void SILGenFunction::emitEnumConstructor(EnumElementDecl *element) {
428428
B.createReturn(ReturnLoc, emitEmptyTuple(Loc));
429429
} else {
430430
assert(enumTI.isLoadable() || !silConv.useLoweredAddresses());
431-
SILValue result = mv.forward(*this);
431+
SILValue result = mv.ensurePlusOne(*this, ReturnLoc).forward(*this);
432432
scope.pop();
433433
B.createReturn(ReturnLoc, result);
434434
}

0 commit comments

Comments
 (0)