Fix llvm assert when calling StructType::setBody from getClassType.

It's possible that while adding the fields to a struct we may complete the struct
due to circular type definitions. Detect that case and return the result right away.
This commit is contained in:
Eugene Rozenfeld 2015-04-21 17:16:59 -07:00
Родитель d1d9ece652
Коммит 9b0f4ec7ec
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -1305,7 +1305,7 @@ Type *GenIR::getClassType(CORINFO_CLASS_HANDLE ClassHandle, bool IsRefClass,
// causes trouble with certain recursive type graphs, for example:
//
// class A { B b; }
// class B : extends A { int c };
// class B : extends A { int c; }
//
// We need to know the size of A before we can finish B. So we can't
// ask for B's details while filling out A.
@ -1405,6 +1405,15 @@ Type *GenIR::getClassType(CORINFO_CLASS_HANDLE ClassHandle, bool IsRefClass,
}
}
// It's possible that while adding the fields to this struct we already
// completed the struct. For example:
// class A { B b; }
// struct B { A a; }
// In that case we are already done.
if (!StructTy->isOpaque()) {
return ResultTy;
}
// Install the field list (even if empty) to complete the struct.
// Since padding is explicit, this is an LLVM packed struct.
StructTy->setBody(Fields, true /* isPacked */);