diff options
author | Vedant Kumar <vsk@apple.com> | 2017-12-21 00:10:25 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-12-21 00:10:25 +0000 |
commit | 09b5bfdd85fa23a331ee565bda289b3c27c00fdf (patch) | |
tree | a5adff5e6bd5871fe32873bd2e3da642ba0f6247 /clang/lib/CodeGen/CGExpr.cpp | |
parent | fae4f7c6818343acc9ad54cacaadaf9fc6fcf52d (diff) | |
download | bcm5719-llvm-09b5bfdd85fa23a331ee565bda289b3c27c00fdf.tar.gz bcm5719-llvm-09b5bfdd85fa23a331ee565bda289b3c27c00fdf.zip |
[ubsan] Diagnose noreturn functions which return
Diagnose 'unreachable' UB when a noreturn function returns.
1. Insert a check at the end of functions marked noreturn.
2. A decl may be marked noreturn in the caller TU, but not marked in
the TU where it's defined. To diagnose this scenario, strip away the
noreturn attribute on the callee and insert check after calls to it.
Testing: check-clang, check-ubsan, check-ubsan-minimal, D40700
rdar://33660464
Differential Revision: https://reviews.llvm.org/D40698
llvm-svn: 321231
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 98740e8f9aa..b61b273977d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3076,6 +3076,17 @@ void CodeGenFunction::EmitCfiCheckFail() { CGM.addUsedGlobal(F); } +void CodeGenFunction::EmitUnreachable(SourceLocation Loc) { + if (SanOpts.has(SanitizerKind::Unreachable)) { + SanitizerScope SanScope(this); + EmitCheck(std::make_pair(static_cast<llvm::Value *>(Builder.getFalse()), + SanitizerKind::Unreachable), + SanitizerHandler::BuiltinUnreachable, + EmitCheckSourceLocation(Loc), None); + } + Builder.CreateUnreachable(); +} + void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked) { llvm::BasicBlock *Cont = createBasicBlock("cont"); @@ -4616,7 +4627,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee Callee.setFunctionPointer(CalleePtr); } - return EmitCall(FnInfo, Callee, ReturnValue, Args); + return EmitCall(FnInfo, Callee, ReturnValue, Args, nullptr, E->getExprLoc()); } LValue CodeGenFunction:: |