aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-05-25 17:04:42 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-05-25 17:04:42 +0000
commit2813420dd3be04fc0c44074c3f1af1aada83ad99 (patch)
treed6af330a9a7436e48a12aef431977f692b73b129 /lib/CodeGen/CGCall.cpp
parent9db614f339f7596e2c0e0e04d6c714cd264ce883 (diff)
add CodeGen support for the alloc_size attribute
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157483 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r--lib/CodeGen/CGCall.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 3ad1df1782..650fe8b623 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -2087,6 +2087,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
CS.setAttributes(Attrs);
CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
+ // add metadata for __attribute__((alloc_size(foo)))
+ if (TargetDecl) {
+ if (const AllocSizeAttr* Attr = TargetDecl->getAttr<AllocSizeAttr>()) {
+ std::vector<llvm::Value*> Args;
+ llvm::IntegerType *Ty = llvm::IntegerType::getInt32Ty(getLLVMContext());
+ bool isMethod = isa<CXXMethodDecl>(TargetDecl);
+
+ for (AllocSizeAttr::args_iterator I = Attr->args_begin(),
+ E = Attr->args_end(); I != E; ++I) {
+ Args.push_back(llvm::ConstantInt::get(Ty, *I + isMethod));
+ }
+
+ llvm::MDNode *MD = llvm::MDNode::get(getLLVMContext(), Args);
+ CS.getInstruction()->setMetadata("alloc_size", MD);
+ }
+ }
+
// In ObjC ARC mode with no ObjC ARC exception safety, tell the ARC
// optimizer it can aggressively ignore unwind edges.
if (CGM.getLangOpts().ObjCAutoRefCount)