Skip to content

Commit c702982

Browse files
committed
SIL: fix debug locations for various kind of instructions
There are some restrictions for which kind of locations can be on which kind of instructions. This change implements them correctly.
1 parent c482b09 commit c702982

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ struct BridgedBuilder{
11511151

11521152
BRIDGED_INLINE swift::SILBuilder unbridged() const;
11531153
BRIDGED_INLINE swift::SILLocation regularLoc() const;
1154+
BRIDGED_INLINE swift::SILLocation returnLoc() const;
11541155

11551156
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createBuiltin(BridgedStringRef name,
11561157
BridgedType type,

include/swift/SIL/SILBridgingImpl.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,25 @@ swift::SILBuilder BridgedBuilder::unbridged() const {
21172117
}
21182118

21192119
swift::SILLocation BridgedBuilder::regularLoc() const {
2120-
return swift::RegularLocation(loc.getLoc().getLocation());
2120+
auto l = loc.getLoc().getLocation();
2121+
switch (l.getKind()) {
2122+
case swift::SILLocation::ReturnKind:
2123+
case swift::SILLocation::ImplicitReturnKind:
2124+
case swift::SILLocation::ArtificialUnreachableKind:
2125+
return swift::RegularLocation(l);
2126+
default:
2127+
return l;
2128+
}
2129+
}
2130+
2131+
swift::SILLocation BridgedBuilder::returnLoc() const {
2132+
auto l = loc.getLoc().getLocation();
2133+
switch (l.getKind()) {
2134+
case swift::SILLocation::ArtificialUnreachableKind:
2135+
return swift::RegularLocation(l);
2136+
default:
2137+
return l;
2138+
}
21212139
}
21222140

21232141
BridgedInstruction BridgedBuilder::createBuiltin(BridgedStringRef name, BridgedType type,
@@ -2399,7 +2417,7 @@ BridgedInstruction BridgedBuilder::createWitnessMethod(BridgedCanType lookupType
23992417

24002418

24012419
BridgedInstruction BridgedBuilder::createReturn(BridgedValue op) const {
2402-
return {unbridged().createReturn(regularLoc(), op.getSILValue())};
2420+
return {unbridged().createReturn(returnLoc(), op.getSILValue())};
24032421
}
24042422

24052423
BridgedInstruction BridgedBuilder::createThrow(BridgedValue op) const {
@@ -2465,7 +2483,7 @@ BridgedInstruction BridgedBuilder::createBranch(BridgedBasicBlock destBlock, Bri
24652483
}
24662484

24672485
BridgedInstruction BridgedBuilder::createUnreachable() const {
2468-
return {unbridged().createUnreachable(regularLoc())};
2486+
return {unbridged().createUnreachable(loc.getLoc().getLocation())};
24692487
}
24702488

24712489
BridgedInstruction BridgedBuilder::createObject(BridgedType type,

0 commit comments

Comments
 (0)