Menu

#2962 "static" keyword prevent inline function body elimination

closed-rejected
None
Front-end
5
2020-01-08
2019-12-23
No

sdcc 3.9.5 #11502
sdcc -mmcs51 --opt-code-size --peep-asm --peep-return test.c

test.c:

 __xdata __at (0x0000) unsigned char reg;
 static inline void foo() {reg++;}
 inline void bar() {reg--;}
 void main(){
    foo();
    bar();
 }

bar - inlined fine
foo - inlined, but body not eliminated and take program space as unreferenced.

Discussion

  • Philipp Klaus Krause

    Since the generated code is correct, this is not a bug.

    The underlying issue is that SDCC is currently a single-pass compiler that compiles each function separately. By the time the static inline function foo is compiled, SDCC does not know if there are uses of foo that cannot be inlined. So it has to generate a function body.

    There already is an open feature request:
    [feature-requests:#414]

    Implementing it would require to do two passes over each whole source file, a first pass to analyze it and pass information to the second. The second pass generating code.

     

    Related

    Feature Requests: #414


    Last edit: Maarten Brock 2024-11-23
  • Philipp Klaus Krause

    • status: open --> closed-rejected
    • assigned_to: Philipp Klaus Krause
    • Category: MCS51 --> Front-end
     

Log in to post a comment.

MongoDB Logo MongoDB