Demangling variadic tuples should not crash (#31988)

The TypeDecoder logic had a bug that caused crashes when it saw a tuple type with a variadic marker.  Since variadic tuples aren't supported, this changes the logic to cleanly reject a tuple with a variadic marker.
This commit is contained in:
tbkka
2020-06-12 10:02:47 -07:00
committed by GitHub
parent 6527a216fb
commit 0855829dc5
3 changed files with 19 additions and 9 deletions

View File

@@ -716,19 +716,16 @@ class TypeDecoder {
// If the tuple element is labeled, add its label to 'labels'.
unsigned typeChildIndex = 0;
unsigned nameIdx = 0;
if (element->getChild(nameIdx)->getKind() == NodeKind::VariadicMarker) {
variadic = true;
nameIdx = 1;
typeChildIndex = 1;
if (element->getChild(typeChildIndex)->getKind() == NodeKind::VariadicMarker) {
return BuiltType();
}
if (element->getChild(nameIdx)->getKind() == NodeKind::TupleElementName) {
if (element->getChild(typeChildIndex)->getKind() == NodeKind::TupleElementName) {
// Add spaces to terminate all the previous labels if this
// is the first we've seen.
if (labels.empty()) labels.append(elements.size(), ' ');
// Add the label and its terminator.
labels += element->getChild(0)->getText();
labels += element->getChild(typeChildIndex)->getText();
labels += ' ';
typeChildIndex++;

View File

@@ -351,12 +351,13 @@ $sSD5IndexVy__GD ---> $sSD5IndexVy__GD
$s4test3StrCACycfC ---> {T:$s4test3StrCACycfc} test.Str.__allocating_init() -> test.Str
$s18keypaths_inlinable13KeypathStructV8computedSSvpACTKq ---> key path getter for keypaths_inlinable.KeypathStruct.computed : Swift.String : keypaths_inlinable.KeypathStruct, serialized
$s18resilient_protocol24ResilientDerivedProtocolPxAA0c4BaseE0Tn --> associated conformance descriptor for resilient_protocol.ResilientDerivedProtocol.A: resilient_protocol.ResilientBaseProtocol
$s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF --> red.test<A, B where B: Swift.Error>(red.Res<A, B>) -> red.Res<A, [B]>
$s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF ---> red.test<A, B where B: Swift.Error>(red.Res<A, B>) -> red.Res<A, [B]>
$s3red4testyAA7OurTypeOy4them05TheirD0Vy5AssocQzGAjE0F8ProtocolAAxAA0c7DerivedH0HD1_AA0c4BaseH0HI1_AieKHA2__HCg_GxmAaLRzlF ---> red.test<A where A: red.OurDerivedProtocol>(A.Type) -> red.OurType<them.TheirType<A.Assoc>>
$s17property_wrappers10WithTuplesV9fractionsSd_S2dtvpfP --> property wrapper backing initializer of property_wrappers.WithTuples.fractions : (Swift.Double, Swift.Double, Swift.Double)
$s17property_wrappers10WithTuplesV9fractionsSd_S2dtvpfP ---> property wrapper backing initializer of property_wrappers.WithTuples.fractions : (Swift.Double, Swift.Double, Swift.Double)
$sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTOTA ---> {T:$sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTO} partial apply forwarder for @nonobjc __C.OS_dispatch_queue.sync(execute: () -> ()) -> ()
$sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out B)
$sxq_Ilgnr_D ---> @differentiable(linear) @callee_guaranteed (@in_guaranteed A) -> (@out B)
$sS3fIedgyywd_D ---> @escaping @differentiable @callee_guaranteed (@unowned Swift.Float, @unowned @noDerivative Swift.Float) -> (@unowned Swift.Float)
$sS5fIedtyyywddw_D ---> @escaping @differentiable @convention(thin) (@unowned Swift.Float, @unowned Swift.Float, @unowned @noDerivative Swift.Float) -> (@unowned Swift.Float, @unowned @noDerivative Swift.Float)
$syQo ---> $syQo
$sx1td_t ---> (t: A...)

View File

@@ -0,0 +1,12 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-executable %s -g -o %t/structural_types -emit-module
// RUN: sed -ne '/\/\/ *DEMANGLE: /s/\/\/ *DEMANGLE: *//p' < %s > %t/input
// RUN: %lldb-moduleimport-test %t/structural_types -type-from-mangled=%t/input | %FileCheck %s
// If this were supported, it would be `(t: τ_0_0...)`
// But tuples with a variadic 'd' marker are not actually valid Swift types, so
// the type decoder rejects them.
// DEMANGLE: $sx1td_t
// CHECK: Can't resolve type of $sx1td_t