Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#136 warning on range overflow

open
nobody
None
1
2006-05-09
2006-05-09
No

It would be nice(TM) if SDCC would emit warnings on
some of these assignments:

------------8<-----------------------------
#include <stdint.h>

#define WAFER_THIN_MINT (1)

int8_t c = INT8_MAX + WAFER_THIN_MINT;
int8_t d = INT8_MIN - WAFER_THIN_MINT;

uint8_t uc = UINT8_MAX + WAFER_THIN_MINT;
uint8_t ud = - WAFER_THIN_MINT;

int16_t i = INT16_MAX + WAFER_THIN_MINT;
int16_t j = INT16_MIN - WAFER_THIN_MINT;

uint16_t ui = UINT16_MAX + WAFER_THIN_MINT;
uint16_t uj = - WAFER_THIN_MINT;

int32_t l = INT32_MAX + WAFER_THIN_MINT;
int32_t m = INT32_MIN - WAFER_THIN_MINT;

uint32_t ul = UINT32_MAX + WAFER_THIN_MINT;
uint32_t um = - WAFER_THIN_MINT;
------------>8-----------------------------

Discussion

  • Bernhard Held
    Bernhard Held
    2006-05-09

    Logged In: YES
    user_id=203539

    This could be easily implemented with the fix for bug
    #1481333 and I was already thinking about exactly this
    topic :-)
    Some code for these warnings is already in SDCC. I'm not
    sure if everybody will like them, even if they can be
    suppressed by --less-pedantic. More comments?

     
  • Maarten Brock
    Maarten Brock
    2006-05-09

    Logged In: YES
    user_id=888171

    These warnings are valid but I still consider them very
    pedantic. In my opinion these NEED to be suppressed with --
    less-pedantic.

     
  • Bernhard Held
    Bernhard Held
    2006-06-04

    Logged In: YES
    user_id=203539

    sdcc #4207 behaves like this:

    1) sdcc emits a warning, which can be suppressed by
    --less-pedantic

    2) You find quite often lines like these:
    int i = 0xffff;
    unsigned int u = -1;

    IMHO it's too pedanic to throw warnings on this.
    Therefore sdcc accepts anything e.g. from
    INT16_MIN...0...UINT16_MAX in an assignment
    to 'signed int' or 'unsigned int'. Or from -127...255
    for 'signed char' or 'unsigned char'.

    If the environment variable SDCC_VERY_PEDANTIC is set
    sdcc emits a warning in these cases too.

    I personally don't need this part, the source can be
    deleted again if it's not commonly accepted. It has to
    be decided what should be done here.

    3) The overflow happens in the addition/subtraction,
    there's no test or warning (yet) on overflows
    at compile time.

    I leave the RFE open because of this part.

    #include <stdint.h>

    #define WAFER_THIN_MINT (1)

    int8_t c = INT8_MAX + WAFER_THIN_MINT; /* 2) */
    int8_t c2 = UINT8_MAX + WAFER_THIN_MINT; /* 1) */
    int8_t d = INT8_MIN - WAFER_THIN_MINT; /* 1) */

    uint8_t uc = UINT8_MAX + WAFER_THIN_MINT; /* 1) */
    uint8_t ud = - WAFER_THIN_MINT; /* 2) */
    uint8_t ud2 = INT8_MIN - WAFER_THIN_MINT; /* 1) */

    int16_t i = INT16_MAX + WAFER_THIN_MINT; /* no warning
    yet: 3) */
    int16_t j = INT16_MIN - WAFER_THIN_MINT; /* no warning
    yet: 3) */

    uint16_t ui = UINT16_MAX + WAFER_THIN_MINT; /* 1) */
    uint16_t uj = - WAFER_THIN_MINT; /* 2) */

    int32_t l = INT32_MAX + WAFER_THIN_MINT; /* no warning
    yet: 3) */
    int32_t m = INT32_MIN - WAFER_THIN_MINT; /* no warning
    yet: 3) */

    uint32_t ul = UINT32_MAX + WAFER_THIN_MINT; /* no warning
    yet: 3) */
    uint32_t um = - WAFER_THIN_MINT; /* 2) */