aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ConstructorGen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/ConstructorGen.cc')
-rw-r--r--lib/CodeGen/ConstructorGen.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/CodeGen/ConstructorGen.cc b/lib/CodeGen/ConstructorGen.cc
index f726590..99f21df 100644
--- a/lib/CodeGen/ConstructorGen.cc
+++ b/lib/CodeGen/ConstructorGen.cc
@@ -62,6 +62,10 @@ void CodeGen::emitAssignment(const LValueInfo &Target, ExprAST *Expr, const Symb
}
Value *Size = Builder->CreateIntCast(Types->getSizeOfConstant(Class->LLVMType),
Type::getIntNTy(*TheContext, sizeof(std::size_t) * CHAR_BIT), false);
+ // Method-only classes have zero-sized LLVM structs but still need
+ // a non-null object address (MALLOC(0) deliberately returns null).
+ Size = Builder->CreateSelect(Builder->CreateICmpEQ(Size, ConstantInt::get(Size->getType(), 0)),
+ ConstantInt::get(Size->getType(), 1), Size);
Value *Object = Memory->emitAllocate(Size, New->getLine());
Builder->CreateStore(Types->getZeroValue(Class->Name), Object);
if (!emitConstruct(Class->Name, Object, New->getArgs(), New->getLine())) return;