Menu ▾ ▴

#880 Call in deeply nested _Generic not inlined.

None
open
nobody
None
5
8 hours ago
2023-06-11
No

For the attached sample, the calls inside the innermost _generic are not inlined.

While the code sample might look exotic at first sight, this bug is a real problem for us: the sample has been created when tracking down the underlying cause of a major strtoul code size regression: [feature-requests:#872].

1 Attachments

Related

Feature Requests: #872

Discussion

  • Philipp Klaus Krause

    • summary: Call in deeply nested _Generic not inblined. --> Call in deeply nested _Generic not inlined.
     
  • Philipp Klaus Krause

    Looks like this won't be easy to solve: We currently inline before we expand _Generic, and at the time of inlining, we don't have a symbol for the function in this call yet (it is still and AST node of type GENERIC).

     
    • Christopher Bazley

      Looks like this won't be easy to solve: We currently inline before we expand _Generic, and at the time of inlining, we don't have a symbol for the function in this call yet (it is still and AST node of type GENERIC).

      Please consider the attached candidate patch to implement the requested feature and undo the workaround in stdckdint.h. The fix seems pleasingly self-contained: it adds an extra conditional block on entry to expandInlineFuncs, to resolve a generic callee before looking for an inline function symbol.

      As previously noted, the patch for [bugs:#4113] is a prerequisite for applying the proposed patch to implement inlining, otherwise reverting the workaround in stdckdint.h provokes errors in checked arithmetic.

       

      Related

      Bugs: #4113


      Last edit: Christopher Bazley 1 day ago
      • Christopher Bazley

        Please find a revised candidate patch attached. A fresh library build showed undefined-identifier errors in checked arithmetic inside strtoul.

        This new version marks declarations in scope during inline function expansion and adds tests for nested blocks and shadowed variable declarations (in support/regression/tests/generic-inline.c) and checked arithmetic (in support/valdiag/tests/generic-inline.c).

        The revised fix for [bugs:#4113] is still a prerequisite.

         

        Related

        Bugs: #4113

  • Philipp Klaus Krause

    Ticket moved from /p/sdcc/bugs/3602/

    Can't be converted:

    • _category: other
     
  • Philipp Klaus Krause

    Moving to feature requests as it is more an efficiency issue than a bug.

     
  • Christopher Bazley

    While working on [bugs:#3952], I noticed a workaround in stdckdint.h which avoids using _Genericin the way intended by its designer (to select a function before calling it), for performance reasons relating to this feature request. In turn, that workaround required me to add casts that I would rather not have added because they undermine type safety.

    I think that fixing [bugs:#4113] is a prerequisite for implementing this feature request, otherwise reverting the workaround in stdckdint.h provokes errors in checked arithmetic.

     

    Related

    Bugs: #3952
    Bugs: #4113


Log in to post a comment.