[Debug info] Map the thrown error type into context when generating debug info

This commit is contained in:
Doug Gregor
2024-01-12 10:10:13 -08:00
parent ff93822ff0
commit c31d45eda6
2 changed files with 20 additions and 2 deletions

View File

@@ -2570,11 +2570,18 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
if (FnTy && (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables))
if (auto ErrorInfo = FnTy->getOptionalErrorResult()) {
GenericContextScope scope(IGM, FnTy->getInvocationGenericSignature());
CanType errorResultTy = ErrorInfo->getReturnValueType(
IGM.getSILModule(), FnTy,
IGM.getMaximalTypeExpansionContext());
SILType SILTy = IGM.silConv.getSILType(
*ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext());
errorResultTy = SILFn->mapTypeIntoContext(errorResultTy)
->getCanonicalType();
SILTy = SILFn->mapTypeIntoContext(SILTy);
auto DTI = DebugTypeInfo::getFromTypeInfo(
ErrorInfo->getReturnValueType(IGM.getSILModule(), FnTy,
IGM.getMaximalTypeExpansionContext()),
errorResultTy,
IGM.getTypeInfo(SILTy), IGM, false);
Error = DBuilder.getOrCreateArray({getOrCreateType(DTI)}).get();
}

View File

@@ -26,6 +26,17 @@ public class C {
}
}
// Function with typed throws.
// CHECK: !DISubprogram(name: "genericRethrow", {{.*}}thrownTypes: ![[GENERIC_THROWN:.*]])
// CHECK: ![[GENERIC_THROWN]] = !{![[GENERIC_THROWN_INNER:.*]]}
// CHECK: ![[GENERIC_THROWN_INNER]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sxD", {{.*}}, elements: ![[GENERIC_THROWN_ELEMENTS:.*]], runtimeLang: DW_LANG_Swift)
// CHECK: ![[GENERIC_THROWN_ELEMENTS]] = !{![[GENERIC_THROWN_ELEMENTS_INNER:.*]]}
// CHECK: ![[GENERIC_THROWN_ELEMENTS_INNER]] = !DIDerivedType(tag: DW_TAG_inheritance, {{.*}}baseType: ![[GENERIC_THROWN_BASE:.*]], extraData: {{.*}})
// CHECK: ![[GENERIC_THROWN_BASE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$ss5Error_pmD", size: {{.*}}, flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$ss5Error_pmD")
public func genericRethrow<E: Error>(fn: () throws(E) -> Void) throws(E) {
try fn()
}
// Negative tests.
// CHECK: !DISubprogram(name: "returnThrowing",
// CHECK-NOT: thrownTypes: