summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 44fd4d8b597..c32e4f2c1f4 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1381,6 +1381,10 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
++AI; // Skip the sret parameter.
}
+ // Get the function-level nonnull attribute if it exists.
+ const NonNullAttr *NNAtt =
+ CurCodeDecl ? CurCodeDecl->getAttr<NonNullAttr>() : nullptr;
+
// Track if we received the parameter as a pointer (indirect, byval, or
// inalloca). If already have a pointer, EmitParmDecl doesn't need to copy it
// into a local alloca for us.
@@ -1468,6 +1472,13 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
assert(AI != Fn->arg_end() && "Argument mismatch!");
llvm::Value *V = AI;
+ if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg))
+ if ((NNAtt && NNAtt->isNonNull(PVD->getFunctionScopeIndex())) ||
+ PVD->hasAttr<NonNullAttr>())
+ AI->addAttr(llvm::AttributeSet::get(getLLVMContext(),
+ AI->getArgNo() + 1,
+ llvm::Attribute::NonNull));
+
if (Arg->getType().isRestrictQualified())
AI->addAttr(llvm::AttributeSet::get(getLLVMContext(),
AI->getArgNo() + 1,
OpenPOWER on IntegriCloud