Menu

#2585 Wrong result in left shift of int by int

closed-fixed
None
Front-end
9
2017-04-26
2017-02-19
No

In sdcc 3.6.5 #9842 for the following test fails (for at least hc08, stm8, mcs51-small) on my Debian GNU/Linux:

/*
   int cast issue
 */

#include <testfwk.h>

#include <limits.h>

void testBug (void)
{
  int i;

  i = SCHAR_MAX;

  ASSERT ((signed char)(i << (int)1) == -2);
}

(i << (int)1) should be 254, casting to signed char should yield -2. The test passes if the (int) is removed, or i is replaced by SCHAR_MAX.

Philipp

Discussion

  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -19,7 +19,7 @@
     }
     ~~~~
    
    -(i << (int)1) should be 254, casting to signed int should yield -2. The test passed if the (int) is removed, or i is replaced by SCHAR_MAX.
    +(i << (int)1) should be 254, casting to signed char should yield -2. The test passes if the (int) is removed, or i is replaced by SCHAR_MAX.
    
     Philipp
    
     
  • Philipp Klaus Krause

    Looks like a CSE bug: dumpraw1 looks ok, while dumpcse has the bug.

    Philipp

     
  • Philipp Klaus Krause

    • Priority: 7 --> 9
     
  • Philipp Klaus Krause

    Increasing priority, since the fix to #2449 is blocked by this bug.

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2017-04-25
    • assigned_to: Maarten Brock
     
  • Maarten Brock

    Maarten Brock - 2017-04-25

    I started looking into this. But I think things go wrong before CSE. This is what the AST looks like and that seems fine. Note the -2 to be a signed char. For simplicity I changed the ASSERT to a returned bool.

    FUNCTION (_testBug=02E2D6F8) type (_Bool fixed) args (void)
    tree (02E2E078) not decorated
    (null):0:{ L1 B0
    (null):0:  DECLARE SYMBOL (L1 B2 i=02BE6660) type (int fixed)
    bug2585.c:11:  RETURN (02E2D450) type (bit fixed)
    bug2585.c:11:    EQ(==) (02E2D3D0) type (bit fixed)
    bug2585.c:11:      LEFT_SHIFT (02E2D150) type (signed-char fixed)
    bug2585.c:11:        CAST (02E2DBF8) from type (int fixed) to type (signed-char fixed)
    bug2585.c:11:          SYMBOL (L1 B2 i=02E2CF50 @ 02BE6660) type (int fixed)
    bug2585.c:11:        CONSTANT (02E2D0D0) value = 1, 0x1, 1.000000 type (int literal)
    bug2585.c:11:      CONSTANT (02E2D350) value = -2, 0xfffffffe, -2.000000 type (const-signed-char literal)
    (null):0:}
    
     
  • Maarten Brock

    Maarten Brock - 2017-04-26
    • status: open --> closed-fixed
    • Category: other --> Front-end
     
  • Maarten Brock

    Maarten Brock - 2017-04-26

    Fixed in SDCC [r9881]

     

Log in to post a comment.

MongoDB Logo MongoDB