#1615 Confusing warnings on signed char comparison

open
nobody
None
Front-end
5
2015-03-09
2010-02-07
wek
No

When comparing a signed char and unsigned char, the following warning is printed:
warning 185: comparison of 'signed char' with 'unsigned char' requires promotion to int

1. When performing arithmetics (*, /, %) on the signed operand, only with % the warning is printed. What is the logic behind this?
2. When performing / or % on an unsigned bitfield, the warning is confusingly printed (while it is not printed when performing a direct comparison). Why?

SDCC : mcs51/gbz80/z80/ds390/pic16/pic14/TININative/ds400/hc08 2.9.7 #5677 (Feb 7 2010) (MINGW32)

Jan Waclawek

Discussion

  • wek

    wek - 2010-02-07
     
  • Ben Shi

    Ben Shi - 2015-03-09
    • Category: --> Front-end
     
  • Ben Shi

    Ben Shi - 2015-07-10

    With the attached bug2.c, the following warnings are generated,

    bug2.c:11: warning 185: comparison of 'signed char' with 'unsigned char' requires promotion to int
    bug2.c:12: warning 185: comparison of 'signed char' with 'unsigned char' requires promotion to int
    bug2.c:15: warning 185: comparison of 'signed char' with 'unsigned char' requires promotion to int
    bug2.c:17: warning 185: comparison of 'signed char' with 'unsigned char' requires promotion to int

    I can understand there are warnings for "s.a / 1" and "s.a % 1", since s.a is 7-bit-field, and their result types are promoted to "signed char", and there is no waning for "s.a * 1" since the result type is promoted to "signed int".

    But I am confused with that there is no warning for "q / 1", but there is warning for "q % 1". Why "q / 1" is promoted to int, while "q % 1" remains signed char? Should the result type be the same for char / char and char % char ?

    Ben

     
  • Ben Shi

    Ben Shi - 2015-07-10

    By adding "case '%': " to line 2316 SDCCsymt.c, schar%schar was promoted to int, but some regression test cases failed.

    Running ds390 regression tests
    Summary for 'ds390': 2 failures, 9279 tests, 1746 test cases, 6804853 bytes, 901116852 ticks
    Failure: gen/ds390/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running hc08 regression tests
    Summary for 'hc08': 2 failures, 9240 tests, 1747 test cases, 2530961 bytes, 31789256 ticks
    Failure: gen/hc08/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running host regression tests
    Summary for 'host': 0 failures, 9200 tests, 1747 test cases, 0 bytes, 0 ticks

    making huge library
    Running mcs51-huge regression tests
    Summary for 'mcs51-huge': 1 failures, 9293 tests, 1746 test cases, 3516296 bytes, 457061376 ticks
    Failure: gen/mcs51-huge/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running mcs51-large regression tests
    Summary for 'mcs51-large': 1 failures, 9291 tests, 1746 test cases, 3055423 bytes, 383109888 ticks
    Failure: gen/mcs51-large/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running mcs51-medium regression tests
    Summary for 'mcs51-medium': 7 failures, 7302 tests, 1746 test cases, 2668197 bytes, 268918092 ticks
    Failure: gen/mcs51-medium/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1
    Failure: gen/mcs51-medium/onebyte/onebyte_attrL_volatile_attrR_volatile

    Running mcs51-small regression tests
    Summary for 'mcs51-small': 1 failures, 7307 tests, 1746 test cases, 2250290 bytes, 221564460 ticks
    Failure: gen/mcs51-small/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running mcs51-stack-auto regression tests
    Summary for 'mcs51-stack-auto': 1 failures, 7307 tests, 1746 test cases, 2506991 bytes, 231922188 ticks
    Failure: gen/mcs51-stack-auto/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running mcs51-xstack-auto regression tests
    Summary for 'mcs51-xstack-auto': 1 failures, 7308 tests, 1746 test cases, 3743400 bytes, 400707288 ticks
    Failure: gen/mcs51-xstack-auto/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running s08 regression tests
    Summary for 's08': 2 failures, 9242 tests, 1747 test cases, 2430235 bytes, 30863063 ticks
    Failure: gen/s08/gcc-torture-execute-divmod-1/gcc-torture-execute-divmod-1

    Running stm8 regression tests
    Summary for 'stm8': 0 failures, 9295 tests, 1747 test cases, 1926373 bytes, 7539671 ticks

    Running ucgbz80 regression tests
    Summary for 'ucgbz80': 0 failures, 9278 tests, 1747 test cases, 2621411 bytes, 20115802 ticks

    Running ucr2k regression tests
    Summary for 'ucr2k': 0 failures, 9286 tests, 1747 test cases, 2289093 bytes, 11489227 ticks

    Running ucr3ka regression tests
    Summary for 'ucr3ka': 0 failures, 9286 tests, 1747 test cases, 2299016 bytes, 10620168 ticks

    Running ucz180 regression tests
    Summary for 'ucz180': 0 failures, 9286 tests, 1747 test cases, 2384136 bytes, 12421589 ticks

    Running ucz80 regression tests
    Summary for 'ucz80': 0 failures, 9297 tests, 1747 test cases, 2318778 bytes, 12574920 ticks

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks