mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Removed lifetime.start and lifetime.end for LLVM
The lifetime annotations were causing errors in release builds, related to stack colorization
This commit is contained in:
parent
28c24e98d7
commit
c0b73cdd6f
5 changed files with 60 additions and 20 deletions
|
@ -1424,6 +1424,9 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
case BfIRCmd_LifetimeEnd:
|
case BfIRCmd_LifetimeEnd:
|
||||||
{
|
{
|
||||||
CMD_PARAM(BeValue*, val);
|
CMD_PARAM(BeValue*, val);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
val->mLifetimeEnded = true;
|
||||||
|
#endif
|
||||||
auto inst = mBeModule->AllocInst<BeLifetimeEndInst>();
|
auto inst = mBeModule->AllocInst<BeLifetimeEndInst>();
|
||||||
inst->mPtr = val;
|
inst->mPtr = val;
|
||||||
SetResult(curId, inst);
|
SetResult(curId, inst);
|
||||||
|
@ -3045,6 +3048,9 @@ BeValue* BeIRCodeGen::GetBeValue(int id)
|
||||||
{
|
{
|
||||||
auto& result = mResults[id];
|
auto& result = mResults[id];
|
||||||
BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value);
|
BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
BF_ASSERT(!result.mBeValue->mLifetimeEnded);
|
||||||
|
#endif
|
||||||
return result.mBeValue;
|
return result.mBeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12043,6 +12043,7 @@ void BfExprEvaluator::InjectMixin(BfAstNode* targetSrc, BfTypedValue target, boo
|
||||||
value = newLocalVar->mConstValue;
|
value = newLocalVar->mConstValue;
|
||||||
|
|
||||||
auto aliasValue = mModule->mBfIRBuilder->CreateAliasValue(value);
|
auto aliasValue = mModule->mBfIRBuilder->CreateAliasValue(value);
|
||||||
|
if (mModule->WantsLifetimes())
|
||||||
scopeData.mDeferredLifetimeEnds.Add(aliasValue);
|
scopeData.mDeferredLifetimeEnds.Add(aliasValue);
|
||||||
|
|
||||||
if (newLocalVar->mAddr)
|
if (newLocalVar->mAddr)
|
||||||
|
@ -15318,6 +15319,16 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (indexArgument.mType->IsPrimitiveType())
|
||||||
|
{
|
||||||
|
auto primType = (BfPrimitiveType*)indexArgument.mType;
|
||||||
|
if ((!primType->IsSigned()) && (primType->mSize < 8))
|
||||||
|
{
|
||||||
|
// GEP will always do a signed upcast so we need to cast manually if we are unsigned
|
||||||
|
indexArgument = BfTypedValue(mModule->mBfIRBuilder->CreateNumericCast(indexArgument.mValue, false, BfTypeCode_IntPtr), mModule->GetPrimitiveType(BfTypeCode_IntPtr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mModule->PopulateType(target.mType);
|
mModule->PopulateType(target.mType);
|
||||||
if (target.mType->IsSizedArray())
|
if (target.mType->IsSizedArray())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1788,7 +1788,7 @@ BfIRValue BfModule::CreateAlloca(BfType* type, bool addLifetime, const char* nam
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
mBfIRBuilder->SetName(allocaInst, name);
|
mBfIRBuilder->SetName(allocaInst, name);
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||||
if (addLifetime)
|
if ((addLifetime) && (WantsLifetimes()))
|
||||||
{
|
{
|
||||||
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
||||||
|
@ -1812,7 +1812,7 @@ BfIRValue BfModule::CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime,
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
mBfIRBuilder->SetName(allocaInst, name);
|
mBfIRBuilder->SetName(allocaInst, name);
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||||
if (addLifetime)
|
if ((addLifetime) && (WantsLifetimes()))
|
||||||
{
|
{
|
||||||
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
||||||
|
@ -7456,9 +7456,12 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
castedVal = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapTypeInstPtr(typeInstance));
|
castedVal = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapTypeInstPtr(typeInstance));
|
||||||
mBfIRBuilder->ClearDebugLocation(castedVal);
|
mBfIRBuilder->ClearDebugLocation(castedVal);
|
||||||
mBfIRBuilder->SetInsertPoint(prevBlock);
|
mBfIRBuilder->SetInsertPoint(prevBlock);
|
||||||
|
if (WantsLifetimes())
|
||||||
|
{
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
castedVal = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapTypeInstPtr(typeInstance));
|
castedVal = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapTypeInstPtr(typeInstance));
|
||||||
|
@ -7507,9 +7510,12 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
{
|
{
|
||||||
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
||||||
mBfIRBuilder->SetInsertPoint(prevBlock);
|
mBfIRBuilder->SetInsertPoint(prevBlock);
|
||||||
|
if (WantsLifetimes())
|
||||||
|
{
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!noDtorCall)
|
if (!noDtorCall)
|
||||||
AddStackAlloc(typedVal, NULL, scopeData, false, true);
|
AddStackAlloc(typedVal, NULL, scopeData, false, true);
|
||||||
if (typeInstance != NULL)
|
if (typeInstance != NULL)
|
||||||
|
@ -7941,6 +7947,13 @@ bool BfModule::IsTargetingBeefBackend()
|
||||||
return GetModuleOptions().mOptLevel == BfOptLevel_OgPlus;
|
return GetModuleOptions().mOptLevel == BfOptLevel_OgPlus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfModule::WantsLifetimes()
|
||||||
|
{
|
||||||
|
if (mProject == NULL)
|
||||||
|
return false;
|
||||||
|
return GetModuleOptions().mOptLevel == BfOptLevel_OgPlus;
|
||||||
|
}
|
||||||
|
|
||||||
bool BfModule::HasCompiledOutput()
|
bool BfModule::HasCompiledOutput()
|
||||||
{
|
{
|
||||||
return (!mSystem->mIsResolveOnly) && (mIsReified);
|
return (!mSystem->mIsResolveOnly) && (mIsReified);
|
||||||
|
@ -11793,7 +11806,7 @@ BfIRValue BfModule::AllocLocalVariable(BfType* type, const StringImpl& name, boo
|
||||||
return mBfIRBuilder->GetFakeVal();
|
return mBfIRBuilder->GetFakeVal();
|
||||||
|
|
||||||
auto allocaInst = CreateAlloca(type, doLifetimeEnd, name.c_str());
|
auto allocaInst = CreateAlloca(type, doLifetimeEnd, name.c_str());
|
||||||
if (!doLifetimeEnd)
|
if ((!doLifetimeEnd) && (WantsLifetimes()))
|
||||||
{
|
{
|
||||||
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
mBfIRBuilder->ClearDebugLocation(lifetimeStart);
|
||||||
|
@ -15969,6 +15982,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
mBfIRBuilder->SetAllocaAlignment(allocaInst, checkType->mAlign);
|
mBfIRBuilder->SetAllocaAlignment(allocaInst, checkType->mAlign);
|
||||||
if (!paramVar->mAddr)
|
if (!paramVar->mAddr)
|
||||||
paramVar->mAddr = allocaInst;
|
paramVar->mAddr = allocaInst;
|
||||||
|
if (WantsLifetimes())
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
splatAddrValues.push_back(allocaInst);
|
splatAddrValues.push_back(allocaInst);
|
||||||
}, paramVar->mResolvedType);
|
}, paramVar->mResolvedType);
|
||||||
|
@ -15989,6 +16003,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr");
|
mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr");
|
||||||
mBfIRBuilder->SetAllocaAlignment(allocaInst, thisType->mAlign);
|
mBfIRBuilder->SetAllocaAlignment(allocaInst, thisType->mAlign);
|
||||||
paramVar->mAddr = allocaInst;
|
paramVar->mAddr = allocaInst;
|
||||||
|
if (WantsLifetimes())
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16007,6 +16022,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr");
|
mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr");
|
||||||
mBfIRBuilder->SetAllocaAlignment(allocaInst, mSystem->mPtrSize);
|
mBfIRBuilder->SetAllocaAlignment(allocaInst, mSystem->mPtrSize);
|
||||||
paramVar->mAddr = allocaInst;
|
paramVar->mAddr = allocaInst;
|
||||||
|
if (WantsLifetimes())
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsert);
|
mBfIRBuilder->SetInsertPoint(prevInsert);
|
||||||
|
@ -16046,6 +16062,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
mBfIRBuilder->SetAllocaAlignment(allocaInst, alignSize);
|
mBfIRBuilder->SetAllocaAlignment(allocaInst, alignSize);
|
||||||
paramVar->mAddr = allocaInst;
|
paramVar->mAddr = allocaInst;
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsert);
|
mBfIRBuilder->SetInsertPoint(prevInsert);
|
||||||
|
if (WantsLifetimes())
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1460,6 +1460,7 @@ public:
|
||||||
void EmitAppendAlign(int align, int sizeMultiple = 0);
|
void EmitAppendAlign(int align, int sizeMultiple = 0);
|
||||||
BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
|
BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true);
|
||||||
bool IsTargetingBeefBackend();
|
bool IsTargetingBeefBackend();
|
||||||
|
bool WantsLifetimes();
|
||||||
bool HasCompiledOutput();
|
bool HasCompiledOutput();
|
||||||
void SkipObjectAccessCheck(BfTypedValue typedVal);
|
void SkipObjectAccessCheck(BfTypedValue typedVal);
|
||||||
void EmitObjectAccessCheck(BfTypedValue typedVal);
|
void EmitObjectAccessCheck(BfTypedValue typedVal);
|
||||||
|
|
|
@ -84,9 +84,11 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
auto allocaInst = mBfIRBuilder->CreateAlloca(origParamTypes[paramIdx]);
|
auto allocaInst = mBfIRBuilder->CreateAlloca(origParamTypes[paramIdx]);
|
||||||
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
|
||||||
|
if (WantsLifetimes())
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
||||||
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
||||||
|
if (WantsLifetimes())
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
deferredCallEntry->mArgsNeedLoad = true;
|
deferredCallEntry->mArgsNeedLoad = true;
|
||||||
|
@ -120,6 +122,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
if (!mBfIRBuilder->mIgnoreWrites)
|
if (!mBfIRBuilder->mIgnoreWrites)
|
||||||
{
|
{
|
||||||
listEntry->mDynCallTail = CreateAlloca(deferredCallEntryTypePtr, false, "deferredCallTail");
|
listEntry->mDynCallTail = CreateAlloca(deferredCallEntryTypePtr, false, "deferredCallTail");
|
||||||
|
if (WantsLifetimes())
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(listEntry->mDynCallTail);
|
scopeData->mDeferredLifetimeEnds.push_back(listEntry->mDynCallTail);
|
||||||
|
|
||||||
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
||||||
|
@ -129,6 +132,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
auto scopeHead = &mCurMethodState->mHeadScope;
|
auto scopeHead = &mCurMethodState->mHeadScope;
|
||||||
mBfIRBuilder->SetCurrentDebugLocation(mCurFilePosition.mCurLine + 1, 0, scopeHead->mDIScope, BfIRMDNode());
|
mBfIRBuilder->SetCurrentDebugLocation(mCurFilePosition.mCurLine + 1, 0, scopeHead->mDIScope, BfIRMDNode());
|
||||||
|
|
||||||
|
if (WantsLifetimes())
|
||||||
mBfIRBuilder->CreateLifetimeStart(listEntry->mDynCallTail);
|
mBfIRBuilder->CreateLifetimeStart(listEntry->mDynCallTail);
|
||||||
auto storeInst = mBfIRBuilder->CreateStore(GetDefaultValue(deferredCallEntryTypePtr), listEntry->mDynCallTail);
|
auto storeInst = mBfIRBuilder->CreateStore(GetDefaultValue(deferredCallEntryTypePtr), listEntry->mDynCallTail);
|
||||||
mBfIRBuilder->ClearDebugLocation(storeInst);
|
mBfIRBuilder->ClearDebugLocation(storeInst);
|
||||||
|
@ -1590,6 +1594,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
|
||||||
if (localDef->mIsReadOnly)
|
if (localDef->mIsReadOnly)
|
||||||
localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr);
|
localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr);
|
||||||
}
|
}
|
||||||
|
if (WantsLifetimes())
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(localDef->mAddr);
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(localDef->mAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue