[cfe-commits] r157483 - in /cfe/trunk: lib/CodeGen/CGCall.cpp test/CodeGen/alloc_size.c
Jordy Rose
jediknil at belkadan.com
Fri May 25 13:41:52 PDT 2012
Suggestion: use the stack-based SmallVector instead of std::vector. Also, a CXXMethodDecl might be a static method, so you'll need to check isInstance() as well.
Jordy
On May 25, 2012, at 13:04, Nuno Lopes wrote:
> Author: nlopes
> Date: Fri May 25 12:04:42 2012
> New Revision: 157483
>
> URL: http://llvm.org/viewvc/llvm-project?rev=157483&view=rev
> Log:
> add CodeGen support for the alloc_size attribute
>
> Added:
> cfe/trunk/test/CodeGen/alloc_size.c
> Modified:
> cfe/trunk/lib/CodeGen/CGCall.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=157483&r1=157482&r2=157483&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri May 25 12:04:42 2012
> @@ -2087,6 +2087,23 @@
> 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)
>
> Added: cfe/trunk/test/CodeGen/alloc_size.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alloc_size.c?rev=157483&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/alloc_size.c (added)
> +++ cfe/trunk/test/CodeGen/alloc_size.c Fri May 25 12:04:42 2012
> @@ -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}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list