mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed issues using object flags on on-debug default alloc
This commit is contained in:
parent
66216ce5d9
commit
63c6421413
8 changed files with 50 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
#if BF_ENABLE_REALTIME_LEAK_CHECK || BF_DEBUG_ALLOC
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS || BF_DEBUG_ALLOC
|
||||
#define BF_DBG_RUNTIME
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@ namespace System.Diagnostics
|
|||
|
||||
#if !DEBUG
|
||||
[CallingConvention(.Cdecl), SkipCall]
|
||||
#endif
|
||||
#else
|
||||
[CallingConvention(.Cdecl)]
|
||||
#endif
|
||||
static extern void Write(char8* str, int strLen);
|
||||
|
||||
public static void WriteLine(StringView line)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#if BF_ENABLE_REALTIME_LEAK_CHECK || BF_DEBUG_ALLOC
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS || BF_DEBUG_ALLOC
|
||||
#define BF_DBG_RUNTIME
|
||||
#endif
|
||||
|
||||
|
|
|
@ -589,9 +589,10 @@ namespace IDE.Compiler
|
|||
SetOpt(options.mEmitDynamicCastCheck, .EmitDynamicCastCheck);
|
||||
SetOpt(enableObjectDebugFlags, .EnableObjectDebugFlags);
|
||||
SetOpt(emitObjectAccessCheck, .EmitObjectAccessCheck);
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
SetOpt(options.mEnableRealtimeLeakCheck, .EnableRealtimeLeakCheck);
|
||||
#endif
|
||||
|
||||
if (options.LeakCheckingEnabled)
|
||||
SetOpt(options.mEnableRealtimeLeakCheck, .EnableRealtimeLeakCheck);
|
||||
|
||||
SetOpt(options.mEnableSideStack, .EnableSideStack);
|
||||
#if !CLI
|
||||
SetOpt(options.mAllowHotSwapping, .EnableHotSwapping);
|
||||
|
|
|
@ -7180,13 +7180,12 @@ namespace IDE
|
|||
|
||||
// Only supported on Windows at the moment
|
||||
bool hasLeakCheck = false;
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
if (workspaceOptions.mEnableRealtimeLeakCheck && workspaceOptions.mEnableObjectDebugFlags)
|
||||
if (workspaceOptions.LeakCheckingEnabled)
|
||||
{
|
||||
hasLeakCheck = true;
|
||||
macroList.Add("BF_ENABLE_REALTIME_LEAK_CHECK");
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((workspaceOptions.mAllocType == .Debug) || (hasLeakCheck))
|
||||
macroList.Add("BF_DEBUG_ALLOC");
|
||||
|
||||
|
|
|
@ -245,6 +245,18 @@ namespace IDE
|
|||
delete configSel;
|
||||
}
|
||||
|
||||
public bool LeakCheckingEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
return mEnableRealtimeLeakCheck && mEnableObjectDebugFlags && (mAllocType == .Debug);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTestProject(Project project)
|
||||
{
|
||||
return ((mBuildKind == .Test) &&
|
||||
|
|
|
@ -1943,7 +1943,12 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
CMD_PARAM(llvm::FunctionType*, type);
|
||||
BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read();
|
||||
CMD_PARAM(String, name);
|
||||
SetResult(curId, llvm::Function::Create(type, LLVMMapLinkageType(linkageType), name.c_str(), mLLVMModule));
|
||||
|
||||
auto func = mLLVMModule->getFunction(name.c_str());
|
||||
if ((func == NULL) || (func->getFunctionType() != type))
|
||||
func = llvm::Function::Create(type, LLVMMapLinkageType(linkageType), name.c_str(), mLLVMModule);
|
||||
|
||||
SetResult(curId, func);
|
||||
}
|
||||
break;
|
||||
case BfIRCmd_EnsureFunctionPatchable:
|
||||
|
|
|
@ -8120,10 +8120,20 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
|||
}
|
||||
}
|
||||
|
||||
bool wasAllocated = false;
|
||||
if (!result)
|
||||
{
|
||||
if (hasCustomAllocator)
|
||||
result = AllocBytes(allocTarget.mRefNode, allocTarget, typeInstance, sizeValue, GetConstValue(typeInstance->mInstAlign), (BfAllocFlags)(BfAllocFlags_ZeroMemory | BfAllocFlags_NoDefaultToMalloc));
|
||||
else if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mCompiler->mOptions.mDebugAlloc))
|
||||
{
|
||||
SizedArray<BfIRValue, 4> llvmArgs;
|
||||
llvmArgs.push_back(sizeValue);
|
||||
auto irFunc = GetBuiltInFunc(BfBuiltInFuncType_Malloc);
|
||||
result = mBfIRBuilder->CreateCall(irFunc, llvmArgs);
|
||||
result = mBfIRBuilder->CreateBitCast(result, mBfIRBuilder->MapTypeInstPtr(typeInstance));
|
||||
wasAllocated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
|
@ -8139,6 +8149,16 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
|||
(isResultInitialized ? "Dbg_ObjectCreatedEx" : "Dbg_ObjectAllocatedEx") :
|
||||
(isResultInitialized ? "Dbg_ObjectCreated" : "Dbg_ObjectAllocated"));
|
||||
mBfIRBuilder->CreateCall(objectCreatedMethod.mFunc, llvmArgs);
|
||||
|
||||
if (wasAllocated)
|
||||
{
|
||||
auto byteType = GetPrimitiveType(BfTypeCode_UInt8);
|
||||
auto bytePtrType = CreatePointerType(byteType);
|
||||
auto flagsPtr = mBfIRBuilder->CreateBitCast(result, mBfIRBuilder->MapType(bytePtrType));
|
||||
auto flagsVal = mBfIRBuilder->CreateLoad(flagsPtr);
|
||||
auto modifiedFlagsVal = mBfIRBuilder->CreateOr(flagsVal, mBfIRBuilder->CreateConst(BfTypeCode_UInt8, /*BF_OBJECTFLAG_ALLOCATED*/4));
|
||||
mBfIRBuilder->CreateStore(modifiedFlagsVal, flagsPtr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue