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
|
#define BF_DBG_RUNTIME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ namespace System.Diagnostics
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
[CallingConvention(.Cdecl), SkipCall]
|
[CallingConvention(.Cdecl), SkipCall]
|
||||||
#endif
|
#else
|
||||||
[CallingConvention(.Cdecl)]
|
[CallingConvention(.Cdecl)]
|
||||||
|
#endif
|
||||||
static extern void Write(char8* str, int strLen);
|
static extern void Write(char8* str, int strLen);
|
||||||
|
|
||||||
public static void WriteLine(StringView line)
|
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
|
#define BF_DBG_RUNTIME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -589,9 +589,10 @@ namespace IDE.Compiler
|
||||||
SetOpt(options.mEmitDynamicCastCheck, .EmitDynamicCastCheck);
|
SetOpt(options.mEmitDynamicCastCheck, .EmitDynamicCastCheck);
|
||||||
SetOpt(enableObjectDebugFlags, .EnableObjectDebugFlags);
|
SetOpt(enableObjectDebugFlags, .EnableObjectDebugFlags);
|
||||||
SetOpt(emitObjectAccessCheck, .EmitObjectAccessCheck);
|
SetOpt(emitObjectAccessCheck, .EmitObjectAccessCheck);
|
||||||
#if BF_PLATFORM_WINDOWS
|
|
||||||
|
if (options.LeakCheckingEnabled)
|
||||||
SetOpt(options.mEnableRealtimeLeakCheck, .EnableRealtimeLeakCheck);
|
SetOpt(options.mEnableRealtimeLeakCheck, .EnableRealtimeLeakCheck);
|
||||||
#endif
|
|
||||||
SetOpt(options.mEnableSideStack, .EnableSideStack);
|
SetOpt(options.mEnableSideStack, .EnableSideStack);
|
||||||
#if !CLI
|
#if !CLI
|
||||||
SetOpt(options.mAllowHotSwapping, .EnableHotSwapping);
|
SetOpt(options.mAllowHotSwapping, .EnableHotSwapping);
|
||||||
|
|
|
@ -7180,13 +7180,12 @@ namespace IDE
|
||||||
|
|
||||||
// Only supported on Windows at the moment
|
// Only supported on Windows at the moment
|
||||||
bool hasLeakCheck = false;
|
bool hasLeakCheck = false;
|
||||||
#if BF_PLATFORM_WINDOWS
|
if (workspaceOptions.LeakCheckingEnabled)
|
||||||
if (workspaceOptions.mEnableRealtimeLeakCheck && workspaceOptions.mEnableObjectDebugFlags)
|
|
||||||
{
|
{
|
||||||
hasLeakCheck = true;
|
hasLeakCheck = true;
|
||||||
macroList.Add("BF_ENABLE_REALTIME_LEAK_CHECK");
|
macroList.Add("BF_ENABLE_REALTIME_LEAK_CHECK");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if ((workspaceOptions.mAllocType == .Debug) || (hasLeakCheck))
|
if ((workspaceOptions.mAllocType == .Debug) || (hasLeakCheck))
|
||||||
macroList.Add("BF_DEBUG_ALLOC");
|
macroList.Add("BF_DEBUG_ALLOC");
|
||||||
|
|
||||||
|
|
|
@ -245,6 +245,18 @@ namespace IDE
|
||||||
delete configSel;
|
delete configSel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool LeakCheckingEnabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if BF_PLATFORM_WINDOWS
|
||||||
|
return mEnableRealtimeLeakCheck && mEnableObjectDebugFlags && (mAllocType == .Debug);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsTestProject(Project project)
|
public bool IsTestProject(Project project)
|
||||||
{
|
{
|
||||||
return ((mBuildKind == .Test) &&
|
return ((mBuildKind == .Test) &&
|
||||||
|
|
|
@ -1943,7 +1943,12 @@ void BfIRCodeGen::HandleNextCmd()
|
||||||
CMD_PARAM(llvm::FunctionType*, type);
|
CMD_PARAM(llvm::FunctionType*, type);
|
||||||
BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read();
|
BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read();
|
||||||
CMD_PARAM(String, name);
|
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;
|
break;
|
||||||
case BfIRCmd_EnsureFunctionPatchable:
|
case BfIRCmd_EnsureFunctionPatchable:
|
||||||
|
|
|
@ -8120,10 +8120,20 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wasAllocated = false;
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
if (hasCustomAllocator)
|
if (hasCustomAllocator)
|
||||||
result = AllocBytes(allocTarget.mRefNode, allocTarget, typeInstance, sizeValue, GetConstValue(typeInstance->mInstAlign), (BfAllocFlags)(BfAllocFlags_ZeroMemory | BfAllocFlags_NoDefaultToMalloc));
|
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)
|
if (result)
|
||||||
|
@ -8139,6 +8149,16 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
(isResultInitialized ? "Dbg_ObjectCreatedEx" : "Dbg_ObjectAllocatedEx") :
|
(isResultInitialized ? "Dbg_ObjectCreatedEx" : "Dbg_ObjectAllocatedEx") :
|
||||||
(isResultInitialized ? "Dbg_ObjectCreated" : "Dbg_ObjectAllocated"));
|
(isResultInitialized ? "Dbg_ObjectCreated" : "Dbg_ObjectAllocated"));
|
||||||
mBfIRBuilder->CreateCall(objectCreatedMethod.mFunc, llvmArgs);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue