summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-10-04 23:52:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-10-04 23:52:29 +0000
commit9f9e5826f2863ece1d25bf251e323a73857a5be6 (patch)
tree9fb36c69a078bf66873ca13720b8957761fc29b4 /clang/lib/CodeGen/CodeGenFunction.cpp
parent4d6cd886f5e6ad05ec5284f19b22457d5c16fe63 (diff)
downloadbcm5719-llvm-9f9e5826f2863ece1d25bf251e323a73857a5be6.tar.gz
bcm5719-llvm-9f9e5826f2863ece1d25bf251e323a73857a5be6.zip
If we flow off the end of a value-returning function:
- outside C++, return undef (behavior is not undefined unless the value is used) - in C++, with -fcatch-undefined-behavior, perform an appropriate trap - in C++, produce an 'unreachable' (behavior is undefined immediately) llvm-svn: 165273
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1d02861ed78..5c0247a33ff 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -535,6 +535,20 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
else
EmitFunctionBody(Args);
+ // C++11 [stmt.return]p2:
+ // Flowing off the end of a function [...] results in undefined behavior in
+ // a value-returning function.
+ // C11 6.9.1p12:
+ // If the '}' that terminates a function is reached, and the value of the
+ // function call is used by the caller, the behavior is undefined.
+ if (getContext().getLangOpts().CPlusPlus && !FD->hasImplicitReturnZero() &&
+ !FD->getResultType()->isVoidType() && Builder.GetInsertBlock()) {
+ if (CatchUndefined)
+ EmitCheck(Builder.getFalse());
+ Builder.CreateUnreachable();
+ Builder.ClearInsertionPoint();
+ }
+
// Emit the standard function epilogue.
FinishFunction(BodyRange.getEnd());
OpenPOWER on IntegriCloud