3 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
4 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
5 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
6 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
7 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
8 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
9 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
10 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
11 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
12 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
13 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
14 .*ivar.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
22 #include <objc/objc-runtime.h>
24 @interface Super : TestRoot {
30 @interface Sub : Super {
36 @implementation Super @end
37 @implementation Sub @end
43 Runtime layout of Sub:
51 sub->subIvar = [Sub class];
52 testassert(((Class *)(__bridge void *)sub)[2] == [Sub class]);
54 ivar = class_getInstanceVariable([Sub class], "subIvar");
56 testassert(2*sizeof(intptr_t) == (size_t)ivar_getOffset(ivar));
57 testassert(0 == strcmp(ivar_getName(ivar), "subIvar"));
58 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "@"));
60 ivar = class_getInstanceVariable([Super class], "superIvar");
62 testassert(sizeof(intptr_t) == (size_t)ivar_getOffset(ivar));
63 testassert(0 == strcmp(ivar_getName(ivar), "superIvar"));
64 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "c"));
65 testassert(ivar == class_getInstanceVariable([Sub class], "superIvar"));
67 ivar = class_getInstanceVariable([Super class], "subIvar");
70 ivar = class_getInstanceVariable(object_getClass([Sub class]), "subIvar");
73 ivar = class_getInstanceVariable([Sub class], "subIvar");
74 object_setIvar(sub, ivar, sub);
75 testassert(sub->subIvar == sub);
76 testassert(sub == object_getIvar(sub, ivar));
78 testassert(NULL == class_getInstanceVariable(NULL, "foo"));
79 testassert(NULL == class_getInstanceVariable([Sub class], NULL));
80 testassert(NULL == class_getInstanceVariable(NULL, NULL));
82 testassert(NULL == object_getIvar(sub, NULL));
83 testassert(NULL == object_getIvar(NULL, ivar));
84 testassert(NULL == object_getIvar(NULL, NULL));
86 object_setIvar(sub, NULL, NULL);
87 object_setIvar(NULL, ivar, NULL);
88 object_setIvar(NULL, NULL, NULL);
90 #if !__has_feature(objc_arc)
94 sub->subIvar = (id)10;
96 object_getInstanceVariable(sub, "subIvar", (void **)&value);
97 testassert(value == 10);
99 object_setInstanceVariable(sub, "subIvar", (id)11);
100 testassert(sub->subIvar == (id)11);
102 ivar = class_getInstanceVariable([Sub class], "subIvar");
103 testassert(ivar == object_getInstanceVariable(sub, "subIvar", NULL));
105 testassert(NULL == object_getInstanceVariable(sub, NULL, NULL));
106 testassert(NULL == object_getInstanceVariable(NULL, "foo", NULL));
107 testassert(NULL == object_getInstanceVariable(NULL, NULL, NULL));
109 testassert(NULL == object_getInstanceVariable(sub, NULL, (void **)&value));
110 testassert(value == 0);
112 testassert(NULL == object_getInstanceVariable(NULL, "foo", (void **)&value));
113 testassert(value == 0);
115 testassert(NULL == object_getInstanceVariable(NULL, NULL, (void **)&value));
116 testassert(value == 0);
118 testassert(NULL == object_setInstanceVariable(sub, NULL, NULL));
119 testassert(NULL == object_setInstanceVariable(NULL, "foo", NULL));
120 testassert(NULL == object_setInstanceVariable(NULL, NULL, NULL));
122 // provoke the same nullability warnings as the real test