#2205 return statement discarded if expected operand missing


1: Sample code that reproduces the problem.

static char m;

void *two__init (void)

2: Exact command used to run SDCC on this sample code

sdcc -mz80 -c two.c

3: SDCC version

SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08
/stm8 3.3.1 #8807 (Aug 18 2013) (MINGW32)

4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.

SDCC absoultely does not generate any code for the line "if(m)return;"
two.c:5: warning 110: conditional flow changed by optimizer: so said EVELYN the
modified DOG

;two.c:3: void *twoinit (void)
; ---------------------------------
; Function two
; ---------------------------------
;two.c:6: m=1;
ld iy,#_m
ld 0 (iy),#0x01

But if just replace "return" to "return 0" - the problem disappears.


<< < 1 2 (Page 2 of 2)
  • Philipp Klaus Krause

    Yes. Sorry. Even dumpraw0 already looks buggy, so this seems to really be a frontend bug.


  • Erik Petrich

    Erik Petrich - 2013-08-19
    • assigned_to: Erik Petrich
  • Erik Petrich

    Erik Petrich - 2013-08-19

    The diagnostic message for return missing an expected operand is classified as a warning, but then is being handled as an error (discarding the return operation entirely). I still need to do some testing, but I should have a commit to fix this later today.

  • Maarten Brock

    Maarten Brock - 2013-08-19

    Ah, so it was a 'no return at all' for undefined behavior.
    Is there any reason to keep this just a warning and not an error?
    I vote for error.

  • Oleg N. Cher

    Oleg N. Cher - 2013-08-19

    I vote for warning.
    Many of C compilers accept such code with just warning.
    Maarten, if you want to improve C language to be more safe and comfortable, you'll need to make a new language better.
    But a C compiler cannot be "improved" by the addition of incompatibility with other C compilers. Example of the compiler support warning in such case? tcc, gcc/mingw/djgpp, ms visual c, borland с builder, turbo c, microsoft quick c, etc, etc.

  • Oleg N. Cher

    Oleg N. Cher - 2013-08-19

    As well as C language is not only a programming language. It's a set of traditions, a developers culture and the gigabytes of C sources. We have not right to drop it out IMHO.

    Maarten, please look at this a normal C function written in assembler:

    unsigned char Basic_POINT (short int x, short int y)

    ifdef __SDCC

    LD IX,#0


    LD IY,#0x5C3A
    LD C,4(IX)
    LD B,5(IX)
    CALL #0x22CE
    CALL #0x2DD5
    LD L,A

    ifdef __SDCC

    POP IX



    Now it compiles with a warnings:

    two.c:18: warning 59: function 'Basic_POINT' must return value
    two.c:18: warning 85: in function Basic_POINT unreferenced function argument : 'x'
    two.c:18: warning 85: in function Basic_POINT unreferenced function argument : 'y'

    As I understand, you propose to disallow that method of using functions that must return result but not return it, at all. And I have a question for you - how do you propose to rewrite the function "Basic_POINT" with the presence of "return"?

    Last edit: Oleg N. Cher 2013-08-19
  • Erik Petrich

    Erik Petrich - 2013-08-19

    It seems to me that the original example is valid under C89/90, so it should not be elevated to an error there. Later C standards only require that we issue a diagnostic message (it's our discretion how we want to classify it). Assuming I find no unexpected result during testing, it would be easiest to leave this as a warning for all standards and just return an undefined value (whatever happens to be in the return register(s), so there's not effect on code efficiency).

  • Erik Petrich

    Erik Petrich - 2013-08-20

    Fixed in revision #8809

  • Erik Petrich

    Erik Petrich - 2013-08-20
    • summary: if omitted in C89/C90 code that is not valid C99 --> return statement discarded if expected operand missing
    • status: open --> closed-fixed
  • Maarten Brock

    Maarten Brock - 2013-08-30

    I've added a regression test for this case in #8824.

<< < 1 2 (Page 2 of 2)

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

Sign up for the SourceForge newsletter:

No, thanks