diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-18 16:39:04 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-18 16:39:04 +0000 |
commit | e881ce2ef6da7865f30fe968fbb3d758436e0ab2 (patch) | |
tree | 0a803ce9027de61a2e02ae36ef8220b1220711ba | |
parent | e44e93aa6b82004c21843177f2f41b6281c492f0 (diff) | |
download | bcm5719-llvm-e881ce2ef6da7865f30fe968fbb3d758436e0ab2.tar.gz bcm5719-llvm-e881ce2ef6da7865f30fe968fbb3d758436e0ab2.zip |
fix PR13071 / rdar://problem/11634669 :
crash on invalid function decl with alloc_size attribute
llvm-svn: 158663
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 6 | ||||
-rw-r--r-- | clang/test/Sema/alloc_size.c | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 561b624167a..e8682d78afa 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -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; diff --git a/clang/test/Sema/alloc_size.c b/clang/test/Sema/alloc_size.c index ae3b4763ccd..e2f52987d1d 100644 --- a/clang/test/Sema/alloc_size.c +++ b/clang/test/Sema/alloc_size.c @@ -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}} |