mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Suppress 'unreachable code' for 'System.Compiler' comparison branches
This commit is contained in:
parent
7cb92e4007
commit
87d403f72e
4 changed files with 52 additions and 2 deletions
|
@ -113,6 +113,11 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
|
||||||
VisitChildNoRef(expr);
|
VisitChildNoRef(expr);
|
||||||
|
|
||||||
mResult = GetResult();
|
mResult = GetResult();
|
||||||
|
|
||||||
|
auto compilerVal = mModule->GetCompilerFieldValue(mResult);
|
||||||
|
if (compilerVal)
|
||||||
|
mResult = compilerVal;
|
||||||
|
|
||||||
if ((mResult) && (wantType != NULL))
|
if ((mResult) && (wantType != NULL))
|
||||||
{
|
{
|
||||||
auto typeInst = mResult.mType->ToTypeInstance();
|
auto typeInst = mResult.mType->ToTypeInstance();
|
||||||
|
|
|
@ -12483,7 +12483,20 @@ BfTypedValue BfModule::LoadValue(BfTypedValue typedValue, BfAstNode* refNode, bo
|
||||||
{
|
{
|
||||||
BfTypedValue result = GetCompilerFieldValue(globalVar->mName);
|
BfTypedValue result = GetCompilerFieldValue(globalVar->mName);
|
||||||
if (result)
|
if (result)
|
||||||
|
{
|
||||||
|
// We want to avoid 'unreachable code' issues from values that
|
||||||
|
// are technically constant but change depending on compilation context
|
||||||
|
if (mCurMethodState != NULL)
|
||||||
|
{
|
||||||
|
auto checkScope = mCurMethodState->mCurScope;
|
||||||
|
while (checkScope != NULL)
|
||||||
|
{
|
||||||
|
checkScope->mSupressNextUnreachable = true;
|
||||||
|
checkScope = checkScope->mPrevScope;
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
return GetDefaultTypedValue(typedValue.mType);
|
return GetDefaultTypedValue(typedValue.mType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14577,6 +14590,32 @@ BfTypedValue BfModule::GetCompilerFieldValue(const StringImpl& str)
|
||||||
return BfTypedValue();
|
return BfTypedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BfTypedValue BfModule::GetCompilerFieldValue(BfTypedValue typedValue)
|
||||||
|
{
|
||||||
|
if (!typedValue.IsAddr())
|
||||||
|
return BfTypedValue();
|
||||||
|
|
||||||
|
if (typedValue.mValue.IsConst())
|
||||||
|
{
|
||||||
|
auto constantValue = mBfIRBuilder->GetConstant(typedValue.mValue);
|
||||||
|
if (constantValue != NULL)
|
||||||
|
{
|
||||||
|
if (constantValue->mConstType == BfConstType_GlobalVar)
|
||||||
|
{
|
||||||
|
auto globalVar = (BfGlobalVar*)constantValue;
|
||||||
|
if (globalVar->mName[0] == '#')
|
||||||
|
{
|
||||||
|
BfTypedValue result = GetCompilerFieldValue(globalVar->mName);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return BfTypedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
|
BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
|
||||||
{
|
{
|
||||||
BfIRValue globalValue;
|
BfIRValue globalValue;
|
||||||
|
|
|
@ -435,6 +435,7 @@ public:
|
||||||
bool mIsDeferredBlock;
|
bool mIsDeferredBlock;
|
||||||
bool mAllowVariableDeclarations;
|
bool mAllowVariableDeclarations;
|
||||||
bool mInInitBlock;
|
bool mInInitBlock;
|
||||||
|
bool mSupressNextUnreachable;
|
||||||
BfMixinState* mMixinState;
|
BfMixinState* mMixinState;
|
||||||
BfBlock* mAstBlock;
|
BfBlock* mAstBlock;
|
||||||
BfAstNode* mCloseNode;
|
BfAstNode* mCloseNode;
|
||||||
|
@ -470,6 +471,7 @@ public:
|
||||||
mHadOuterDynStack = false;
|
mHadOuterDynStack = false;
|
||||||
mHadScopeValueRetain = false;
|
mHadScopeValueRetain = false;
|
||||||
mIsDeferredBlock = false;
|
mIsDeferredBlock = false;
|
||||||
|
mSupressNextUnreachable = false;
|
||||||
mAllowTargeting = true;
|
mAllowTargeting = true;
|
||||||
mAllowVariableDeclarations = true;
|
mAllowVariableDeclarations = true;
|
||||||
mInInitBlock = false;
|
mInInitBlock = false;
|
||||||
|
@ -1691,6 +1693,7 @@ public:
|
||||||
BfIRValue GetInterfaceSlotNum(BfTypeInstance* ifaceType);
|
BfIRValue GetInterfaceSlotNum(BfTypeInstance* ifaceType);
|
||||||
void HadSlotCountDependency();
|
void HadSlotCountDependency();
|
||||||
BfTypedValue GetCompilerFieldValue(const StringImpl& str);
|
BfTypedValue GetCompilerFieldValue(const StringImpl& str);
|
||||||
|
BfTypedValue GetCompilerFieldValue(const BfTypedValue typedVal);
|
||||||
BfTypedValue ReferenceStaticField(BfFieldInstance* fieldInstance);
|
BfTypedValue ReferenceStaticField(BfFieldInstance* fieldInstance);
|
||||||
int GetFieldDataIdx(BfTypeInstance* typeInst, int fieldIdx, const char* fieldName = NULL);
|
int GetFieldDataIdx(BfTypeInstance* typeInst, int fieldIdx, const char* fieldName = NULL);
|
||||||
BfTypedValue GetThis(bool markUsing = true);
|
BfTypedValue GetThis(bool markUsing = true);
|
||||||
|
|
|
@ -3453,6 +3453,7 @@ void BfModule::VisitCodeBlock(BfBlock* block)
|
||||||
|
|
||||||
if ((!hadUnreachableCode) && (!mCurMethodState->mInPostReturn))
|
if ((!hadUnreachableCode) && (!mCurMethodState->mInPostReturn))
|
||||||
{
|
{
|
||||||
|
if ((mCurMethodState->mCurScope == NULL) || (!mCurMethodState->mCurScope->mSupressNextUnreachable))
|
||||||
Warn(BfWarning_CS0162_UnreachableCode, "Unreachable code", child);
|
Warn(BfWarning_CS0162_UnreachableCode, "Unreachable code", child);
|
||||||
|
|
||||||
hadUnreachableCode = true;
|
hadUnreachableCode = true;
|
||||||
|
@ -3462,6 +3463,8 @@ void BfModule::VisitCodeBlock(BfBlock* block)
|
||||||
mBfIRBuilder->mIgnoreWrites = true;
|
mBfIRBuilder->mIgnoreWrites = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((mCurMethodState != NULL) && (mCurMethodState->mCurScope != NULL))
|
||||||
|
mCurMethodState->mCurScope->mSupressNextUnreachable = false;
|
||||||
|
|
||||||
if (itr.IsLast())
|
if (itr.IsLast())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue