diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 06:58:13 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 06:58:13 +0000 |
| commit | c372c08dc940db58f1da9cadeb64b4cb3c837704 (patch) | |
| tree | 70636fd3a485eaf16fb7f442c294ac066c76e1a1 /lib/CodeGen | |
| parent | 74b6d06711afd3efbbc47436f1491900994313f3 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen')
| -rw-r--r-- | lib/CodeGen/ConstructorGen.cc | 4 |
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; |
