mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Fix for signed numeric cast with immediate
This commit is contained in:
parent
a888fd745a
commit
f993d3cc62
2 changed files with 10 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue