]> granicus.if.org Git - clang/commit
Add -f[no-]strict-return flag that can be used to avoid undefined behaviour
authorAlex Lorenz <arphaman@gmail.com>
Wed, 4 Jan 2017 13:40:34 +0000 (13:40 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 4 Jan 2017 13:40:34 +0000 (13:40 +0000)
commit8fca6cf5969b00357ecf6b33a008f2633c5f0b93
tree1d987390e827995cfd8ad28ddc88d2e53a95a327
parent8bd2b99f9b7a5a83534a4bbf73e2db4f608055c2
Add -f[no-]strict-return flag that can be used to avoid undefined behaviour
in non-void functions that fall off at the end without returning a value when
compiling C++.

Clang uses the new compiler flag to determine when it should treat control flow
paths that fall off the end of a non-void function as unreachable. If
-fno-strict-return is on, the code generator emits the ureachable and trap
IR only when the function returns either a record type with a non-trivial
destructor or another non-trivially copyable type.

The primary goal of this flag is to avoid treating falling off the end of a
non-void function as undefined behaviour. The burden of undefined behaviour
is placed on the caller instead: if the caller ignores the returned value then
the undefined behaviour is avoided. This kind of behaviour is useful in
several cases, e.g. when compiling C code in C++ mode.

rdar://13102603

Differential Revision: https://reviews.llvm.org/D27163

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290960 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/CodeGenFunction.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGenCXX/return.cpp
test/CodeGenObjCXX/return.mm [new file with mode: 0644]
test/Driver/clang_f_opts.c