#1545 switch in inline function does not work

closed-fixed
Maarten Brock
5
2013-05-25
2009-06-23
Johan Hovold
No

Bad assembly code (jumps to undefined symbols) is generated from a switch statement within an inline function.

static inline void g(void)
{
extern char c;

switch(c) {
case 0:
c = 1;
break;
}
}

static void f(void)
{
g();
}

$ sdcc -mmcs51 --model-small --std-c99 -c -o inline_bug.rel inline_bug.c
inline_bug.c:7: warning 126: unreachable code
inline_bug.c:7: warning 126: unreachable code
?ASxxxx-Error-<u> in line 125 of inline_bug.asm
<u> undefined symbol encountered during assembly
?ASxxxx-Error-<u> in line 128 of inline_bug.asm
<u> undefined symbol encountered during assembly
removing inline_bug.rel

SDCC : mcs51 2.9.0 #5416 (May 7 2009) (UNIX)

Discussion

  • Johan Hovold
    Johan Hovold
    2009-06-23

    switch statement in inline function

     
    Attachments
  • Johan Hovold
    Johan Hovold
    2009-06-23

    unresolved symbols in generated assembly code

     
    Attachments
  • RvS
    RvS
    2009-08-11

    The problem is that labels are generated for cases in switch statements only when the ast is transformed into iCode, as then is decided whether a jumptable or a set if if-statements is generated. And this is *after* the inline function expansion. Hence, you see in a number of places in the code a translation of case statements to actual lables (search for "case_%d_%d"); one for each value in swvals.val. The solution is that the label should be created *before* inline function expansion is executed.
    or me it is not clear how this can be achieved. So, ideas are welcome, I will give it a try.

    Ruud

     
  • Maarten Brock
    Maarten Brock
    2010-09-13

    This bug seems to have been fixed along the way as it no longer exists in SDCC 2.9.7 #5969. It no longer warns about unreachable code nor errors on undefined symbols.

     
  • Maarten Brock
    Maarten Brock
    2010-09-13

    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed