Skip to content

[SIL] Fix incorrect handling of 'forwarding' when parsing SIL #38065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,9 +2520,10 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

auto parseForwardingOwnershipKind =
[&](ValueOwnershipKind &forwardingKind) -> bool {
if (P.consumeIf(tok::comma)) {
return parseVerbatim("forwarding") ||
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
if (P.consumeIf(tok::comma) &&
P.Tok.is(tok::identifier) && P.Tok.getText() == "forwarding") {
P.consumeToken();
return P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
parseSILOwnership(forwardingKind);
}
return false;
Expand Down Expand Up @@ -2944,7 +2945,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
ResultVal =
B.createOpenExistentialBoxValue(InstLoc, Val, Ty, forwardingOwnership);
Expand All @@ -2964,7 +2965,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal =
Expand All @@ -2978,7 +2979,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal =
Expand Down Expand Up @@ -3204,7 +3205,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal = B.createMarkDependence(InstLoc, Val, Base, forwardingOwnership);
Expand Down Expand Up @@ -3403,7 +3404,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
return true;
}

if (parseSILDebugLocation(InstLoc, B)) {
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true)) {
return true;
}

Expand Down Expand Up @@ -3522,7 +3523,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal =
Expand Down Expand Up @@ -3600,7 +3601,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

auto opaque = Lowering::AbstractionPattern::getOpaque();
Expand Down Expand Up @@ -3683,7 +3684,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal =
Expand Down Expand Up @@ -4157,7 +4158,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
: ValueOwnershipKind(OwnershipKind::None);

if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal = B.createTuple(InstLoc, Ty2, OpList, forwardingOwnership);
Expand Down Expand Up @@ -4231,7 +4232,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
: ValueOwnershipKind(OwnershipKind::None);

if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal =
Expand All @@ -4253,7 +4254,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
if (Opcode == SILInstructionKind::UncheckedEnumDataInst)
parseForwardingOwnershipKind(forwardingOwnership);

if (parseSILDebugLocation(InstLoc, B))
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
EnumElementDecl *Elt = cast<EnumElementDecl>(EltRef.getDecl());
auto ResultTy = Operand->getType().getEnumElementType(
Expand Down Expand Up @@ -4312,7 +4313,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
return true;
}

if (parseSILDebugLocation(InstLoc, B))
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
auto ResultTy = TT->getElement(Field).getType()->getCanonicalType();
if (Opcode == SILInstructionKind::TupleElementAddrInst)
Expand Down Expand Up @@ -4588,7 +4589,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
F && F->hasOwnership() ? mergeSILValueOwnership(OpList)
: ValueOwnershipKind(OwnershipKind::None);
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B)) {
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true)) {
return true;
}
if (Opcode == SILInstructionKind::StructInst) {
Expand All @@ -4614,7 +4615,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
return true;
}

if (parseSILDebugLocation(InstLoc, B))
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
if (!FieldV || !isa<VarDecl>(FieldV)) {
P.diagnose(NameLoc, diag::sil_struct_inst_wrong_field);
Expand Down Expand Up @@ -4830,7 +4831,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
if (parseForwardingOwnershipKind(forwardingOwnership))
return true;
}
if (parseSILDebugLocation(InstLoc, B))
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

// Resolve the results.
Expand Down Expand Up @@ -4893,7 +4894,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
return true;
}

if (parseSILDebugLocation(InstLoc, B))
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
if (Opcode == SILInstructionKind::SwitchEnumInst) {
ResultVal = B.createSwitchEnum(InstLoc, Val, DefaultBB, CaseBBs, None,
Expand Down Expand Up @@ -5143,7 +5144,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ArrayRef<ProtocolConformanceRef> conformances =
Expand Down Expand Up @@ -5311,7 +5312,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership(OwnershipKind::None);
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
auto *parameterIndices = IndexSubset::get(
P.Context, fnType->getNumParameters(), rawParameterIndices);
Expand Down Expand Up @@ -5360,7 +5361,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,

ValueOwnershipKind forwardingOwnership(OwnershipKind::None);
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

auto *parameterIndicesSubset = IndexSubset::get(
Expand Down Expand Up @@ -5406,7 +5407,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
ValueOwnershipKind forwardingOwnership =
functionOperand.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;

ResultVal = B.createDifferentiableFunctionExtract(
Expand Down Expand Up @@ -5434,7 +5435,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
ValueOwnershipKind forwardingOwnership =
functionOperand.getOwnershipKind();
if (parseForwardingOwnershipKind(forwardingOwnership) ||
parseSILDebugLocation(InstLoc, B))
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
return true;
ResultVal = B.createLinearFunctionExtract(
InstLoc, extractee, functionOperand, forwardingOwnership);
Expand Down
26 changes: 26 additions & 0 deletions test/SIL/Parser/debug_info.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo %s | %FileCheck %s
sil_stage canonical

import Builtin
import Swift

struct TheStruct {
var data : Builtin.Int64
init()
}

sil_scope 1 { parent @struct_debug_info_test : $@convention(thin) (TheStruct) -> TheStruct }

// SR-14814: Make sure the `forwarding` directive being optional in the presence
// of debug info directives (i.e. `loc` and `scope`)

// CHECK-LABEL: sil [transparent] @struct_debug_info_test :
sil [transparent] @struct_debug_info_test : $@convention(thin) (TheStruct) -> TheStruct {
bb0(%0 : $TheStruct):
// CHECK: %1 = struct_extract %0 : $TheStruct, #TheStruct.data, loc "input.swift":3:4, scope 1
%1 = struct_extract %0 : $TheStruct, #TheStruct.data, loc "input.swift":3:4, scope 1
// CHECK: %2 = struct $TheStruct (%1 : $Builtin.Int64), loc "input.swift":5:6, scope 1
%2 = struct $TheStruct (%1 : $Builtin.Int64), loc "input.swift":5:6, scope 1
return %2 : $TheStruct, loc "input.swift":7:8, scope 1
}
// CHECK: } // end sil function 'struct_debug_info_test'