From 522c5806473929647415340c8e2f599288ae3cc8 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sun, 19 Apr 2009 00:06:23 +0200 Subject: [PATCH] Do not emit declare or emit a vtbl entry for bodyless functions in abstract classes. Maybe the better fix would be to adjust FuncDeclaration::isAbstract, but there may be unwelcome sideeffects. --- gen/functions.cpp | 7 +++++-- ir/irclass.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index c829223c..aaa64ab0 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -361,8 +361,11 @@ void DtoResolveFunction(FuncDeclaration* fdecl) Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); LOG_SCOPE; - // queue declaration unless the function is abstract without body - if (!fdecl->isAbstract() || fdecl->fbody) + // queue declaration unless the function is abstract without body; + // bodyless functions in an abstract class are considered abstract + ClassDeclaration* cd = fdecl->parent->isClassDeclaration(); + bool isabstract = fdecl->isAbstract() || (cd && cd->isAbstract()); + if (!isabstract || fdecl->fbody) { DtoDeclareFunction(fdecl); } diff --git a/ir/irclass.cpp b/ir/irclass.cpp index 15661639..ffda5af9 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -132,7 +132,7 @@ LLConstant * IrStruct::getVtblInit() FuncDeclaration* fd = dsym->isFuncDeclaration(); assert(fd && "vtbl entry not a function"); - if (fd->isAbstract() && !fd->fbody) + if ((cd->isAbstract() || fd->isAbstract()) && !fd->fbody) { c = getNullValue(DtoType(fd->type->pointerTo())); } @@ -335,7 +335,7 @@ llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instan FuncDeclaration* fd = dsym->isFuncDeclaration(); assert(fd && "vtbl entry not a function"); - assert(!(fd->isAbstract() && !fd->fbody) && + assert(!((fd->isAbstract() || cd->isAbstract()) && !fd->fbody) && "null symbol in interface implementation vtable"); fd->codegen(Type::sir);