Do not erroneously treat integer constant expressions of type unsigned int as signed in certain contexts.

Unsigned constants in the range 0x8000-0xFFFF were erroneously being treated like negative signed values in some contexts, including in array declarators and in the case labels of switch statements where the expression switched over has type long or unsigned long.

This could lead to bogus compile errors for array declarations and typedefs such as the following:

typedef char foo[0x8000];

It could also lead to cases in switch statements not being properly matched, as in the following program:

#include <stdio.h>
int main(void)
{
    long i = 0xFF00;
    switch (i) {
        case 0xFF00:
            puts("good");
            break;
        default:
            puts("bad");
    }
}
This commit is contained in:
Stephen Heumann 2016-10-12 20:36:03 -05:00
parent 0705a337b0
commit b83ed7b17b

View File

@ -3682,6 +3682,7 @@ else begin {record the expression for an initialize
end {else if} end {else if}
else if tree^.token.kind = uintconst then begin else if tree^.token.kind = uintconst then begin
expressionValue := tree^.token.ival; expressionValue := tree^.token.ival;
expressionValue := expressionValue & $0000FFFF;
expressionType := uwordPtr; expressionType := uwordPtr;
isConstant := true; isConstant := true;
end {else if} end {else if}