Do not construct Ir-Types twice for the same type.

This is the same as in PR #1269. The Ir-Types may be initialized
twice (due to pointers, forward references etc.).
This commit fixes hopefully all instances of this problem, using
the same approach in each factory function.

This fixes issue #1112.
This commit is contained in:
Kai Nacke 2016-02-01 21:52:15 +01:00
parent 4aac6351d4
commit 6ca3d730ae
3 changed files with 21 additions and 11 deletions

View file

@ -186,12 +186,16 @@ IrTypeArray *IrTypeArray::get(Type *dt) {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
IrTypeVector::IrTypeVector(Type *dt) : IrType(dt, vector2llvm(dt)) {} IrTypeVector::IrTypeVector(Type *dt, llvm::Type *lt) : IrType(dt, lt) {}
IrTypeVector *IrTypeVector::get(Type *dt) { IrTypeVector *IrTypeVector::get(Type *dt) {
auto t = new IrTypeVector(dt); LLType *lt = vector2llvm(dt);
dt->ctype = t; // Could have already built the type as part of a struct forward reference,
return t; // just as for pointers and arrays.
if (!dt->ctype) {
dt->ctype = new IrTypeVector(dt, lt);
}
return dt->ctype->isVector();
} }
llvm::Type *IrTypeVector::vector2llvm(Type *dt) { llvm::Type *IrTypeVector::vector2llvm(Type *dt) {

View file

@ -182,7 +182,7 @@ public:
protected: protected:
/// ///
explicit IrTypeVector(Type *dt); explicit IrTypeVector(Type *dt, llvm::Type *lt);
static llvm::Type *vector2llvm(Type *dt); static llvm::Type *vector2llvm(Type *dt);
}; };

View file

@ -26,9 +26,12 @@ IrTypeFunction *IrTypeFunction::get(Type *dt) {
IrFuncTy irFty; IrFuncTy irFty;
llvm::Type *lt = DtoFunctionType(dt, irFty, nullptr, nullptr); llvm::Type *lt = DtoFunctionType(dt, irFty, nullptr, nullptr);
auto result = new IrTypeFunction(dt, lt, irFty); // Could have already built the type as part of a struct forward reference,
dt->ctype = result; // just as for pointers and arrays.
return result; if (!dt->ctype) {
dt->ctype = new IrTypeFunction(dt, lt, irFty);
}
return dt->ctype->isFunction();
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -47,7 +50,10 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) {
llvm::Type *types[] = {getVoidPtrType(), getPtrToType(ltf)}; llvm::Type *types[] = {getVoidPtrType(), getPtrToType(ltf)};
LLStructType *lt = LLStructType::get(gIR->context(), types, false); LLStructType *lt = LLStructType::get(gIR->context(), types, false);
auto result = new IrTypeDelegate(t, lt, irFty); // Could have already built the type as part of a struct forward reference,
t->ctype = result; // just as for pointers and arrays.
return result; if (!t->ctype) {
t->ctype = new IrTypeDelegate(t, lt, irFty);
}
return t->ctype->isDelegate();
} }