1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fix for signed numeric cast with immediate

This commit is contained in:
Brian Fiete 2021-06-23 08:39:12 -07:00
parent a888fd745a
commit f993d3cc62
2 changed files with 10 additions and 1 deletions

View file

@ -16147,7 +16147,7 @@ void BeMCContext::Generate(BeFunction* function)
mcMemberRef.mKind = BeMCOperandKind_VRegLoad;
AllocInst(BeMCInstKind_Mov, mcMemberRef, mcValue);
// Our InsertValue always modifies the source aggregrate, it does not make a copy like LLVM's InsertValue would infer.
// Our InsertValue always modifies the source aggregate, it does not make a copy like LLVM's InsertValue would infer.
// This is okay because of Beef front end knowledge, but is not general purpose.
result = mcAgg;
}
@ -16157,6 +16157,7 @@ void BeMCContext::Generate(BeFunction* function)
auto castedInst = (BeNumericCastInst*)inst;
auto mcValue = GetOperand(castedInst->mValue);
auto fromType = GetType(mcValue);
if (fromType == castedInst->mToType)
{
// If it's just a sign change then leave it alone
@ -16179,6 +16180,10 @@ void BeMCContext::Generate(BeFunction* function)
bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);
if ((toType->IsFloat()) && (fromType->IsIntable()) && (castedInst->mValSigned))
doSignExtension = true;
if (mcValue.IsImmediate())
doSignExtension = false;
if (doSignExtension)
{
AllocInst(BeMCInstKind_MovSX, toValue, mcValue);

View file

@ -38,6 +38,10 @@ namespace Tests
{
Test.Assert(0b0111010110111100110100010101 == 123456789);
Test.Assert(0o726746425 == 123456789);
int i0 = 5;
int i1 = i0 % 1;
Test.Assert(i1 == 0);
}
}
}