diff --git a/BeefySysLib/util/AllocDebug.cpp b/BeefySysLib/util/AllocDebug.cpp index 195553d2..7a0219ce 100644 --- a/BeefySysLib/util/AllocDebug.cpp +++ b/BeefySysLib/util/AllocDebug.cpp @@ -12,7 +12,6 @@ USING_NS_BF; -#ifdef DEF_BF_ALLOCDEBUG ////////////////////////////////////////////////////////////////////////// @@ -190,7 +189,7 @@ void StompInit() gStompInside = false; } -static void* StompAlloc(int size) +void* StompAlloc(int size) { //return malloc(size); @@ -222,7 +221,7 @@ static void* StompAlloc(int size) gStompInside = false; } -static void StompFree(void* addr) +void StompFree(void* addr) { if (gSA_CritSect == NULL) StompInit(); @@ -328,6 +327,8 @@ void DbgHeapFree(const void* ptr, const char* fileName, int lineNum) assert("Not found" == 0); } +#ifdef DEF_BF_ALLOCDEBUG + void DbgHeapCheck() { for (int i = 0; i < (int) gDbgHeapRecords.size(); i++) @@ -391,7 +392,7 @@ void* __cdecl operator new(std::size_t size) #ifdef USE_STOMP return StompAlloc((int)size); #else - return DbgHeapAlloc(size, fileName, lineNum); + return DbgHeapAlloc(size, "", 0); #endif } @@ -427,7 +428,7 @@ void operator delete(void* ptr) #ifdef USE_STOMP StompFree(ptr); #else - DbgHeapFree(ptr, fileName, lineNum); + DbgHeapFree(ptr, "", 0); #endif } @@ -436,7 +437,7 @@ void operator delete[](void* ptr) #ifdef USE_STOMP StompFree(ptr); #else - DbgHeapFree(ptr, fileName, lineNum); + DbgHeapFree(ptr, "", 0); #endif } diff --git a/BeefySysLib/util/AllocDebug.h b/BeefySysLib/util/AllocDebug.h index c73a0590..c0ce11d1 100644 --- a/BeefySysLib/util/AllocDebug.h +++ b/BeefySysLib/util/AllocDebug.h @@ -85,3 +85,6 @@ void BpDump(); #define BP_ALLOC_RAW_T(T) #endif + +void* StompAlloc(int size); +void StompFree(void* addr); \ No newline at end of file diff --git a/BeefySysLib/util/BumpAllocator.h b/BeefySysLib/util/BumpAllocator.h index 5af6a684..2187eb19 100644 --- a/BeefySysLib/util/BumpAllocator.h +++ b/BeefySysLib/util/BumpAllocator.h @@ -5,11 +5,17 @@ #include "../Common.h" //#define BUMPALLOC_TRACKALLOCS +//#define BUMPALLOC_STOMPALLOC #ifdef BUMPALLOC_ETW_TRACING #include "VSCustomNativeHeapEtwProvider.h" #endif +#ifdef BUMPALLOC_STOMPALLOC +void* StompAlloc(int size); +void StompFree(void* addr); +#endif + #ifdef BUMPALLOC_TRACKALLOCS #include "Dictionary.h" #endif @@ -74,7 +80,11 @@ public: mCurAlloc = NULL; mCurPtr = (uint8*)(intptr)ALLOC_SIZE; for (auto ptr : mPools) +#ifdef BUMPALLOC_STOMPALLOC + StompFree(ptr); +#else free(ptr); +#endif mPools.Clear(); mSizes.Clear(); mCurChunkNum = -1; @@ -130,7 +140,11 @@ public: int curSize = (int)(mCurPtr - mCurAlloc); mPrevSizes += curSize; mSizes.push_back(curSize); - mCurAlloc = (uint8*)malloc(ALLOC_SIZE); +#ifdef BUMPALLOC_STOMPALLOC + mCurAlloc = (uint8*)StompAlloc(ALLOC_SIZE); +#else + mCurAlloc = (uint8*)malloc(ALLOC_SIZE); +#endif memset(mCurAlloc, 0, ALLOC_SIZE); mPools.push_back(mCurAlloc); mCurPtr = mCurAlloc; @@ -205,7 +219,11 @@ public: if (wantSize > ALLOC_SIZE / 2) { +#ifdef BUMPALLOC_STOMPALLOC + uint8* bigData = (uint8*)StompAlloc((int)wantSize); +#else uint8* bigData = (uint8*)malloc(wantSize); +#endif memset(bigData, 0, wantSize); mPools.push_back(bigData); return bigData; diff --git a/IDEHelper/Backend/BeIRCodeGen.cpp b/IDEHelper/Backend/BeIRCodeGen.cpp index 43e8bb6f..3bc86c34 100644 --- a/IDEHelper/Backend/BeIRCodeGen.cpp +++ b/IDEHelper/Backend/BeIRCodeGen.cpp @@ -1658,6 +1658,9 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeValue*, val); CMD_PARAM(bool, unnamedAddr); + + BF_ASSERT(BeValueDynCast(val) != NULL); + ((BeGlobalVariable*)val)->mUnnamedAddr = true; } break; @@ -1665,6 +1668,8 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeValue*, val); CMD_PARAM(BeConstant*, initializer); + + BF_ASSERT(BeValueDynCast(val) != NULL); auto globalVariable = (BeGlobalVariable*)val; globalVariable->mInitializer = initializer; @@ -1681,6 +1686,8 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeValue*, val); CMD_PARAM(int, alignment); + BF_ASSERT(BeValueDynCast(val) != NULL); + auto globalVariable = (BeGlobalVariable*)val; globalVariable->mAlign = alignment; BF_ASSERT(alignment > 0); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 629dc624..be120eab 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -4461,7 +4461,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto pointerTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectPointerType, BfIRPopulateType_Full), pointerTypeDataParms); typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectPointerType), true, BfIRLinkageType_External, pointerTypeData, typeDataName); - + mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize); typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType)); } else if (type->IsSizedArray()) @@ -4478,18 +4478,19 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto sizedArrayTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectSizedArrayType, BfIRPopulateType_Full), sizedArrayTypeDataParms); typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectSizedArrayType), true, BfIRLinkageType_External, sizedArrayTypeData, typeDataName); + mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize); typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType)); } else { typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(mContext->mBfTypeType), true, BfIRLinkageType_External, typeData, typeDataName); + mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize); } } else typeDataVar = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(mContext->mBfTypeType)); - - mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize); + mTypeDataRefs[typeInstance] = typeDataVar; return typeDataVar;