[Mangler] Check the order of generic type parameters before mangling them to avoid assertion hit.

This commit is contained in:
Xi Ge
2016-12-09 09:51:40 -08:00
committed by GitHub
parent 6b14beb84d
commit 6bbdf4a837
7 changed files with 43 additions and 10 deletions

View File

@@ -568,7 +568,8 @@ void Mangler::mangleDeclType(const ValueDecl *decl,
requirements, requirementsBuf);
// Mangle the generic signature, if any.
if (!genericParams.empty() || !requirements.empty()) {
if ((!genericParams.empty() || !requirements.empty()) &&
checkGenericParamsOrder(genericParams)) {
Buffer << 'u';
mangleGenericSignatureParts(genericParams, initialParamDepth,
requirements);
@@ -591,6 +592,24 @@ void Mangler::mangleConstrainedType(CanType type) {
mangleType(type, 0);
}
bool Mangler::
checkGenericParamsOrder(ArrayRef<swift::GenericTypeParamType *> params) {
unsigned depth = 0;
unsigned count = 0;
for (auto param : params) {
if (param->getDepth() > depth) {
depth = param->getDepth();
count = 0;
} else if (param->getDepth() < depth) {
return false;
}
if (param->getIndex() != count)
return false;
count ++;
}
return true;
}
void Mangler::mangleGenericSignatureParts(
ArrayRef<GenericTypeParamType*> params,
unsigned initialParamDepth,