Fix compiler crash when using function result in if condition
This commit is contained in:
parent
0a3ad006b7
commit
982fe17aed
|
@ -73,6 +73,15 @@ void vic_waitFrame(void)
|
|||
;
|
||||
}
|
||||
|
||||
void vic_waitFrames(char n)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
vic_waitFrame();
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
void vic_waitLine(int line)
|
||||
{
|
||||
char upper = (char)(line >> 1) & VIC_CTRL1_RST8;
|
||||
|
|
|
@ -109,6 +109,9 @@ inline void vic_waitTop(void);
|
|||
// wait for the top of the frame and then for the bottom of the visual area
|
||||
inline void vic_waitFrame(void);
|
||||
|
||||
// wait for n frames
|
||||
void vic_waitFrames(char n);
|
||||
|
||||
// wait for a specific raster line
|
||||
void vic_waitLine(int line);
|
||||
|
||||
|
|
|
@ -516,7 +516,7 @@ const char * string::cend(void) const
|
|||
string string::substr(char pos, char len) const
|
||||
{
|
||||
if (!cstr || len == 0 || pos >= cstr[0])
|
||||
return string;
|
||||
return string();
|
||||
else
|
||||
{
|
||||
char l = cstr[0];
|
||||
|
|
|
@ -40,6 +40,10 @@ void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const char
|
|||
else
|
||||
fprintf(stderr, "%s(%d, %d) : %s %d: %s '%s' != '%s'\n", loc.mFileName, loc.mLine, loc.mColumn, level, eid, msg, info1, info2);
|
||||
|
||||
if (loc.mFrom)
|
||||
|
||||
Error(*(loc.mFrom), EINFO_EXPANDED, "While expanding here");
|
||||
|
||||
if (mErrorCount > 10 || eid >= EFATAL_GENERIC)
|
||||
exit(20);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
class Location
|
||||
{
|
||||
public:
|
||||
const char* mFileName;
|
||||
int mLine, mColumn;
|
||||
const char * mFileName;
|
||||
int mLine, mColumn;
|
||||
const Location * mFrom;
|
||||
|
||||
Location() : mFileName(nullptr), mLine(0), mColumn(0) {}
|
||||
Location() : mFileName(nullptr), mLine(0), mColumn(0), mFrom(nullptr) {}
|
||||
Location(const Location& loc, const Location* from)
|
||||
: mFileName(loc.mFileName), mLine(loc.mLine), mColumn(loc.mColumn), mFrom(from)
|
||||
{}
|
||||
};
|
||||
|
||||
class Ident;
|
||||
|
@ -14,6 +18,7 @@ class Ident;
|
|||
enum ErrorID
|
||||
{
|
||||
EINFO_GENERIC = 1000,
|
||||
EINFO_EXPANDED = 1001,
|
||||
|
||||
EWARN_GENERIC = 2000,
|
||||
EWARN_CONSTANT_TRUNCATED,
|
||||
|
|
|
@ -16826,6 +16826,26 @@ void InterCodeBasicBlock::PeepholeOptimization(const GrowingVariableArray& stati
|
|||
}
|
||||
}
|
||||
|
||||
void InterCodeBasicBlock::CheckNullptrDereference(void)
|
||||
{
|
||||
if (!mVisited)
|
||||
{
|
||||
mVisited = true;
|
||||
|
||||
for (int i = 0; i < mInstructions.Size(); i++)
|
||||
{
|
||||
InterInstruction* ins = mInstructions[i];
|
||||
if (ins->mCode == IC_LOAD && ins->mSrc[0].mTemp < 0 && ins->mSrc[0].mMemory == IM_ABSOLUTE && ins->mSrc[0].mIntConst == 0 && !ins->mVolatile)
|
||||
mProc->mModule->mErrors->Error(ins->mLocation, EWARN_NULL_POINTER_DEREFERENCED, "nullptr dereferenced");
|
||||
else if (ins->mCode == IC_STORE && ins->mSrc[1].mTemp < 0 && ins->mSrc[1].mMemory == IM_ABSOLUTE && ins->mSrc[1].mIntConst == 0 && !ins->mVolatile)
|
||||
mProc->mModule->mErrors->Error(ins->mLocation, EWARN_NULL_POINTER_DEREFERENCED, "nullptr dereferenced");
|
||||
}
|
||||
|
||||
if (mTrueJump) mTrueJump->CheckNullptrDereference();
|
||||
if (mFalseJump) mFalseJump->CheckNullptrDereference();
|
||||
}
|
||||
}
|
||||
|
||||
void InterCodeBasicBlock::CheckValueReturn(void)
|
||||
{
|
||||
if (!mVisited)
|
||||
|
@ -19088,6 +19108,9 @@ void InterCodeProcedure::Close(void)
|
|||
mEntryBlock->CheckValueReturn();
|
||||
}
|
||||
|
||||
ResetVisited();
|
||||
mEntryBlock->CheckNullptrDereference();
|
||||
|
||||
if (mSaveTempsLinkerObject && mTempSize > BC_REG_TMP_SAVED - BC_REG_TMP)
|
||||
mSaveTempsLinkerObject->AddSpace(mTempSize - (BC_REG_TMP_SAVED - BC_REG_TMP));
|
||||
|
||||
|
|
|
@ -605,6 +605,7 @@ public:
|
|||
|
||||
void WarnUsedUndefinedVariables(void);
|
||||
void CheckValueReturn(void);
|
||||
void CheckNullptrDereference(void);
|
||||
|
||||
void CollectGlobalReferences(NumberSet& referencedGlobals, NumberSet& modifiedGlobals, bool & storesIndirect, bool & loadsIndirect, bool & globalsChecked);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -61,6 +61,7 @@ protected:
|
|||
int mResult, mDepth, mVarIndex;
|
||||
bool mConstExpr;
|
||||
ExValue * mResultExp;
|
||||
Location * mLocation;
|
||||
|
||||
InlineMapper(void)
|
||||
: mParams(-1), mResult(-1), mDepth(0), mResultExp(nullptr)
|
||||
|
@ -78,17 +79,19 @@ protected:
|
|||
InterCodeProcedure* mMainInitProc;
|
||||
InterCodeBasicBlock* mMainInitBlock;
|
||||
|
||||
void BuildSwitchTree(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock* block, ExValue v, const SwitchNodeArray& nodes, int left, int right, int vleft, int vright, InterCodeBasicBlock* dblock);
|
||||
Location MapLocation(Expression * exp, InlineMapper* inlineMapper);
|
||||
|
||||
ExValue ToValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue v);
|
||||
ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue v, int level = 0);
|
||||
ExValue CoerceType(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue v, Declaration * type, bool checkTrunc = true);
|
||||
void BuildSwitchTree(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock* block, InlineMapper * inlineMapper, ExValue v, const SwitchNodeArray& nodes, int left, int right, int vleft, int vright, InterCodeBasicBlock* dblock);
|
||||
|
||||
ExValue ToValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v);
|
||||
ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level = 0);
|
||||
ExValue CoerceType(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, Declaration * type, bool checkTrunc = true);
|
||||
ExValue TranslateExpression(Declaration * procType, InterCodeProcedure * proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, const BranchTarget & breakBlock, const BranchTarget& continueBlock, InlineMapper * inlineMapper, ExValue * lrexp = nullptr);
|
||||
void TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, InlineMapper* inlineMapper);
|
||||
ExValue TranslateInline(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, bool inlineConstexpr, ExValue* lrexp);
|
||||
void CopyStruct(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue vl, ExValue vr, InlineMapper* inlineMapper, bool moving);
|
||||
void CopyStructSimple(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock * block, ExValue vl, ExValue vr);
|
||||
void StoreValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue vl, ExValue vr);
|
||||
void CopyStructSimple(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock * block, InlineMapper* inlineMapper, ExValue vl, ExValue vr);
|
||||
void StoreValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue vl, ExValue vr);
|
||||
|
||||
void UnwindDestructStack(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, DestructStack* stack, DestructStack * bottom, InlineMapper* inlineMapper);
|
||||
void BuildInitializer(InterCodeModule* mod, uint8 * dp, int offset, Declaration* data, InterVariable * variable);
|
||||
|
|
|
@ -14159,6 +14159,15 @@ bool NativeCodeBasicBlock::ForwardZpYIndex(bool full)
|
|||
yoffset = 0;
|
||||
ypred = i;
|
||||
}
|
||||
else if (mIns[i].mType == ASMIT_INC && mIns[i].mMode == ASMIM_ZERO_PAGE && mIns[i].mAddress == yreg && yoffset == 1 && !(mIns[i].mLive & LIVE_CPU_REG_Z))
|
||||
{
|
||||
mIns[i].mType = ASMIT_STY;
|
||||
for (int j = ypred; j < i; j++)
|
||||
mIns[j].mLive |= LIVE_CPU_REG_Y;
|
||||
yoffset = 0;
|
||||
ypred = i;
|
||||
changed = true;
|
||||
}
|
||||
#if 1
|
||||
else if (mIns[i].mType == ASMIT_INC && mIns[i].mMode == ASMIM_ZERO_PAGE && mIns[i].mAddress == yreg && yoffset == 0 && mIns[ypred].mType == ASMIT_STY && !(mIns[i].mLive & LIVE_CPU_REG_Y))
|
||||
{
|
||||
|
|
|
@ -3279,6 +3279,7 @@ Expression* Parser::CleanupExpression(Expression* exp)
|
|||
Expression* cexp = new Expression(exp->mLocation, EX_CLEANUP);
|
||||
cexp->mLeft = exp;
|
||||
cexp->mRight = xexp;
|
||||
cexp->mDecType = exp->mDecType;
|
||||
|
||||
FreeTempVarExp(xexp);
|
||||
return cexp;
|
||||
|
|
Loading…
Reference in New Issue