]> granicus.if.org Git - clang/commitdiff
Don't crash when applying an alloc_size attribute on a K&R function.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 22 Feb 2013 06:58:28 +0000 (06:58 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 22 Feb 2013 06:58:28 +0000 (06:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175867 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0a30163f99d43bc8756040346fc8c0cdd7b463fc..1142e0dd2db718d8e8bcf1cd362bc93c777cc9fe 100644 (file)
@@ -1097,7 +1097,11 @@ static void handleAllocSizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   // In C++ the implicit 'this' function parameter also counts, and they are
   // counted from one.
   bool HasImplicitThisParam = isInstanceMethod(D);
-  unsigned NumArgs = getFunctionOrMethodNumArgs(D) + HasImplicitThisParam;
+  unsigned NumArgs;
+  if (hasFunctionProto(D))
+    NumArgs = getFunctionOrMethodNumArgs(D) + HasImplicitThisParam;
+  else
+    NumArgs = 0;
 
   SmallVector<unsigned, 8> SizeArgs;
 
index e2f52987d1dbbf606c840a597fd0d073a2befbc7..6a580b5a809be5ce9feb501fd5f3c241bb7f27fc 100644 (file)
@@ -24,3 +24,4 @@ void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // exp
 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}}
+void* fn11() __attribute__((alloc_size(1))); // expected-error{{attribute parameter 1 is out of bounds}}