Fix unsigned promotion for binary not operator

This commit is contained in:
drmortalwombat 2024-02-17 13:10:14 +01:00
parent 58ffe2ad06
commit 8457316815
2 changed files with 21 additions and 1 deletions

View File

@ -502,8 +502,16 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
{
Expression* ex = new Expression(mLocation, EX_CONSTANT);
Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER);
dec->mBase = mLeft->mDecValue->mBase;
dec->mInteger = ~mLeft->mDecValue->mInteger;
if (mLeft->mDecValue->mBase->mSize <= 2)
{
dec->mInteger &= 0xffff;
dec->mBase = TheUnsignedIntTypeDeclaration;
}
else
dec->mBase = TheUnsignedLongTypeDeclaration;
ex->mDecValue = dec;
ex->mDecType = dec->mBase;
return ex;

View File

@ -7281,6 +7281,18 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
{
nexp->mDecType = TheUnsignedCharTypeDeclaration;
}
else if (nexp->mToken == TK_BINARY_AND)
{
if (nexp->mDecType->mFlags & DTF_SIGNED)
{
if (nexp->mDecType->mSize == 4)
nexp->mDecType = TheUnsignedLongTypeDeclaration;
else
nexp->mDecType = TheUnsignedIntTypeDeclaration;
}
else
nexp->mDecType = nexp->mLeft->mDecType;
}
else
nexp->mDecType = nexp->mLeft->mDecType;
}