diff options
| author | Hal Finkel <hfinkel@anl.gov> | 2014-07-11 17:35:21 +0000 |
|---|---|---|
| committer | Hal Finkel <hfinkel@anl.gov> | 2014-07-11 17:35:21 +0000 |
| commit | 82504f03ce98c30da60a12d84c71384e44734f15 (patch) | |
| tree | 784f293a5b04692676d2d61904f34c26632e68d0 /clang/lib/CodeGen | |
| parent | 0a51abc100bf47fbd009e827274175e8d549e7fd (diff) | |
| download | bcm5719-llvm-82504f03ce98c30da60a12d84c71384e44734f15.tar.gz bcm5719-llvm-82504f03ce98c30da60a12d84c71384e44734f15.zip | |
Add nonnull in CodeGen for __attribute__((nonnull))
We now have an LLVM-level nonnull attribute that can be applied to function
parameters, and we emit it for reference types (as of r209723), but did not
emit it when an __attribute__((nonnull)) was provided. Now we will.
llvm-svn: 212835
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 11 |
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, |

