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>
7
8extern void abort(void);
9
10int someivar = 1;
11
12/* The testsuite object depends on local variable scope so we need to
13   implement our own minimal base object here. */
14
15@interface MyClass
16{
17  Class isa;
18  int someivar;
19}
20
21+ (id) alloc;
22- (id) init;
23- (int) getGlobal;
24- (int) getInstance;
25- (int) getHidden;
26@end
27
28@implementation MyClass
29+ (id) alloc
30{
31  return class_createInstance (self, 0);
32}
33
34- (id) init
35{
36  self->someivar = 2;
37
38  return self;
39}
40
41- (int) getGlobal
42{
43  return someivar;
44}
45
46- (int) getInstance
47{
48  return self->someivar;
49}
50
51- (int) getHidden
52{
53  int someivar = 3;
54
55  return someivar;
56}
57@end
58
59int main(void)
60{
61  id object;
62
63  object = [[MyClass alloc] init];
64
65  /* Check for aliasing between instance variable and global
66     variable. */
67
68  if ([object getGlobal] != 1) {
69    abort();
70  }
71
72  if ([object getInstance] != 2) {
73    abort();
74  }
75
76  /* Check whether the local variable hides the instance variable. */
77
78  if ([object getHidden] != 3) {
79    abort();
80  }
81
82  return 0;
83}
84