From 896c60d18c86b5062c0645a1cad0c2d991074d24 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 21 Nov 2016 00:25:58 -0600 Subject: [PATCH] Determine the type to use for computing a >>= or <<= operation based only on the left operand. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, fix a case where an uninitialized value could be used, potentially resulting in errors not being reported (although I haven’t seen that in practice). This fixes problems where >>= operations might not use an arithmetic shift in certain cases where they should, as in the below program: #include int main (void) { int i; unsigned u; long l; unsigned long ul; i = -1; u = 1; i >>= u; printf("%i\n", i); /* should be -1 */ l = -1; ul = 3; l >>= ul; printf("%li\n", l); /* should be -1 */ } --- Expression.pas | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Expression.pas b/Expression.pas index b7d0977..0001b58 100644 --- a/Expression.pas +++ b/Expression.pas @@ -2963,8 +2963,19 @@ case tree^.token.kind of else kind := lType^.kind; GenerateCode(tree^.right); + if tree^.token.kind in [gtgteqop,ltlteqop] then + if kind = scalarType then + if expressionType^.kind = scalarType then begin + et := UsualUnaryConversions; + if et <> Unary(ltype^.baseType) then begin + Gen2(pc_cnv, et, ord(Unary(ltype^.baseType))); + expressionType := lType; + end; {if} + end; {if} if kind <> pointerType then - et := UsualBinaryConversions(lType); + et := UsualBinaryConversions(lType) + else + et := ccPointer; case tree^.token.kind of pluseqop: