add CodeGen support for the alloc_size attribute
llvm-svn: 157483
This commit is contained in:
parent
debb881079
commit
147dcd8c33
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
|
||||
|
||||
void *my_recalloc(void *, unsigned, unsigned) __attribute__((alloc_size(2,3)));
|
||||
|
||||
// CHECK: @f
|
||||
void* f() {
|
||||
// CHECK: call i8* @my_recalloc{{.*}}, !alloc_size !0
|
||||
return my_recalloc(0, 11, 27);
|
||||
}
|
||||
|
||||
// CHECK: !0 = metadata !{i32 1, i32 2}
|
Loading…
Reference in New Issue