mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Fixed crash related to global var alignment
This commit is contained in:
parent
2c6a72ba68
commit
aaccaa97e2
5 changed files with 40 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -85,3 +85,6 @@ void BpDump();
|
|||
#define BP_ALLOC_RAW_T(T)
|
||||
|
||||
#endif
|
||||
|
||||
void* StompAlloc(int size);
|
||||
void StompFree(void* addr);
|
|
@ -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;
|
||||
|
|
|
@ -1658,6 +1658,9 @@ void BeIRCodeGen::HandleNextCmd()
|
|||
{
|
||||
CMD_PARAM(BeValue*, val);
|
||||
CMD_PARAM(bool, unnamedAddr);
|
||||
|
||||
BF_ASSERT(BeValueDynCast<BeGlobalVariable>(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<BeGlobalVariable>(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<BeGlobalVariable>(val) != NULL);
|
||||
|
||||
auto globalVariable = (BeGlobalVariable*)val;
|
||||
globalVariable->mAlign = alignment;
|
||||
BF_ASSERT(alignment > 0);
|
||||
|
|
|
@ -4461,7 +4461,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& 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<int, int>& 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue