Skip to content

Commit d458ed1

Browse files
committed
[debug-info] Add a helper getDiagnosticName that works for both DebugVarCarryingInst and VarDeclCarryingInst.
1 parent 2365176 commit d458ed1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/swift/SIL/DebugUtils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,26 @@ inline DebugVarCarryingInst DebugVarCarryingInst::getFromValue(SILValue value) {
556556
return DebugVarCarryingInst();
557557
}
558558

559+
static_assert(sizeof(DebugVarCarryingInst) == sizeof(VarDeclCarryingInst) &&
560+
alignof(DebugVarCarryingInst) == alignof(VarDeclCarryingInst),
561+
"Expected debug var carrying inst to have the same "
562+
"size/alignment/layout as VarDeclCarryingInst!");
563+
559564
/// Attempt to discover a StringRef varName for the value \p value based only
560565
/// off of debug var information. If we fail, we return the name "unknown".
561566
inline StringRef getDebugVarName(SILValue value) {
562567
auto inst = DebugVarCarryingInst::getFromValue(value);
563568
return DebugVarCarryingInst::getName(inst);
564569
}
565570

571+
inline StringRef getDiagnosticName(SILValue value) {
572+
if (auto inst = DebugVarCarryingInst::getFromValue(value))
573+
return inst.getName();
574+
if (auto inst = VarDeclCarryingInst::getFromValue(value))
575+
return inst.getName();
576+
return "unknown";
577+
}
578+
566579
} // end namespace swift
567580

568581
#endif // SWIFT_SIL_DEBUGUTILS_H

0 commit comments

Comments
 (0)