diff options
| author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-24 00:22:00 +0000 |
|---|---|---|
| committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-24 00:22:00 +0000 |
| commit | 5c7ad16fddccc4841d89ac87a3b226ad64bb39af (patch) | |
| tree | 398407e57ca4acd5e003a9eafb062372038510f7 /clang/test | |
| parent | 9b43c3f0c5cf2c360abe613dd81f616da148395b (diff) | |
| download | bcm5719-llvm-5c7ad16fddccc4841d89ac87a3b226ad64bb39af.tar.gz bcm5719-llvm-5c7ad16fddccc4841d89ac87a3b226ad64bb39af.zip | |
implement Sema support for the alloc_size attribute
Portions of this patch by Xi Wang. Reviewed by Jordy Rose. Thank you both.
Codegen support will follow soon.
llvm-svn: 157360
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Sema/alloc_size.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/test/Sema/alloc_size.c b/clang/test/Sema/alloc_size.c new file mode 100644 index 00000000000..18309e3106e --- /dev/null +++ b/clang/test/Sema/alloc_size.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void* my_malloc(unsigned char) __attribute__((alloc_size(1))); +void* my_calloc(unsigned char, short) __attribute__((alloc_size(1,2))); +void* my_realloc(void*, unsigned) __attribute__((alloc_size(2))); + + +void* fn1(int) __attribute__((alloc_size("xpto"))); // expected-error{{attribute requires integer constant}} + +void* fn2(void*) __attribute__((alloc_size(1))); // expected-error{{attribute requires integer constant}} + +void* fn3(unsigned) __attribute__((alloc_size(0))); // expected-error{{attribute parameter 1 is out of bounds}} +void* fn4(unsigned) __attribute__((alloc_size(2))); // expected-error{{attribute parameter 1 is out of bounds}} + +void fn5(unsigned) __attribute__((alloc_size(1))); // expected-warning{{only applies to functions that return a pointer}} +char fn6(unsigned) __attribute__((alloc_size(1))); // expected-warning{{only applies to functions that return a pointer}} + +void* fn7(unsigned) __attribute__((alloc_size)); // expected-error {{attribute takes at least 1 argument}} + +void *fn8(int, int) __attribute__((alloc_size(1, 1))); // expected-error {{attribute parameter 2 is duplicated}} + +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}} |

