From b3ffeb58b5fd25c50852c17391ebfa2a65ff0d78 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Fri, 22 May 2020 18:21:55 -0700 Subject: [PATCH 1/8] Read the label text from the correct child --- include/swift/Demangling/TypeDecoder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/swift/Demangling/TypeDecoder.h b/include/swift/Demangling/TypeDecoder.h index 8bfc73f4e932d..c70b43263aa3a 100644 --- a/include/swift/Demangling/TypeDecoder.h +++ b/include/swift/Demangling/TypeDecoder.h @@ -705,7 +705,7 @@ class TypeDecoder { if (labels.empty()) labels.append(elements.size(), ' '); // Add the label and its terminator. - labels += element->getChild(0)->getText(); + labels += element->getChild(nameIdx)->getText(); labels += ' '; typeChildIndex++; From 24d76ac61cbca915e64882ba20a069eadad6b557 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 26 May 2020 16:06:52 -0700 Subject: [PATCH 2/8] Reject variadic tuple manglings --- include/swift/Demangling/TypeDecoder.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/swift/Demangling/TypeDecoder.h b/include/swift/Demangling/TypeDecoder.h index c70b43263aa3a..5d5ac51570050 100644 --- a/include/swift/Demangling/TypeDecoder.h +++ b/include/swift/Demangling/TypeDecoder.h @@ -693,19 +693,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(0)->getKind() == NodeKind::VariadicMarker) { + return BuiltType(); // Reject a variadic tuple mangling } - if (element->getChild(nameIdx)->getKind() == NodeKind::TupleElementName) { + if (element->getChild(0)->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(nameIdx)->getText(); + labels += element->getChild(0)->getText(); labels += ' '; typeChildIndex++; From 8583ac45d435f5b5c5c86800ec96d5928df7bdfd Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 26 May 2020 16:07:24 -0700 Subject: [PATCH 3/8] Verify demangler doesn't crash on a variadic tuple --- test/Demangle/Inputs/manglings.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index 877d1dcc9e554..50761e6c4df55 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -359,3 +359,4 @@ $sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out $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) $syQo ---> $syQo +$sx1td_t --> $sx1td_t From 21c70d5c92d1ff70fd7ceb25c3267dd3ed7b5fa0 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Thu, 4 Jun 2020 15:16:49 -0700 Subject: [PATCH 4/8] Fix a couple of other test lines that had incorrect ---> markers --- test/Demangle/Inputs/manglings.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index 50761e6c4df55..b7a5e0b5c2a46 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -350,10 +350,10 @@ $S1t1PP10AssocType2_AA1QTN ---> default associated conformance accessor for t.P. $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(red.Res) -> red.Res +$s18resilient_protocol24ResilientDerivedProtocolPxAA0c4BaseE0Tn ---> associated conformance descriptor for resilient_protocol.ResilientDerivedProtocol.A: resilient_protocol.ResilientBaseProtocol +$s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF ---> red.test(red.Res) -> red.Res $s3red4testyAA7OurTypeOy4them05TheirD0Vy5AssocQzGAjE0F8ProtocolAAxAA0c7DerivedH0HD1_AA0c4BaseH0HI1_AieKHA2__HCg_GxmAaLRzlF ---> red.test(A.Type) -> red.OurType> -$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) From 95fff9cbed346355c78c02772fcdf1772f54af13 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Fri, 5 Jun 2020 15:38:23 -0700 Subject: [PATCH 5/8] Re-disable a broken (but unrelated) test; correctly enable the test I just added --- test/Demangle/Inputs/manglings.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index b7a5e0b5c2a46..8d2df8d469805 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -350,7 +350,7 @@ $S1t1PP10AssocType2_AA1QTN ---> default associated conformance accessor for t.P. $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 +$s18resilient_protocol24ResilientDerivedProtocolPxAA0c4BaseE0Tn --> associated conformance descriptor for resilient_protocol.ResilientDerivedProtocol.A: resilient_protocol.ResilientBaseProtocol $s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF ---> red.test(red.Res) -> red.Res $s3red4testyAA7OurTypeOy4them05TheirD0Vy5AssocQzGAjE0F8ProtocolAAxAA0c7DerivedH0HD1_AA0c4BaseH0HI1_AieKHA2__HCg_GxmAaLRzlF ---> red.test(A.Type) -> red.OurType> $s17property_wrappers10WithTuplesV9fractionsSd_S2dtvpfP ---> property wrapper backing initializer of property_wrappers.WithTuples.fractions : (Swift.Double, Swift.Double, Swift.Double) @@ -359,4 +359,4 @@ $sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out $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) $syQo ---> $syQo -$sx1td_t --> $sx1td_t +$sx1td_t ---> $sx1td_t From 9d125ea84a7e2340f8ebf24803bb224e487d7c83 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Mon, 8 Jun 2020 16:54:35 -0700 Subject: [PATCH 6/8] This test verifies the behavior of the demangler, not the type decoder. So valid demanglings of invalid types are actually accepted here. --- test/Demangle/Inputs/manglings.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Demangle/Inputs/manglings.txt b/test/Demangle/Inputs/manglings.txt index 8d2df8d469805..6bc994a37db8f 100644 --- a/test/Demangle/Inputs/manglings.txt +++ b/test/Demangle/Inputs/manglings.txt @@ -359,4 +359,4 @@ $sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out $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) $syQo ---> $syQo -$sx1td_t ---> $sx1td_t +$sx1td_t ---> (t: A...) From 973ec51f41aeaf0468633b62d2354f6e81dd0cde Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 9 Jun 2020 11:37:28 -0700 Subject: [PATCH 7/8] A slightly cleaner way to express the logic here --- include/swift/Demangling/TypeDecoder.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/swift/Demangling/TypeDecoder.h b/include/swift/Demangling/TypeDecoder.h index 04f055865c71e..38f125757bcf0 100644 --- a/include/swift/Demangling/TypeDecoder.h +++ b/include/swift/Demangling/TypeDecoder.h @@ -693,16 +693,16 @@ class TypeDecoder { // If the tuple element is labeled, add its label to 'labels'. unsigned typeChildIndex = 0; - if (element->getChild(0)->getKind() == NodeKind::VariadicMarker) { - return BuiltType(); // Reject a variadic tuple mangling + if (element->getChild(typeChildIndex)->getKind() == NodeKind::VariadicMarker) { + return BuiltType(); } - if (element->getChild(0)->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++; From 0927930b97719208c7c1df73913fcc2668fca5bb Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 9 Jun 2020 11:38:04 -0700 Subject: [PATCH 8/8] New type decoder test to verify that variadic tuples are rejected --- test/TypeDecoder/invalid_types.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/TypeDecoder/invalid_types.swift diff --git a/test/TypeDecoder/invalid_types.swift b/test/TypeDecoder/invalid_types.swift new file mode 100644 index 0000000000000..9f26375b875e0 --- /dev/null +++ b/test/TypeDecoder/invalid_types.swift @@ -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