https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106696

            Bug ID: 106696
           Summary: Fallthrough between functions without proper return
                    statement when optimizing
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefan.kneifel at bluewin dot ch
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---
              Host: x86_64
            Target: x86_64, aarch64

Consider the following incorrect code:
----------------------
void*   foo     (void)
{
}

int     bar     (void)
{
    return 42;
}
----------------------
Compiling this as either plain C or without optimization gives the proper
warning (no return statement in function returning non-void), but returns from
foo. However, compiling this as C++ with optimization on (-O1 is sufficient),
the warning is emitted anyway, but the function body of foo is now eliminated
entirely (even the ret statement!) and a call to foo() falls through to a call
to bar(). For security reasons, I don't think this should be the case, even
when the input code is faulty.

Reply via email to