Skip to content

Commit 32af2dd

Browse files
committed
Swift SIL: an autogenerated Location needs to keep the debug scope.
Therefore, instead of creating an autogenerated location with a null scope, make an existing location `autoGenerated`.
1 parent 275861f commit 32af2dd

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import SILBridging
1515
public struct Location {
1616
let bridged: BridgedLocation
1717

18-
public static var autoGeneratedLocation: Location {
19-
Location(bridged: SILLocation_getAutogeneratedLocation())
18+
/// Keeps the debug scope but marks it as auto-generated.
19+
public var autoGenerated: Location {
20+
Location(bridged: SILLocation_getAutogeneratedLocation(bridged))
2021
}
2122
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ SwiftInt SILType_getCaseIdxOfEnumType(BridgedType type,
334334

335335
BridgedSubstitutionMap SubstitutionMap_getEmpty();
336336

337-
BridgedLocation SILLocation_getAutogeneratedLocation();
337+
BridgedLocation SILLocation_getAutogeneratedLocation(BridgedLocation loc);
338338

339339
BridgedBasicBlock SILArgument_getParent(BridgedArgument argument);
340340
BridgedArgumentConvention SILArgument_getConvention(BridgedArgument argument);

include/swift/SIL/SILBridgingUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ inline SILValue castToSILValue(BridgedValue value) {
4949
return static_cast<ValueBase *>(value.obj);
5050
}
5151

52+
inline SILDebugLocation castToDebugLocation(BridgedLocation loc) {
53+
return *reinterpret_cast<SILDebugLocation *>(&loc);
54+
}
55+
5256
inline SILType castToSILType(BridgedType type) {
5357
return SILType::getFromOpaqueValue(type.typePtr);
5458
}

lib/SIL/Utils/SILBridging.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,10 @@ BridgedSubstitutionMap SubstitutionMap_getEmpty() {
556556
// SILLocation
557557
//===----------------------------------------------------------------------===//
558558

559-
BridgedLocation SILLocation_getAutogeneratedLocation() {
560-
SILDebugLocation loc;
561-
return *reinterpret_cast<BridgedLocation *>(&loc);
559+
BridgedLocation SILLocation_getAutogeneratedLocation(BridgedLocation loc) {
560+
SILDebugLocation autoGenLoc(RegularLocation::getAutoGeneratedLocation(),
561+
castToDebugLocation(loc).getScope());
562+
return *reinterpret_cast<BridgedLocation *>(&autoGenLoc);
562563
}
563564

564565
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)