blob: df1c8927586ef4ede0bdb0a1750ff4b5168ea5be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* Test instance variable scope. */
/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
/* { dg-do run } */
/* { dg-additional-options "-Wno-shadow-ivar -fno-local-ivars -Wno-objc-root-class" } */
#include "../objc-obj-c++-shared/runtime.h"
#include <objc/objc.h>
extern void abort(void);
int someivar = 1;
/* The testsuite object depends on local variable scope so we need to
implement our own minimal base object here. */
@interface MyClass
{
Class isa;
int someivar;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) getGlobal;
- (int) getInstance;
- (int) getHidden;
@end
@implementation MyClass
+ (id) initialize
{
return self;
}
+ (id) alloc
{
return class_createInstance (self, 0);
}
- (id) init
{
self->someivar = 2;
return self;
}
- (int) getGlobal
{
return someivar;
}
- (int) getInstance
{
return self->someivar;
}
- (int) getHidden
{
int someivar = 3;
return someivar;
}
@end
int main(void)
{
id object;
object = [[MyClass alloc] init];
/* Check for aliasing between instance variable and global
variable. */
if ([object getGlobal] != 1) {
abort();
}
if ([object getInstance] != 2) {
abort();
}
/* Check whether the local variable hides the instance variable. */
if ([object getHidden] != 3) {
abort();
}
return 0;
}
|