Skip to content

Commit 7341dc8

Browse files
authored
Merge pull request #38065 from mshockwave/dev-fix-sr-14814
[SIL] Fix incorrect handling of 'forwarding' when parsing SIL
2 parents d312e80 + 007ec33 commit 7341dc8

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,9 +2519,10 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
25192519

25202520
auto parseForwardingOwnershipKind =
25212521
[&](ValueOwnershipKind &forwardingKind) -> bool {
2522-
if (P.consumeIf(tok::comma)) {
2523-
return parseVerbatim("forwarding") ||
2524-
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
2522+
if (P.consumeIf(tok::comma) &&
2523+
P.Tok.is(tok::identifier) && P.Tok.getText() == "forwarding") {
2524+
P.consumeToken();
2525+
return P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
25252526
parseSILOwnership(forwardingKind);
25262527
}
25272528
return false;
@@ -2943,7 +2944,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
29432944

29442945
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
29452946
if (parseForwardingOwnershipKind(forwardingOwnership) ||
2946-
parseSILDebugLocation(InstLoc, B))
2947+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
29472948
return true;
29482949
ResultVal =
29492950
B.createOpenExistentialBoxValue(InstLoc, Val, Ty, forwardingOwnership);
@@ -2963,7 +2964,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
29632964

29642965
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
29652966
if (parseForwardingOwnershipKind(forwardingOwnership) ||
2966-
parseSILDebugLocation(InstLoc, B))
2967+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
29672968
return true;
29682969

29692970
ResultVal =
@@ -2977,7 +2978,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
29772978

29782979
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
29792980
if (parseForwardingOwnershipKind(forwardingOwnership) ||
2980-
parseSILDebugLocation(InstLoc, B))
2981+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
29812982
return true;
29822983

29832984
ResultVal =
@@ -3203,7 +3204,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
32033204

32043205
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
32053206
if (parseForwardingOwnershipKind(forwardingOwnership) ||
3206-
parseSILDebugLocation(InstLoc, B))
3207+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
32073208
return true;
32083209

32093210
ResultVal = B.createMarkDependence(InstLoc, Val, Base, forwardingOwnership);
@@ -3402,7 +3403,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
34023403
return true;
34033404
}
34043405

3405-
if (parseSILDebugLocation(InstLoc, B)) {
3406+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true)) {
34063407
return true;
34073408
}
34083409

@@ -3521,7 +3522,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
35213522

35223523
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
35233524
if (parseForwardingOwnershipKind(forwardingOwnership) ||
3524-
parseSILDebugLocation(InstLoc, B))
3525+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
35253526
return true;
35263527

35273528
ResultVal =
@@ -3599,7 +3600,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
35993600

36003601
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
36013602
if (parseForwardingOwnershipKind(forwardingOwnership) ||
3602-
parseSILDebugLocation(InstLoc, B))
3603+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
36033604
return true;
36043605

36053606
auto opaque = Lowering::AbstractionPattern::getOpaque();
@@ -3682,7 +3683,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
36823683

36833684
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
36843685
if (parseForwardingOwnershipKind(forwardingOwnership) ||
3685-
parseSILDebugLocation(InstLoc, B))
3686+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
36863687
return true;
36873688

36883689
ResultVal =
@@ -4156,7 +4157,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
41564157
: ValueOwnershipKind(OwnershipKind::None);
41574158

41584159
if (parseForwardingOwnershipKind(forwardingOwnership) ||
4159-
parseSILDebugLocation(InstLoc, B))
4160+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
41604161
return true;
41614162

41624163
ResultVal = B.createTuple(InstLoc, Ty2, OpList, forwardingOwnership);
@@ -4230,7 +4231,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
42304231
: ValueOwnershipKind(OwnershipKind::None);
42314232

42324233
if (parseForwardingOwnershipKind(forwardingOwnership) ||
4233-
parseSILDebugLocation(InstLoc, B))
4234+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
42344235
return true;
42354236

42364237
ResultVal =
@@ -4252,7 +4253,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
42524253
if (Opcode == SILInstructionKind::UncheckedEnumDataInst)
42534254
parseForwardingOwnershipKind(forwardingOwnership);
42544255

4255-
if (parseSILDebugLocation(InstLoc, B))
4256+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
42564257
return true;
42574258
EnumElementDecl *Elt = cast<EnumElementDecl>(EltRef.getDecl());
42584259
auto ResultTy = Operand->getType().getEnumElementType(
@@ -4311,7 +4312,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
43114312
return true;
43124313
}
43134314

4314-
if (parseSILDebugLocation(InstLoc, B))
4315+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
43154316
return true;
43164317
auto ResultTy = TT->getElement(Field).getType()->getCanonicalType();
43174318
if (Opcode == SILInstructionKind::TupleElementAddrInst)
@@ -4587,7 +4588,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
45874588
F && F->hasOwnership() ? mergeSILValueOwnership(OpList)
45884589
: ValueOwnershipKind(OwnershipKind::None);
45894590
if (parseForwardingOwnershipKind(forwardingOwnership) ||
4590-
parseSILDebugLocation(InstLoc, B)) {
4591+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true)) {
45914592
return true;
45924593
}
45934594
if (Opcode == SILInstructionKind::StructInst) {
@@ -4613,7 +4614,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
46134614
return true;
46144615
}
46154616

4616-
if (parseSILDebugLocation(InstLoc, B))
4617+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
46174618
return true;
46184619
if (!FieldV || !isa<VarDecl>(FieldV)) {
46194620
P.diagnose(NameLoc, diag::sil_struct_inst_wrong_field);
@@ -4829,7 +4830,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
48294830
if (parseForwardingOwnershipKind(forwardingOwnership))
48304831
return true;
48314832
}
4832-
if (parseSILDebugLocation(InstLoc, B))
4833+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
48334834
return true;
48344835

48354836
// Resolve the results.
@@ -4892,7 +4893,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
48924893
return true;
48934894
}
48944895

4895-
if (parseSILDebugLocation(InstLoc, B))
4896+
if (parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
48964897
return true;
48974898
if (Opcode == SILInstructionKind::SwitchEnumInst) {
48984899
ResultVal = B.createSwitchEnum(InstLoc, Val, DefaultBB, CaseBBs, None,
@@ -5142,7 +5143,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
51425143

51435144
ValueOwnershipKind forwardingOwnership = Val.getOwnershipKind();
51445145
if (parseForwardingOwnershipKind(forwardingOwnership) ||
5145-
parseSILDebugLocation(InstLoc, B))
5146+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
51465147
return true;
51475148

51485149
ArrayRef<ProtocolConformanceRef> conformances =
@@ -5310,7 +5311,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
53105311

53115312
ValueOwnershipKind forwardingOwnership(OwnershipKind::None);
53125313
if (parseForwardingOwnershipKind(forwardingOwnership) ||
5313-
parseSILDebugLocation(InstLoc, B))
5314+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
53145315
return true;
53155316
auto *parameterIndices = IndexSubset::get(
53165317
P.Context, fnType->getNumParameters(), rawParameterIndices);
@@ -5359,7 +5360,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
53595360

53605361
ValueOwnershipKind forwardingOwnership(OwnershipKind::None);
53615362
if (parseForwardingOwnershipKind(forwardingOwnership) ||
5362-
parseSILDebugLocation(InstLoc, B))
5363+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
53635364
return true;
53645365

53655366
auto *parameterIndicesSubset = IndexSubset::get(
@@ -5405,7 +5406,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
54055406
ValueOwnershipKind forwardingOwnership =
54065407
functionOperand.getOwnershipKind();
54075408
if (parseForwardingOwnershipKind(forwardingOwnership) ||
5408-
parseSILDebugLocation(InstLoc, B))
5409+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
54095410
return true;
54105411

54115412
ResultVal = B.createDifferentiableFunctionExtract(
@@ -5433,7 +5434,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
54335434
ValueOwnershipKind forwardingOwnership =
54345435
functionOperand.getOwnershipKind();
54355436
if (parseForwardingOwnershipKind(forwardingOwnership) ||
5436-
parseSILDebugLocation(InstLoc, B))
5437+
parseSILDebugLocation(InstLoc, B, /*parsedComma=*/ true))
54375438
return true;
54385439
ResultVal = B.createLinearFunctionExtract(
54395440
InstLoc, extractee, functionOperand, forwardingOwnership);

test/SIL/Parser/debug_info.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo %s | %FileCheck %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
struct TheStruct {
8+
var data : Builtin.Int64
9+
init()
10+
}
11+
12+
sil_scope 1 { parent @struct_debug_info_test : $@convention(thin) (TheStruct) -> TheStruct }
13+
14+
// SR-14814: Make sure the `forwarding` directive being optional in the presence
15+
// of debug info directives (i.e. `loc` and `scope`)
16+
17+
// CHECK-LABEL: sil [transparent] @struct_debug_info_test :
18+
sil [transparent] @struct_debug_info_test : $@convention(thin) (TheStruct) -> TheStruct {
19+
bb0(%0 : $TheStruct):
20+
// CHECK: %1 = struct_extract %0 : $TheStruct, #TheStruct.data, loc "input.swift":3:4, scope 1
21+
%1 = struct_extract %0 : $TheStruct, #TheStruct.data, loc "input.swift":3:4, scope 1
22+
// CHECK: %2 = struct $TheStruct (%1 : $Builtin.Int64), loc "input.swift":5:6, scope 1
23+
%2 = struct $TheStruct (%1 : $Builtin.Int64), loc "input.swift":5:6, scope 1
24+
return %2 : $TheStruct, loc "input.swift":7:8, scope 1
25+
}
26+
// CHECK: } // end sil function 'struct_debug_info_test'

0 commit comments

Comments
 (0)