mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +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,7 +12043,8 @@ 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);
|
||||||
scopeData.mDeferredLifetimeEnds.Add(aliasValue);
|
if (mModule->WantsLifetimes())
|
||||||
|
scopeData.mDeferredLifetimeEnds.Add(aliasValue);
|
||||||
|
|
||||||
if (newLocalVar->mAddr)
|
if (newLocalVar->mAddr)
|
||||||
mModule->mBfIRBuilder->DbgInsertDeclare(aliasValue, diVariable);
|
mModule->mBfIRBuilder->DbgInsertDeclare(aliasValue, diVariable);
|
||||||
|
@ -15156,7 +15157,7 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
||||||
auto startCheckTypeInst = target.mType->ToTypeInstance();
|
auto startCheckTypeInst = target.mType->ToTypeInstance();
|
||||||
|
|
||||||
for (int pass = 0; pass < 2; pass++)
|
for (int pass = 0; pass < 2; pass++)
|
||||||
{
|
{
|
||||||
bool isFailurePass = pass == 1;
|
bool isFailurePass = pass == 1;
|
||||||
|
|
||||||
auto curCheckType = startCheckTypeInst;
|
auto curCheckType = startCheckTypeInst;
|
||||||
|
@ -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,8 +7456,11 @@ 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);
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
if (WantsLifetimes())
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
{
|
||||||
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -7507,8 +7510,11 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
||||||
{
|
{
|
||||||
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
mBfIRBuilder->ClearDebugLocation(allocaInst);
|
||||||
mBfIRBuilder->SetInsertPoint(prevBlock);
|
mBfIRBuilder->SetInsertPoint(prevBlock);
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
if (WantsLifetimes())
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
{
|
||||||
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!noDtorCall)
|
if (!noDtorCall)
|
||||||
AddStackAlloc(typedVal, NULL, scopeData, false, true);
|
AddStackAlloc(typedVal, NULL, scopeData, false, true);
|
||||||
|
@ -7937,8 +7943,15 @@ bool BfModule::IsOptimized()
|
||||||
bool BfModule::IsTargetingBeefBackend()
|
bool BfModule::IsTargetingBeefBackend()
|
||||||
{
|
{
|
||||||
if (mProject == NULL)
|
if (mProject == NULL)
|
||||||
return false;
|
return false;
|
||||||
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()
|
||||||
|
@ -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,7 +15982,8 @@ 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;
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
splatAddrValues.push_back(allocaInst);
|
splatAddrValues.push_back(allocaInst);
|
||||||
}, paramVar->mResolvedType);
|
}, paramVar->mResolvedType);
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsert);
|
mBfIRBuilder->SetInsertPoint(prevInsert);
|
||||||
|
@ -15989,7 +16003,8 @@ 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;
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -16007,7 +16022,8 @@ 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;
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
mBfIRBuilder->SetInsertPoint(prevInsert);
|
mBfIRBuilder->SetInsertPoint(prevInsert);
|
||||||
}
|
}
|
||||||
|
@ -16046,7 +16062,8 @@ 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);
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (wantsAddr)
|
else if (wantsAddr)
|
||||||
|
|
|
@ -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,10 +84,12 @@ 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);
|
||||||
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
mBfIRBuilder->CreateLifetimeStart(allocaInst);
|
||||||
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
mBfIRBuilder->CreateStore(scopeArg, allocaInst);
|
||||||
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst;
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
if (WantsLifetimes())
|
||||||
|
scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
|
||||||
}
|
}
|
||||||
deferredCallEntry->mArgsNeedLoad = true;
|
deferredCallEntry->mArgsNeedLoad = true;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +122,8 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
if (!mBfIRBuilder->mIgnoreWrites)
|
if (!mBfIRBuilder->mIgnoreWrites)
|
||||||
{
|
{
|
||||||
listEntry->mDynCallTail = CreateAlloca(deferredCallEntryTypePtr, false, "deferredCallTail");
|
listEntry->mDynCallTail = CreateAlloca(deferredCallEntryTypePtr, false, "deferredCallTail");
|
||||||
scopeData->mDeferredLifetimeEnds.push_back(listEntry->mDynCallTail);
|
if (WantsLifetimes())
|
||||||
|
scopeData->mDeferredLifetimeEnds.push_back(listEntry->mDynCallTail);
|
||||||
|
|
||||||
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
|
||||||
mBfIRBuilder->SaveDebugLocation();
|
mBfIRBuilder->SaveDebugLocation();
|
||||||
|
@ -129,7 +132,8 @@ 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());
|
||||||
|
|
||||||
mBfIRBuilder->CreateLifetimeStart(listEntry->mDynCallTail);
|
if (WantsLifetimes())
|
||||||
|
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,7 +1594,8 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
|
||||||
if (localDef->mIsReadOnly)
|
if (localDef->mIsReadOnly)
|
||||||
localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr);
|
localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr);
|
||||||
}
|
}
|
||||||
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(localDef->mAddr);
|
if (WantsLifetimes())
|
||||||
|
mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(localDef->mAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!localDef->mAddr) && (!isConst) && ((!localDef->mIsReadOnly) || (localNeedsAddr)))
|
if ((!localDef->mAddr) && (!isConst) && ((!localDef->mIsReadOnly) || (localNeedsAddr)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue