Skip to content

Commit d70e93b

Browse files
committed
[Demangler] Fix OldRemangler to cope with single argument functions.
The Demangler can sometimes output ArgumentTuples containing a single argument without placing that argument inside a Tuple node. OldRemangler failed to take account of this and either crashed or failed with an assertion failure depending on whether assertions were enabled or not. rdar://63678072
1 parent 528764c commit d70e93b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

lib/Demangling/OldRemangler.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,31 @@ static NodePointer applyParamLabels(NodePointer LabelList, NodePointer OrigType,
164164
auto ParamsType = Factory.createNode(Node::Kind::ArgumentTuple);
165165
auto Tuple = Factory.createNode(Node::Kind::Tuple);
166166

167-
auto OrigTuple = ArgTuple->getFirstChild()->getFirstChild();
168-
assert(OrigTuple->getKind() == Node::Kind::Tuple);
169-
170-
for (unsigned i = 0, n = OrigTuple->getNumChildren(); i != n; ++i) {
171-
const auto Label = LabelList->getChild(i);
167+
auto processParameter = [&](NodePointer Label, NodePointer Param) {
172168
if (Label->getKind() == Node::Kind::FirstElementMarker) {
173-
Tuple->addChild(OrigTuple->getChild(i), Factory);
174-
continue;
169+
Tuple->addChild(Param, Factory);
170+
return;
175171
}
176172

177-
auto OrigElt = OrigTuple->getChild(i);
178-
auto NewElt = Factory.createNode(Node::Kind::TupleElement);
179-
180-
NewElt->addChild(Factory.createNodeWithAllocatedText(
173+
auto NewParam = Factory.createNode(Node::Kind::TupleElement);
174+
NewParam->addChild(Factory.createNodeWithAllocatedText(
181175
Node::Kind::TupleElementName, Label->getText()),
182-
Factory);
176+
Factory);
183177

184-
for (auto &Child : *OrigElt)
185-
NewElt->addChild(Child, Factory);
178+
for (auto &Child : *Param)
179+
NewParam->addChild(Child, Factory);
180+
181+
Tuple->addChild(NewParam, Factory);
182+
};
186183

187-
Tuple->addChild(NewElt, Factory);
184+
auto OrigTuple = ArgTuple->getFirstChild()->getFirstChild();
185+
186+
if (OrigTuple->getKind() != Node::Kind::Tuple) {
187+
processParameter(LabelList->getChild(0), OrigTuple);
188+
} else {
189+
for (unsigned i = 0, n = OrigTuple->getNumChildren(); i != n; ++i) {
190+
processParameter(LabelList->getChild(i), OrigTuple->getChild(i));
191+
}
188192
}
189193

190194
auto Type = Factory.createNode(Node::Kind::Type);

test/Demangle/remangle.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ RUN: diff %t.input %t.output
99
// CHECK: Swift.(Mystruct in _7B40D7ED6632C2BEA2CA3BFFD57E3435)
1010
RUN: swift-demangle -remangle-objc-rt '$ss8Mystruct33_7B40D7ED6632C2BEA2CA3BFFD57E3435LLV' | %FileCheck %s
1111

12+
// CHECK-OLD: r in _.?(Swift.UnsafeRawPointer) -> Swift.UnsafeRawPointer
13+
RUN: swift-demangle -remangle-objc-rt '$s1_1?1PSVSVF1rP' | %FileCheck -check-prefix CHECK-OLD %s
14+
1215
// CHECK-GENERICEXT: Swift._ContiguousArrayStorage<(extension in Swift):Swift.FlattenSequence<StdlibCollectionUnittest.MinimalBidirectionalCollection<StdlibCollectionUnittest.MinimalBidirectionalCollection<Swift.Int>>>.Index>
1316
RUN: swift-demangle -remangle-objc-rt '$ss23_ContiguousArrayStorageCys15FlattenSequenceVsE5IndexVy24StdlibCollectionUnittest020MinimalBidirectionalH0VyAIySiGG_GGD' | %FileCheck -check-prefix CHECK-GENERICEXT %s
14-

0 commit comments

Comments
 (0)