]> granicus.if.org Git - clang/commitdiff
fix PR13071 / rdar://problem/11634669 :
authorNuno Lopes <nunoplopes@sapo.pt>
Mon, 18 Jun 2012 16:39:04 +0000 (16:39 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Mon, 18 Jun 2012 16:39:04 +0000 (16:39 +0000)
crash on invalid function decl with alloc_size attribute

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158663 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/alloc_size.c

index 561b624167a7a17d6e3062bff7d69e9348c1d593..e8682d78afa79aa4f95b8376f987e0cbd6395a9d 100644 (file)
@@ -923,6 +923,12 @@ static void possibleTransparentUnionPointerType(QualType &T) {
 }
 
 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;
 
index ae3b4763ccdfafe757b25ecc6a80f5276a330010..e2f52987d1dbbf606c840a597fd0d073a2befbc7 100644 (file)
@@ -20,3 +20,7 @@ void* fn7(unsigned) __attribute__((alloc_size)); // expected-error {{attribute t
 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}}