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.
This commit is contained in:
Erik Eckstein
2025-06-18 20:54:53 +02:00
parent c482b09878
commit c70298220d
2 changed files with 22 additions and 3 deletions

View File

@@ -1151,6 +1151,7 @@ struct BridgedBuilder{
BRIDGED_INLINE swift::SILBuilder unbridged() const;
BRIDGED_INLINE swift::SILLocation regularLoc() const;
BRIDGED_INLINE swift::SILLocation returnLoc() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createBuiltin(BridgedStringRef name,
BridgedType type,

View File

@@ -2117,7 +2117,25 @@ swift::SILBuilder BridgedBuilder::unbridged() const {
}
swift::SILLocation BridgedBuilder::regularLoc() const {
return swift::RegularLocation(loc.getLoc().getLocation());
auto l = loc.getLoc().getLocation();
switch (l.getKind()) {
case swift::SILLocation::ReturnKind:
case swift::SILLocation::ImplicitReturnKind:
case swift::SILLocation::ArtificialUnreachableKind:
return swift::RegularLocation(l);
default:
return l;
}
}
swift::SILLocation BridgedBuilder::returnLoc() const {
auto l = loc.getLoc().getLocation();
switch (l.getKind()) {
case swift::SILLocation::ArtificialUnreachableKind:
return swift::RegularLocation(l);
default:
return l;
}
}
BridgedInstruction BridgedBuilder::createBuiltin(BridgedStringRef name, BridgedType type,
@@ -2399,7 +2417,7 @@ BridgedInstruction BridgedBuilder::createWitnessMethod(BridgedCanType lookupType
BridgedInstruction BridgedBuilder::createReturn(BridgedValue op) const {
return {unbridged().createReturn(regularLoc(), op.getSILValue())};
return {unbridged().createReturn(returnLoc(), op.getSILValue())};
}
BridgedInstruction BridgedBuilder::createThrow(BridgedValue op) const {
@@ -2465,7 +2483,7 @@ BridgedInstruction BridgedBuilder::createBranch(BridgedBasicBlock destBlock, Bri
}
BridgedInstruction BridgedBuilder::createUnreachable() const {
return {unbridged().createUnreachable(regularLoc())};
return {unbridged().createUnreachable(loc.getLoc().getLocation())};
}
BridgedInstruction BridgedBuilder::createObject(BridgedType type,