Fix auto deduction of void return type
This commit is contained in:
parent
b1b5ee737b
commit
13629c70d4
|
@ -4328,54 +4328,66 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
vr = Dereference(proc, exp, block, inlineMapper, vr);
|
vr = Dereference(proc, exp, block, inlineMapper, vr);
|
||||||
|
|
||||||
if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID)
|
if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID)
|
||||||
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has void return type");
|
{
|
||||||
|
if (vr.mType->mType != DT_TYPE_VOID)
|
||||||
|
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has void return type");
|
||||||
|
}
|
||||||
else if (procType->mBase->mType == DT_TYPE_BOOL && (vr.mType->IsIntegerType() || vr.mType->mType == DT_TYPE_POINTER))
|
else if (procType->mBase->mType == DT_TYPE_BOOL && (vr.mType->IsIntegerType() || vr.mType->mType == DT_TYPE_POINTER))
|
||||||
;
|
;
|
||||||
else if (!procType->mBase->CanAssign(vr.mType))
|
else if (!procType->mBase->CanAssign(vr.mType))
|
||||||
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Cannot return incompatible type");
|
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Cannot return incompatible type");
|
||||||
|
|
||||||
vr = CoerceType(proc, exp, block, inlineMapper, vr, procType->mBase);
|
if (vr.mType->mType == DT_TYPE_VOID)
|
||||||
|
|
||||||
ins->mSrc[0].mType = InterTypeOf(vr.mType);
|
|
||||||
ins->mSrc[0].mTemp = vr.mTemp;
|
|
||||||
|
|
||||||
if (inlineMapper)
|
|
||||||
{
|
{
|
||||||
if (inlineMapper->mResultExp)
|
if (inlineMapper)
|
||||||
{
|
ins->mCode = IC_NONE;
|
||||||
ins->mSrc[1].mType = IT_POINTER;
|
|
||||||
ins->mSrc[1].mTemp = inlineMapper->mResultExp->mTemp;
|
|
||||||
ins->mSrc[1].mMemory = IM_INDIRECT;
|
|
||||||
ins->mCode = IC_STORE;
|
|
||||||
ins->mSrc[1].mOperandSize = procType->mBase->mSize;
|
|
||||||
ins->mNumOperands = 2;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
ins->mCode = IC_RETURN;
|
||||||
InterInstruction* ains = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONSTANT);
|
|
||||||
ains->mDst.mType = IT_POINTER;
|
|
||||||
ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType);
|
|
||||||
ains->mConst.mType = IT_POINTER;
|
|
||||||
ains->mConst.mOperandSize = procType->mBase->mSize;
|
|
||||||
ains->mConst.mIntConst = 0;
|
|
||||||
ains->mConst.mVarIndex = inlineMapper->mResult;;
|
|
||||||
ains->mConst.mMemory = IM_LOCAL;
|
|
||||||
block->Append(ains);
|
|
||||||
|
|
||||||
ins->mSrc[1].mType = ains->mDst.mType;
|
|
||||||
ins->mSrc[1].mTemp = ains->mDst.mTemp;
|
|
||||||
ins->mSrc[1].mMemory = IM_INDIRECT;
|
|
||||||
ins->mCode = IC_STORE;
|
|
||||||
ins->mSrc[1].mOperandSize = ains->mConst.mOperandSize;
|
|
||||||
ins->mNumOperands = 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ins->mCode = IC_RETURN_VALUE;
|
vr = CoerceType(proc, exp, block, inlineMapper, vr, procType->mBase);
|
||||||
ins->mNumOperands = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ins->mSrc[0].mType = InterTypeOf(vr.mType);
|
||||||
|
ins->mSrc[0].mTemp = vr.mTemp;
|
||||||
|
|
||||||
|
if (inlineMapper)
|
||||||
|
{
|
||||||
|
if (inlineMapper->mResultExp)
|
||||||
|
{
|
||||||
|
ins->mSrc[1].mType = IT_POINTER;
|
||||||
|
ins->mSrc[1].mTemp = inlineMapper->mResultExp->mTemp;
|
||||||
|
ins->mSrc[1].mMemory = IM_INDIRECT;
|
||||||
|
ins->mCode = IC_STORE;
|
||||||
|
ins->mSrc[1].mOperandSize = procType->mBase->mSize;
|
||||||
|
ins->mNumOperands = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InterInstruction* ains = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONSTANT);
|
||||||
|
ains->mDst.mType = IT_POINTER;
|
||||||
|
ains->mDst.mTemp = proc->AddTemporary(ains->mDst.mType);
|
||||||
|
ains->mConst.mType = IT_POINTER;
|
||||||
|
ains->mConst.mOperandSize = procType->mBase->mSize;
|
||||||
|
ains->mConst.mIntConst = 0;
|
||||||
|
ains->mConst.mVarIndex = inlineMapper->mResult;;
|
||||||
|
ains->mConst.mMemory = IM_LOCAL;
|
||||||
|
block->Append(ains);
|
||||||
|
|
||||||
|
ins->mSrc[1].mType = ains->mDst.mType;
|
||||||
|
ins->mSrc[1].mTemp = ains->mDst.mTemp;
|
||||||
|
ins->mSrc[1].mMemory = IM_INDIRECT;
|
||||||
|
ins->mCode = IC_STORE;
|
||||||
|
ins->mSrc[1].mOperandSize = ains->mConst.mOperandSize;
|
||||||
|
ins->mNumOperands = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ins->mCode = IC_RETURN_VALUE;
|
||||||
|
ins->mNumOperands = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -8651,6 +8651,9 @@ Expression* Parser::ParseFunction(Declaration * dec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dec->mBase->mType == DT_TYPE_AUTO)
|
||||||
|
dec->mBase->mType = DT_TYPE_VOID;
|
||||||
|
|
||||||
mScope->End(mScanner->mLocation);
|
mScope->End(mScanner->mLocation);
|
||||||
mScope = oscope;
|
mScope = oscope;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue