mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Demangler: make the demangler more tolerant with malformed symbols.
Instead of crashing it just should not demangle malformed symbols. rdar://problem/32113006
This commit is contained in:
@@ -28,12 +28,6 @@ using swift::Demangle::FunctionSigSpecializationParamKind;
|
|||||||
// Private utility functions //
|
// Private utility functions //
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
[[noreturn]]
|
|
||||||
static void demangler_unreachable(const char *Message) {
|
|
||||||
fprintf(stderr, "fatal error: %s\n", Message);
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static bool isDeclName(Node::Kind kind) {
|
static bool isDeclName(Node::Kind kind) {
|
||||||
@@ -1283,6 +1277,8 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
|
|||||||
|
|
||||||
NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
|
NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
|
||||||
NodePointer Spec = demangleSpecAttributes(SpecKind);
|
NodePointer Spec = demangleSpecAttributes(SpecKind);
|
||||||
|
if (!Spec)
|
||||||
|
return nullptr;
|
||||||
NodePointer TyList = popTypeList();
|
NodePointer TyList = popTypeList();
|
||||||
if (!TyList)
|
if (!TyList)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -1907,21 +1903,21 @@ NodePointer Demangler::demangleGenericRequirement() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
name = "m";
|
name = "m";
|
||||||
} else {
|
} else {
|
||||||
demangler_unreachable("Unknown layout constraint");
|
// Unknown layout constraint.
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NameNode = createNode(Node::Kind::Identifier, name);
|
auto NameNode = createNode(Node::Kind::Identifier, name);
|
||||||
auto LayoutRequirement = createWithChildren(
|
auto LayoutRequirement = createWithChildren(
|
||||||
Node::Kind::DependentGenericLayoutRequirement, ConstrTy, NameNode);
|
Node::Kind::DependentGenericLayoutRequirement, ConstrTy, NameNode);
|
||||||
if (size)
|
if (size)
|
||||||
LayoutRequirement->addChild(size, *this);
|
addChild(LayoutRequirement, size);
|
||||||
if (alignment)
|
if (alignment)
|
||||||
LayoutRequirement->addChild(alignment, *this);
|
addChild(LayoutRequirement, alignment);
|
||||||
return LayoutRequirement;
|
return LayoutRequirement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
demangler_unreachable("Unhandled TypeKind in switch.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePointer Demangler::demangleGenericType() {
|
NodePointer Demangler::demangleGenericType() {
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ using namespace Demangle;
|
|||||||
using llvm::Optional;
|
using llvm::Optional;
|
||||||
using llvm::None;
|
using llvm::None;
|
||||||
|
|
||||||
[[noreturn]]
|
|
||||||
static void unreachable(const char *Message) {
|
|
||||||
fprintf(stderr, "fatal error: %s\n", Message);
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct FindPtr {
|
struct FindPtr {
|
||||||
FindPtr(Node *v) : Target(v) {}
|
FindPtr(Node *v) : Target(v) {}
|
||||||
@@ -575,7 +569,8 @@ private:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unreachable("Unknown constant prop specialization");
|
// Unknown constant prop specialization
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool demangleFuncSigSpecializationClosureProp(NodePointer parent) {
|
bool demangleFuncSigSpecializationClosureProp(NodePointer parent) {
|
||||||
@@ -1483,7 +1478,8 @@ private:
|
|||||||
return Factory.createNode(Node::Kind::MetatypeRepresentation,
|
return Factory.createNode(Node::Kind::MetatypeRepresentation,
|
||||||
"@objc_metatype");
|
"@objc_metatype");
|
||||||
|
|
||||||
unreachable("Unhandled metatype representation");
|
// Unknown metatype representation
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePointer demangleGenericRequirement() {
|
NodePointer demangleGenericRequirement() {
|
||||||
@@ -1546,7 +1542,7 @@ private:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
name = "m";
|
name = "m";
|
||||||
} else {
|
} else {
|
||||||
unreachable("Unknown layout constraint");
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePointer second = Factory.createNode(kind, name);
|
NodePointer second = Factory.createNode(kind, name);
|
||||||
@@ -2114,7 +2110,7 @@ private:
|
|||||||
case ImplConventionContext::Parameter: return (FOR_PARAMETER); \
|
case ImplConventionContext::Parameter: return (FOR_PARAMETER); \
|
||||||
case ImplConventionContext::Result: return (FOR_RESULT); \
|
case ImplConventionContext::Result: return (FOR_RESULT); \
|
||||||
} \
|
} \
|
||||||
unreachable("bad context"); \
|
return StringRef(); \
|
||||||
}
|
}
|
||||||
auto Nothing = StringRef();
|
auto Nothing = StringRef();
|
||||||
CASE('a', Nothing, Nothing, "@autoreleased")
|
CASE('a', Nothing, Nothing, "@autoreleased")
|
||||||
@@ -2177,18 +2173,18 @@ private:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
kind = Node::Kind::ImplErrorResult;
|
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;
|
if (convention.empty()) return nullptr;
|
||||||
auto type = demangleType();
|
auto type = demangleType();
|
||||||
if (!type) return nullptr;
|
if (!type) return nullptr;
|
||||||
|
|||||||
@@ -254,4 +254,5 @@ _T04main1_yyF ---> main._() -> ()
|
|||||||
_T04test6testitSiyt_tF ---> test.testit(()) -> Swift.Int
|
_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)
|
_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) () -> ()
|
_T0Ix_IyB_Tr ---> {T:} reabstraction thunk from @callee_owned () -> () to @callee_unowned @convention(block) () -> ()
|
||||||
|
_T0Rml ---> _T0Rml
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user