Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / objc.dg / gnu-api-2-ivar.m
blob072d2655bb8badd82512effd11b091716f62002b
1 /* Test the Modern GNU Objective-C Runtime API.
3   This is test 'ivar', covering all functions starting with 'ivar'.  */
5 /* { dg-do run } */
6 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
7 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8 /* { dg-additional-options "-Wno-objc-root-class" } */
10 /* To get the modern GNU Objective-C Runtime API, you include
11    objc/runtime.h.  */
12 #include <objc/runtime.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
17 @interface MyRootClass
18 { Class isa; }
19 + alloc;
20 - init;
21 + initialize;
22 @end
24 @implementation MyRootClass
25 + alloc { return class_createInstance (self, 0); }
26 - init  { return self; }
27 + initialize { return self; }
28 @end
30 @protocol MyProtocol
31 - (id) variable;
32 @end
34 @protocol MySecondProtocol
35 - (id) setVariable: (id)value;
36 @end
38 @interface MySubClass : MyRootClass <MyProtocol>
39 { id variable_ivar; }
40 - (void) setVariable: (id)value;
41 - (id) variable;
42 @end
44 @implementation MySubClass
45 - (void) setVariable: (id)value { variable_ivar = value; }
46 - (id) variable { return variable_ivar; }
47 @end
50 int main(int argc, void **args)
52   /* Functions are tested in alphabetical order.  */
54   printf ("Testing ivar_getName () ...\n");
55   {
56     Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
57                                            "variable_ivar");
58    if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
59       abort ();
61    ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
62                                      "variable");
63    if (ivar != 0)
64       abort ();
65   }
67   printf ("Testing ivar_getOffset () ...\n");
68   {
69     Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
70                                            "isa");
71     if (ivar_getOffset (ivar) != 0)
72       abort ();
73   }
75   printf ("Testing ivar_getTypeEncoding () ...\n");
76   {
77     Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
78                                            "variable_ivar");
79     if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)
80       abort ();
81   }
83   return 0;