Fix unsigned promotion for binary not operator
This commit is contained in:
parent
58ffe2ad06
commit
8457316815
|
|
@ -502,8 +502,16 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
|
||||||
{
|
{
|
||||||
Expression* ex = new Expression(mLocation, EX_CONSTANT);
|
Expression* ex = new Expression(mLocation, EX_CONSTANT);
|
||||||
Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER);
|
Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER);
|
||||||
dec->mBase = mLeft->mDecValue->mBase;
|
|
||||||
dec->mInteger = ~mLeft->mDecValue->mInteger;
|
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->mDecValue = dec;
|
||||||
ex->mDecType = dec->mBase;
|
ex->mDecType = dec->mBase;
|
||||||
return ex;
|
return ex;
|
||||||
|
|
|
||||||
|
|
@ -7281,6 +7281,18 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
||||||
{
|
{
|
||||||
nexp->mDecType = TheUnsignedCharTypeDeclaration;
|
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
|
else
|
||||||
nexp->mDecType = nexp->mLeft->mDecType;
|
nexp->mDecType = nexp->mLeft->mDecType;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue