mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-03 05:23:14 +01:00
Check if basic types are read from object.di before usage.
If object.di was not read or is incomplete then basic types may be missing. This results in a crash if they are used during runtime initialization. This fixes #551.
This commit is contained in:
@@ -168,6 +168,18 @@ static LLType* rt_dg2()
|
||||
return LLStructType::get(gIR->context(), types, false);
|
||||
}
|
||||
|
||||
template<typename DECL>
|
||||
static void ensureDecl(DECL *decl, const char *msg)
|
||||
{
|
||||
if (!decl || !decl->type)
|
||||
{
|
||||
Logger::println("Missing class declaration: %s\n", msg);
|
||||
error(Loc(), "Missing class declaration: %s", msg);
|
||||
errorSupplemental(Loc(), "Please check that object.di is included and valid");
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
static void LLVM_D_BuildRuntimeModule()
|
||||
{
|
||||
Logger::println("building runtime module");
|
||||
@@ -187,10 +199,16 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
LLType* wstringTy = DtoType(Type::twchar->arrayOf());
|
||||
LLType* dstringTy = DtoType(Type::tdchar->arrayOf());
|
||||
|
||||
ensureDecl(ClassDeclaration::object, "Object");
|
||||
LLType* objectTy = DtoType(ClassDeclaration::object->type);
|
||||
ensureDecl(ClassDeclaration::classinfo, "ClassInfo");
|
||||
LLType* classInfoTy = DtoType(ClassDeclaration::classinfo->type);
|
||||
ensureDecl(Type::typeinfo, "TypeInfo");
|
||||
LLType* typeInfoTy = DtoType(Type::typeinfo->type);
|
||||
ensureDecl(Type::typeinfoassociativearray, "TypeInfo_AssociativeArray");
|
||||
LLType* aaTypeInfoTy = DtoType(Type::typeinfoassociativearray->type);
|
||||
ensureDecl(Module::moduleinfo, "ModuleInfo");
|
||||
LLType* moduleInfoPtr = getPtrToType(DtoType(Module::moduleinfo->type));
|
||||
|
||||
LLType* aaTy = rt_ptr(LLStructType::get(gIR->context()));
|
||||
|
||||
@@ -306,7 +324,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||
llvm::StringRef fname("_d_array_bounds");
|
||||
llvm::StringRef fname2("_d_switch_error");
|
||||
LLType *types[] = {
|
||||
getPtrToType(DtoType(Module::moduleinfo->type)),
|
||||
moduleInfoPtr,
|
||||
intTy
|
||||
};
|
||||
LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false);
|
||||
|
||||
Reference in New Issue
Block a user