summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
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
commit147dcd8c33258f0239baf9a02bfca846557e09f4 (patch)
treefe8927060d98a42c4f2158be7f369a7fa6379e65 /clang/lib/CodeGen
parentdebb88107981694c5e16ce6030180b1ed8c98fd1 (diff)
downloadbcm5719-llvm-147dcd8c33258f0239baf9a02bfca846557e09f4.tar.gz
bcm5719-llvm-147dcd8c33258f0239baf9a02bfca846557e09f4.zip
add CodeGen support for the alloc_size attribute
llvm-svn: 157483
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3ad1df1782f..650fe8b6233 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/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)
OpenPOWER on IntegriCloud