Skip to content

Commit 43acc1f

Browse files
committed
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.
1 parent a2d7c9f commit 43acc1f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

gen/runtime.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ static LLType* rt_dg2()
168168
return LLStructType::get(gIR->context(), types, false);
169169
}
170170

171+
template<typename DECL>
172+
static void ensureDecl(DECL *decl, const char *msg)
173+
{
174+
if (!decl || !decl->type)
175+
{
176+
Logger::println("Missing class declaration: %s\n", msg);
177+
error(Loc(), "Missing class declaration: %s", msg);
178+
errorSupplemental(Loc(), "Please check that object.di is included and valid");
179+
fatal();
180+
}
181+
}
182+
171183
static void LLVM_D_BuildRuntimeModule()
172184
{
173185
Logger::println("building runtime module");
@@ -187,10 +199,16 @@ static void LLVM_D_BuildRuntimeModule()
187199
LLType* wstringTy = DtoType(Type::twchar->arrayOf());
188200
LLType* dstringTy = DtoType(Type::tdchar->arrayOf());
189201

202+
ensureDecl(ClassDeclaration::object, "Object");
190203
LLType* objectTy = DtoType(ClassDeclaration::object->type);
204+
ensureDecl(ClassDeclaration::classinfo, "ClassInfo");
191205
LLType* classInfoTy = DtoType(ClassDeclaration::classinfo->type);
206+
ensureDecl(Type::typeinfo, "TypeInfo");
192207
LLType* typeInfoTy = DtoType(Type::typeinfo->type);
208+
ensureDecl(Type::typeinfoassociativearray, "TypeInfo_AssociativeArray");
193209
LLType* aaTypeInfoTy = DtoType(Type::typeinfoassociativearray->type);
210+
ensureDecl(Module::moduleinfo, "ModuleInfo");
211+
LLType* moduleInfoPtr = getPtrToType(DtoType(Module::moduleinfo->type));
194212

195213
LLType* aaTy = rt_ptr(LLStructType::get(gIR->context()));
196214

@@ -306,7 +324,7 @@ static void LLVM_D_BuildRuntimeModule()
306324
llvm::StringRef fname("_d_array_bounds");
307325
llvm::StringRef fname2("_d_switch_error");
308326
LLType *types[] = {
309-
getPtrToType(DtoType(Module::moduleinfo->type)),
327+
moduleInfoPtr,
310328
intTy
311329
};
312330
LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false);

0 commit comments

Comments
 (0)