blob: 3c560752749add91abf0b1e1a681f9cbca480549 [file] [log] [blame]
Aaron Ballmanbf5cf8c2013-07-22 17:55:04 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Fariborz Jahanianf4aa2792011-06-27 21:12:03 +00002// rdar://9584012
3
4typedef struct {
5 char *str;
6} Class;
7
8typedef union {
9 Class *object;
10} Instance __attribute__((transparent_union));
11
12__attribute__((nonnull(1))) void Class_init(Instance this, char *str) {
13 this.object->str = str;
14}
15
16int main(void) {
17 Class *obj;
18 Class_init(0, "Hello World"); // expected-warning {{null passed to a callee which requires a non-null argument}}
19 Class_init(obj, "Hello World");
20}
21
Aaron Ballmanbe50eb82013-07-30 00:48:57 +000022void foo(const char *str) __attribute__((nonnull("foo"))); // expected-error{{'nonnull' attribute requires parameter 1 to be an integer constant}}
Aaron Ballmancedaaea2013-12-26 17:07:49 +000023void bar(int i) __attribute__((nonnull(1))); // expected-warning {{'nonnull' attribute only applies to pointer arguments}} expected-warning {{'nonnull' attribute applied to function with no pointer arguments}}
Ted Kremenek9aedc152014-01-17 06:24:56 +000024
25void baz(__attribute__((nonnull)) const char *str);
26void baz2(__attribute__((nonnull(1))) const char *str); // expected-warning {{'nonnull' attribute when used on parameters takes no arguments}}
27void baz3(__attribute__((nonnull)) int x); // expected-warning {{'nonnull' attribute only applies to pointer arguments}}
28
29void test_baz() {
30 baz(0); // expected-warning {{null passed to a callee which requires a non-null argument}}
31 baz2(0); // no-warning
32 baz3(0); // no-warning
33}
34
Aaron Ballmand6432f82014-01-17 14:38:58 +000035int i __attribute__((nonnull)); // expected-warning {{'nonnull' attribute only applies to functions, methods, and parameters}}