[cfe-commits] r158663 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp test/Sema/alloc_size.c

Nuno Lopes nunoplopes at sapo.pt
Mon Jun 18 09:39:04 PDT 2012


Author: nlopes
Date: Mon Jun 18 11:39:04 2012
New Revision: 158663

URL: http://llvm.org/viewvc/llvm-project?rev=158663&view=rev
Log:
fix PR13071 / rdar://problem/11634669 :
crash on invalid function decl with alloc_size attribute

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/alloc_size.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=158663&r1=158662&r2=158663&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Jun 18 11:39:04 2012
@@ -923,6 +923,12 @@
 }
 
 static void handleAllocSizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  if (!isFunctionOrMethod(D)) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+    << "alloc_size" << ExpectedFunctionOrMethod;
+    return;
+  }
+
   if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
     return;
 

Modified: cfe/trunk/test/Sema/alloc_size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc_size.c?rev=158663&r1=158662&r2=158663&view=diff
==============================================================================
--- cfe/trunk/test/Sema/alloc_size.c (original)
+++ cfe/trunk/test/Sema/alloc_size.c Mon Jun 18 11:39:04 2012
@@ -20,3 +20,7 @@
 void *fn8(int, int) __attribute__((alloc_size(1, 1))); // OK
 
 void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // expected-warning {{integer constant is too large for its type}} // expected-error {{attribute parameter 1 is out of bounds}}
+
+void* fn10(size_t, size_t) __attribute__((alloc_size(1,2))); // expected-error{{redefinition of parameter}} \
+                                                             // expected-error{{a parameter list without types is only allowed in a function definition}} \
+                                                             // expected-warning{{alloc_size attribute only applies to functions and methods}}





More information about the cfe-commits mailing list