From 8e1162c71d40ada37c358d17182c68d8d9fad41d Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 8 Sep 2014 17:22:45 +0000 Subject: Implement nonnull-attribute sanitizer Summary: This patch implements a new UBSan check, which verifies that function arguments declared to be nonnull with __attribute__((nonnull)) are actually nonnull in runtime. To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs (where applicable) and if function declaration has nonnull attribute specified for a certain formal parameter, we compare the corresponding RValue to null as soon as it's calculated. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, rnk Differential Revision: http://reviews.llvm.org/D5082 llvm-svn: 217389 --- clang/lib/CodeGen/CodeGenFunction.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.h') diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 4841b535062..ff74ce9fd75 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2625,6 +2625,7 @@ public: void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, CallExpr::const_arg_iterator ArgBeg, CallExpr::const_arg_iterator ArgEnd, + const FunctionDecl *CalleeDecl = nullptr, unsigned ParamsToSkip = 0, bool ForceColumnInfo = false) { SmallVector ArgTypes; CallExpr::const_arg_iterator Arg = ArgBeg; @@ -2673,13 +2674,15 @@ public: for (; Arg != ArgEnd; ++Arg) ArgTypes.push_back(Arg->getType()); - EmitCallArgs(Args, ArgTypes, ArgBeg, ArgEnd, ForceColumnInfo); + EmitCallArgs(Args, ArgTypes, ArgBeg, ArgEnd, CalleeDecl, ParamsToSkip, + ForceColumnInfo); } void EmitCallArgs(CallArgList &Args, ArrayRef ArgTypes, CallExpr::const_arg_iterator ArgBeg, CallExpr::const_arg_iterator ArgEnd, - bool ForceColumnInfo = false); + const FunctionDecl *CalleeDecl = nullptr, + unsigned ParamsToSkip = 0, bool ForceColumnInfo = false); private: const TargetCodeGenInfo &getTargetHooks() const { -- cgit v1.2.3