PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / objc.dg / ivar-scope-4.m
blobf7209724be998c12d5a3fd21aeade16b65c096cd
1 /* Test instance variable scope.  */
2 /* Author: Dimitris Papavasiliou <dpapavas@gmail.com>.  */
3 /* { dg-do run } */
4 /* { dg-additional-options "-Wno-shadow-ivar -fno-local-ivars" } */
5 #include "../objc-obj-c++-shared/runtime.h"
6 #include <objc/objc.h>
8 extern void abort(void);
10 int someivar = 1;
12 /* The testsuite object depends on local variable scope so we need to
13    implement our own minimal base object here. */
15 @interface MyClass
17   Class isa;
18   int someivar;
21 + (id) alloc;
22 - (id) init;
23 - (int) getGlobal;
24 - (int) getInstance;
25 - (int) getHidden;
26 @end
28 @implementation MyClass
29 + (id) alloc
31   return class_createInstance (self, 0);
34 - (id) init
36   self->someivar = 2;
38   return self;
41 - (int) getGlobal
43   return someivar;
46 - (int) getInstance
48   return self->someivar;
51 - (int) getHidden
53   int someivar = 3;
54   
55   return someivar;
57 @end
59 int main(void)
61   id object;
63   object = [[MyClass alloc] init];
65   /* Check for aliasing between instance variable and global
66      variable. */
68   if ([object getGlobal] != 1) {
69     abort();
70   }
71   
72   if ([object getInstance] != 2) {
73     abort();
74   }
76   /* Check whether the local variable hides the instance variable. */
77   
78   if ([object getHidden] != 3) {
79     abort();
80   }
82   return 0;