[llvm-bugs] [Bug 32158] Program crashing due to missing return statement?

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 6 15:19:25 PST 2017


Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
                 CC|                            |richard-llvm at metafoo.co.uk
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
A compiler is not permitted to reject a program merely because some function in
it unconditionally evokes undefined behavior.

For user convenience, at -O0 we insert a trap instruction at the end of such a
function, and at -O1 and above we optimize on the basis that the end of the
function is unreachable if there is a missing 'return' statement.

In Clang 4, you can use -fno-strict-return to instead request that the function
returns uninitialized garbage when this happens. Obviously that's likely to
misbehave at runtime if the return value is used or the return type is not
trivially-destructible, but this can make sense for instance when compiling C
code as C++ (C has weaker rules in this area).

The proposed change in this bug (making -Wreturn-type an error by default)
would not be conforming; I'm marking this INVALID on that basis, but feel free
to reopen if you think there are still things that could be improved here.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170306/001c4e69/attachment.html>

More information about the llvm-bugs mailing list