@@ -1922,48 +1922,53 @@ prepareCallArguments(ApplySite AI, SILBuilder &Builder,
19221922 SILLocation Loc = AI.getLoc ();
19231923 auto substConv = AI.getSubstCalleeConv ();
19241924 unsigned ArgIdx = AI.getCalleeArgIndexOfFirstAppliedArg ();
1925- for (auto &Op : AI.getArgumentOperands ()) {
1926- auto handleConversion = [&]() {
1927- // Rewriting SIL arguments is only for lowered addresses.
1928- if (!substConv.useLoweredAddresses ())
1929- return false ;
19301925
1931- if (ArgIdx < substConv.getSILArgIndexOfFirstParam ()) {
1932- // Handle result arguments.
1933- unsigned formalIdx =
1934- substConv.getIndirectFormalResultIndexForSILArg (ArgIdx);
1935- if (ReInfo.isFormalResultConverted (formalIdx)) {
1936- // The result is converted from indirect to direct. We need to insert
1937- // a store later.
1938- assert (!StoreResultTo);
1939- StoreResultTo = Op.get ();
1940- return true ;
1941- }
1942- } else {
1943- // Handle arguments for formal parameters.
1944- unsigned paramIdx = ArgIdx - substConv.getSILArgIndexOfFirstParam ();
1945- if (ReInfo.isParamConverted (paramIdx)) {
1946- // An argument is converted from indirect to direct. Instead of the
1947- // address we pass the loaded value.
1948- auto argConv = substConv.getSILArgumentConvention (ArgIdx);
1949- SILValue Val;
1950- if (!argConv.isGuaranteedConvention () || isa<PartialApplyInst>(AI)) {
1951- Val = Builder.emitLoadValueOperation (Loc, Op.get (),
1952- LoadOwnershipQualifier::Take);
1953- } else {
1954- Val = Builder.emitLoadBorrowOperation (Loc, Op.get ());
1955- if (Val.getOwnershipKind () == ValueOwnershipKind::Guaranteed)
1956- ArgAtIndexNeedsEndBorrow.push_back (Arguments.size ());
1957- }
1958- Arguments.push_back (Val);
1959- return true ;
1960- }
1926+ auto handleConversion = [&](SILValue InputValue) {
1927+ // Rewriting SIL arguments is only for lowered addresses.
1928+ if (!substConv.useLoweredAddresses ())
1929+ return false ;
1930+
1931+ if (ArgIdx < substConv.getSILArgIndexOfFirstParam ()) {
1932+ // Handle result arguments.
1933+ unsigned formalIdx =
1934+ substConv.getIndirectFormalResultIndexForSILArg (ArgIdx);
1935+ if (!ReInfo.isFormalResultConverted (formalIdx)) {
1936+ return false ;
19611937 }
1938+
1939+ // The result is converted from indirect to direct. We need to insert
1940+ // a store later.
1941+ assert (!StoreResultTo);
1942+ StoreResultTo = InputValue;
1943+ return true ;
1944+ }
1945+
1946+ // Handle arguments for formal parameters.
1947+ unsigned paramIdx = ArgIdx - substConv.getSILArgIndexOfFirstParam ();
1948+ if (!ReInfo.isParamConverted (paramIdx)) {
19621949 return false ;
1963- };
1964- if (!handleConversion ())
1965- Arguments.push_back (Op.get ());
1950+ }
1951+
1952+ // An argument is converted from indirect to direct. Instead of the
1953+ // address we pass the loaded value.
1954+ auto argConv = substConv.getSILArgumentConvention (ArgIdx);
1955+ SILValue Val;
1956+ if (!argConv.isGuaranteedConvention () || isa<PartialApplyInst>(AI)) {
1957+ Val = Builder.emitLoadValueOperation (Loc, InputValue,
1958+ LoadOwnershipQualifier::Take);
1959+ } else {
1960+ Val = Builder.emitLoadBorrowOperation (Loc, InputValue);
1961+ if (Val.getOwnershipKind () == ValueOwnershipKind::Guaranteed)
1962+ ArgAtIndexNeedsEndBorrow.push_back (Arguments.size ());
1963+ }
1964+
1965+ Arguments.push_back (Val);
1966+ return true ;
1967+ };
19661968
1969+ for (auto &Op : AI.getArgumentOperands ()) {
1970+ if (!handleConversion (Op.get ()))
1971+ Arguments.push_back (Op.get ());
19671972 ++ArgIdx;
19681973 }
19691974}
0 commit comments