Skip to content

Commit 29bc981

Browse files
committed
[Debug info] Map the thrown error type into context when generating debug info
1 parent 64a0fe1 commit 29bc981

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,11 +2570,18 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
25702570
if (FnTy && (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables))
25712571
if (auto ErrorInfo = FnTy->getOptionalErrorResult()) {
25722572
GenericContextScope scope(IGM, FnTy->getInvocationGenericSignature());
2573+
CanType errorResultTy = ErrorInfo->getReturnValueType(
2574+
IGM.getSILModule(), FnTy,
2575+
IGM.getMaximalTypeExpansionContext());
25732576
SILType SILTy = IGM.silConv.getSILType(
25742577
*ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext());
2578+
2579+
errorResultTy = SILFn->mapTypeIntoContext(errorResultTy)
2580+
->getCanonicalType();
2581+
SILTy = SILFn->mapTypeIntoContext(SILTy);
2582+
25752583
auto DTI = DebugTypeInfo::getFromTypeInfo(
2576-
ErrorInfo->getReturnValueType(IGM.getSILModule(), FnTy,
2577-
IGM.getMaximalTypeExpansionContext()),
2584+
errorResultTy,
25782585
IGM.getTypeInfo(SILTy), IGM, false);
25792586
Error = DBuilder.getOrCreateArray({getOrCreateType(DTI)}).get();
25802587
}

test/DebugInfo/Errors.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ public class C {
2626
}
2727
}
2828

29+
// Function with typed throws.
30+
// CHECK: !DISubprogram(name: "genericRethrow", {{.*}}thrownTypes: ![[GENERIC_THROWN:.*]])
31+
// CHECK: ![[GENERIC_THROWN]] = !{![[GENERIC_THROWN_INNER:.*]]}
32+
// CHECK: ![[GENERIC_THROWN_INNER]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sxD", {{.*}}, elements: ![[GENERIC_THROWN_ELEMENTS:.*]], runtimeLang: DW_LANG_Swift)
33+
// CHECK: ![[GENERIC_THROWN_ELEMENTS]] = !{![[GENERIC_THROWN_ELEMENTS_INNER:.*]]}
34+
// CHECK: ![[GENERIC_THROWN_ELEMENTS_INNER]] = !DIDerivedType(tag: DW_TAG_inheritance, {{.*}}baseType: ![[GENERIC_THROWN_BASE:.*]], extraData: {{.*}})
35+
// CHECK: ![[GENERIC_THROWN_BASE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$ss5Error_pmD", size: {{.*}}, flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$ss5Error_pmD")
36+
public func genericRethrow<E: Error>(fn: () throws(E) -> Void) throws(E) {
37+
try fn()
38+
}
39+
2940
// Negative tests.
3041
// CHECK: !DISubprogram(name: "returnThrowing",
3142
// CHECK-NOT: thrownTypes:

0 commit comments

Comments
 (0)