r175867 - Don't crash when applying an alloc_size attribute on a K&R function.

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Feb 21 22:58:28 PST 2013


Author: akirtzidis
Date: Fri Feb 22 00:58:28 2013
New Revision: 175867

URL: http://llvm.org/viewvc/llvm-project?rev=175867&view=rev
Log:
Don't crash when applying an alloc_size attribute on a K&R function.

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=175867&r1=175866&r2=175867&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Feb 22 00:58:28 2013
@@ -1097,7 +1097,11 @@ static void handleAllocSizeAttr(Sema &S,
   // 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;
 

Modified: cfe/trunk/test/Sema/alloc_size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc_size.c?rev=175867&r1=175866&r2=175867&view=diff
==============================================================================
--- cfe/trunk/test/Sema/alloc_size.c (original)
+++ cfe/trunk/test/Sema/alloc_size.c Fri Feb 22 00:58:28 2013
@@ -24,3 +24,4 @@ void* fn9(unsigned) __attribute__((alloc
 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}}





More information about the cfe-commits mailing list