Nuno, this patch didn't get reviewed before commit. The LLVM review is ongoing, and seems to indicate the solution is not yet ready. Folks have also raised serious concerns about the implementation strategy here.<div><br>
</div><div>While supporting the alloc_size attribute at least enough to parse it and reject invalid formulations seems good for GCC compatibility, adding code generation and LLVM support to it is adding a significant amount of maintenance for this feature, and there has been no discussion or general consensus that this functionality's design is the right long-term solution for Clang/LLVM. In fact, there was no discussion at all until Kostya started his email thread, which I don't think you've responded to yet.</div>
<div><br></div><div>I would like to suggest you not continue committing (especially without review) patches toward a system that hasn't been designed and supported by the larger community. I think you really need to take time to engage the rest of the open source group in your efforts, and figure out what the correct design and implementation strategy is here.</div>
<div><br></div><div>I've CC'ed Chris and Doug as they may feel differently. =] I would be very interested in their feedback at least about what is the best process.</div><div>-Chandler</div><div><div><br><div class="gmail_quote">
On Fri, May 25, 2012 at 10:04 AM, Nuno Lopes <span dir="ltr"><<a href="mailto:nunoplopes@sapo.pt" target="_blank">nunoplopes@sapo.pt</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: nlopes<br>
Date: Fri May 25 12:04:42 2012<br>
New Revision: 157483<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=157483&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=157483&view=rev</a><br>
Log:<br>
add CodeGen support for the alloc_size attribute<br>
<br>
Added:<br>
    cfe/trunk/test/CodeGen/alloc_size.c<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGCall.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=157483&r1=157482&r2=157483&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=157483&r1=157482&r2=157483&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri May 25 12:04:42 2012<br>
@@ -2087,6 +2087,23 @@<br>
   CS.setAttributes(Attrs);<br>
   CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));<br>
<br>
+  // add metadata for __attribute__((alloc_size(foo)))<br>
+  if (TargetDecl) {<br>
+    if (const AllocSizeAttr* Attr = TargetDecl->getAttr<AllocSizeAttr>()) {<br>
+      std::vector<llvm::Value*> Args;<br>
+      llvm::IntegerType *Ty = llvm::IntegerType::getInt32Ty(getLLVMContext());<br>
+      bool isMethod = isa<CXXMethodDecl>(TargetDecl);<br>
+<br>
+      for (AllocSizeAttr::args_iterator I = Attr->args_begin(),<br>
+           E = Attr->args_end(); I != E; ++I) {<br>
+        Args.push_back(llvm::ConstantInt::get(Ty, *I + isMethod));<br>
+      }<br>
+<br>
+      llvm::MDNode *MD = llvm::MDNode::get(getLLVMContext(), Args);<br>
+      CS.getInstruction()->setMetadata("alloc_size", MD);<br>
+    }<br>
+  }<br>
+<br>
   // In ObjC ARC mode with no ObjC ARC exception safety, tell the ARC<br>
   // optimizer it can aggressively ignore unwind edges.<br>
   if (CGM.getLangOpts().ObjCAutoRefCount)<br>
<br>
Added: cfe/trunk/test/CodeGen/alloc_size.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alloc_size.c?rev=157483&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alloc_size.c?rev=157483&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGen/alloc_size.c (added)<br>
+++ cfe/trunk/test/CodeGen/alloc_size.c Fri May 25 12:04:42 2012<br>
@@ -0,0 +1,11 @@<br>
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s<br>
+<br>
+void *my_recalloc(void *, unsigned, unsigned) __attribute__((alloc_size(2,3)));<br>
+<br>
+// CHECK: @f<br>
+void* f() {<br>
+  // CHECK: call i8* @my_recalloc{{.*}}, !alloc_size !0<br>
+  return my_recalloc(0, 11, 27);<br>
+}<br>
+<br>
+// CHECK: !0 = metadata !{i32 1, i32 2}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>