mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-01 20:43:13 +01:00
Allocate objects on the stack if they (a) don't have a destructor, and
(b) don't override the delete operator (on top of the regular conditions for stack allocation that also apply to arrays, structs, etc.). The "no destructor" clause is not strictly necessary, but calling them at the right time would be tricky to say the least; it would involve, among other things, "manually" inserting a try-finally block around anything that might throw exceptions not caught in the current function. Note: objects with custom new operators are automatically ignored because they don't use the regular allocation runtime call, so there's no need to pay special attention to them.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "gen/llvmhelpers.h"
|
||||
#include "gen/utils.h"
|
||||
#include "gen/arrays.h"
|
||||
#include "gen/metadata.h"
|
||||
|
||||
#include "ir/irstruct.h"
|
||||
#include "ir/irtypeclass.h"
|
||||
@@ -70,6 +71,29 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol()
|
||||
classInfo = new llvm::GlobalVariable(
|
||||
tc->getPA().get(), false, _linkage, NULL, initname, gIR->module);
|
||||
|
||||
#ifdef USE_METADATA
|
||||
// Generate some metadata on this ClassInfo if it's for a class.
|
||||
|
||||
ClassDeclaration* classdecl = aggrdecl->isClassDeclaration();
|
||||
if (classdecl && !aggrdecl->isInterfaceDeclaration()) {
|
||||
// Gather information
|
||||
const LLType* type = DtoType(aggrdecl->type);
|
||||
const LLType* bodyType = llvm::cast<LLPointerType>(type)->getElementType();
|
||||
bool hasDestructor = (classdecl->dtor != NULL);
|
||||
bool hasCustomDelete = (classdecl->aggDelete != NULL);
|
||||
// Construct the fields
|
||||
LLConstant* mdVals[CD_NumFields];
|
||||
mdVals[CD_BodyType] = llvm::UndefValue::get(bodyType);
|
||||
mdVals[CD_Finalize] = LLConstantInt::get(LLType::Int1Ty, hasDestructor);
|
||||
mdVals[CD_CustomDelete] = LLConstantInt::get(LLType::Int1Ty, hasCustomDelete);
|
||||
// Construct the metadata
|
||||
llvm::MDNode* metadata = llvm::MDNode::get(mdVals, CD_NumFields);
|
||||
// Insert it into the module
|
||||
new llvm::GlobalVariable(metadata->getType(), true,
|
||||
METADATA_LINKAGE_TYPE, metadata, CD_PREFIX + initname, gIR->module);
|
||||
}
|
||||
#endif
|
||||
|
||||
return classInfo;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user