Menu

#2733 False "overflow in implicit constant conversion" warning

open
nobody
None
Front-end
5
2022-09-12
2018-03-29
No

As of [r10267] (and probably for quite a while before that),

unsigned char c = 1  <<  7;

results in a warning "overflow in implicit constant conversion" . However, the constant is 128, which is perfectly within the range of unsigned int. I noticed this issue due to a failure of the valdiag regression testing.

Philipp

Related

Bugs: #2827
Bugs: #3094
Discussion: warning 158: overflow in implicit constant conversion
Discussion: warning 158: overflow in implicit constant conversion
Wiki: SDCC 4.3.0 Release
Wiki: SDCC 4.4.0 Release
Wiki: SDCC 4.5.0 Release
Wiki: SDCC 4.6.0 Release

Discussion

  • Philipp Klaus Krause

    Looks like the 1 << 7 at some point is considered to be a signed char literal.

    Philipp

     
  • Philipp Klaus Krause

    The same problem happens for types other than char:

    unsigned int i = 1u << 15;
    unsigned long int l = 1ul  << 31;
    unsigned long int ll = 1ull  << 31;
    

    All give the same warning.

    Philipp

     
  • Philipp Klaus Krause

    However, for unsigned char, the false warning is always given, both on initialization and assignment. For the other unsigned types the false warning is only given on initialization.

    Philipp

     
  • Philipp Klaus Krause

    This, or a similar issue also affects operations other than <<:
    https://www.mikrocontroller.net/topic/474289

     
  • Erik Petrich

    Erik Petrich - 2019-05-19

    I trying to resolve the similar [#2877] just before the last release, but couldn't find a correction simple enough that I had confidence that I wasn't inadvertently breaking something else. Because of the assignment to unsigned char, decorateType() is propagating RESULT_TYPE_CHAR which ends up causing the literal to convert from int to signed char.

     

    Related

    Bugs: #2877

  • Diego Herranz

    Diego Herranz - 2021-01-13

    As of r12014, I think this still happens.

    I attach an example where 2 very similar expressions raise the warning or not, in case that helps.

    Simply compiled using: sdcc main.c

    unsigned char a = 0x80 | 0x00 | (0x01 << 2); //warning 158
    unsigned char b = 0x80 | (0x01 << 2); //no warning
    

    Many thanks!

     

Log in to post a comment.

MongoDB Logo MongoDB