Skip to content

Demangler: make the demangler more tolerant with malformed symbols. #9657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ using swift::Demangle::FunctionSigSpecializationParamKind;
// Private utility functions //
//////////////////////////////////

[[noreturn]]
static void demangler_unreachable(const char *Message) {
fprintf(stderr, "fatal error: %s\n", Message);
std::abort();
}

namespace {

static bool isDeclName(Node::Kind kind) {
Expand Down Expand Up @@ -1283,6 +1277,8 @@ NodePointer Demangler::demangleThunkOrSpecialization() {

NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
NodePointer Spec = demangleSpecAttributes(SpecKind);
if (!Spec)
return nullptr;
NodePointer TyList = popTypeList();
if (!TyList)
return nullptr;
Expand Down Expand Up @@ -1907,21 +1903,21 @@ NodePointer Demangler::demangleGenericRequirement() {
return nullptr;
name = "m";
} else {
demangler_unreachable("Unknown layout constraint");
// Unknown layout constraint.
return nullptr;
}

auto NameNode = createNode(Node::Kind::Identifier, name);
auto LayoutRequirement = createWithChildren(
Node::Kind::DependentGenericLayoutRequirement, ConstrTy, NameNode);
if (size)
LayoutRequirement->addChild(size, *this);
addChild(LayoutRequirement, size);
if (alignment)
LayoutRequirement->addChild(alignment, *this);
addChild(LayoutRequirement, alignment);
return LayoutRequirement;
}
}

demangler_unreachable("Unhandled TypeKind in switch.");
return nullptr;
}

NodePointer Demangler::demangleGenericType() {
Expand Down
38 changes: 17 additions & 21 deletions lib/Demangling/OldDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ using namespace Demangle;
using llvm::Optional;
using llvm::None;

[[noreturn]]
static void unreachable(const char *Message) {
fprintf(stderr, "fatal error: %s\n", Message);
std::abort();
}

namespace {
struct FindPtr {
FindPtr(Node *v) : Target(v) {}
Expand Down Expand Up @@ -575,7 +569,8 @@ class OldDemangler {
return true;
}

unreachable("Unknown constant prop specialization");
// Unknown constant prop specialization
return false;
}

bool demangleFuncSigSpecializationClosureProp(NodePointer parent) {
Expand Down Expand Up @@ -1483,7 +1478,8 @@ class OldDemangler {
return Factory.createNode(Node::Kind::MetatypeRepresentation,
"@objc_metatype");

unreachable("Unhandled metatype representation");
// Unknown metatype representation
return nullptr;
}

NodePointer demangleGenericRequirement() {
Expand Down Expand Up @@ -1546,7 +1542,7 @@ class OldDemangler {
return nullptr;
name = "m";
} else {
unreachable("Unknown layout constraint");
return nullptr;
}

NodePointer second = Factory.createNode(kind, name);
Expand Down Expand Up @@ -2114,7 +2110,7 @@ class OldDemangler {
case ImplConventionContext::Parameter: return (FOR_PARAMETER); \
case ImplConventionContext::Result: return (FOR_RESULT); \
} \
unreachable("bad context"); \
return StringRef(); \
}
auto Nothing = StringRef();
CASE('a', Nothing, Nothing, "@autoreleased")
Expand Down Expand Up @@ -2177,18 +2173,18 @@ class OldDemangler {
return nullptr;
kind = Node::Kind::ImplErrorResult;
}

auto getContext = [](Node::Kind kind) -> ImplConventionContext {
if (kind == Node::Kind::ImplParameter)
return ImplConventionContext::Parameter;
else if (kind == Node::Kind::ImplResult
|| kind == Node::Kind::ImplErrorResult)
return ImplConventionContext::Result;
else
unreachable("unexpected node kind");
};

auto convention = demangleImplConvention(getContext(kind));
ImplConventionContext ConvCtx;
if (kind == Node::Kind::ImplParameter) {
ConvCtx = ImplConventionContext::Parameter;
} else if (kind == Node::Kind::ImplResult
|| kind == Node::Kind::ImplErrorResult) {
ConvCtx = ImplConventionContext::Result;
} else {
return nullptr;
}

auto convention = demangleImplConvention(ConvCtx);
if (convention.empty()) return nullptr;
auto type = demangleType();
if (!type) return nullptr;
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,5 @@ _T04main1_yyF ---> main._() -> ()
_T04test6testitSiyt_tF ---> test.testit(()) -> Swift.Int
_T08_ElementQzSbs5Error_pIxxdzo_ABSbsAC_pIxidzo_s26RangeReplaceableCollectionRzABRLClTR ---> {T:} reabstraction thunk helper <A where A: Swift.RangeReplaceableCollection, A._Element: AnyObject> from @callee_owned (@owned A._Element) -> (@unowned Swift.Bool, @error @owned Swift.Error) to @callee_owned (@in A._Element) -> (@unowned Swift.Bool, @error @owned Swift.Error)
_T0Ix_IyB_Tr ---> {T:} reabstraction thunk from @callee_owned () -> () to @callee_unowned @convention(block) () -> ()
_T0Rml ---> _T0Rml