From c372c08dc940db58f1da9cadeb64b4cb3c837704 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 06:58:13 +0000 Subject: fix(classes): preserve method-only heap objects and document NEW Allocate at least one byte for method-only classes so their heap addresses remain usable through pointers. Complete constructor diagnostics, field-order and exception coverage, document construction and rebinding, and highlight NEW. Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/ConstructorGen.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/CodeGen') 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; -- cgit v1.3.1-4-g156e