Menu ▾ ▴

#2878 Missing error on return in function returning void

closed-out-of-date
None
other
5
2023-01-26
2019-03-01
No

SDCC currently does not give an error on returning an expression of type void in a function returning void, even though the standard does not allow it ("A return statement with an expression shall not appear in a function whose return type is void." in section 6.8.6.4 of the ISO C17 standard):

static void attr_rtx            (char *, char *);
static char *attr_string        (char *);

static void
attr_eq (char *name, char *value)
{
  return attr_rtx (attr_string (name), attr_string (value));
}

Apparently allowing this is a GCC extension. Unfortunately, SDCC doesn't handle it fully that way either, as it results in a temporary of size zero, which in turn can cause problems in the backends (e.g. a segfault in the pdk14 backend).

IMO, the easiest solution is to just give an error on such a return statement.

Philipp

Related

Wiki: NGI0-Entrust-SDCC

Discussion

  • Philipp Klaus Krause

     
  • Philipp Klaus Krause

    Looking at SDCCast.c, it seems SDCC intentionally allows this.
    So we're back to the question: Fix it, so it is handled like in GCC, or just give an error.

    Philipp

     
  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -SDCC currently dfoes not give an error on returning an expression of type void in a function returning void, even though the standard does not allow it ("A return statement with an expression shall not appear in a function whose return type is void." in section 6.8.6.4 of the ISO C17 standard):
    +SDCC currently does not give an error on returning an expression of type void in a function returning void, even though the standard does not allow it ("A return statement with an expression shall not appear in a function whose return type is void." in section 6.8.6.4 of the ISO C17 standard):
    
     ~~~~
     static void attr_rtx            (char *, char *);
    
     
  • Philipp Klaus Krause

    • status: open --> closed-out-of-date
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Looks like this has been fixed since. As of [r13822], we get the error when using --std-cXX, and for --std-sdccXX, we generate working code.

     

    Related

    Commit: [r13822]


Log in to post a comment.