aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/objc-gc-1.mm
blob: fc63e54b2eb295d8ec4071ee1dc4031f892f5670 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* APPLE LOCAL file ObjC GC */
/* A compile-only test for insertion of write barriers. */
/* Developed by Ziemowit Laski  <zlaski@apple.com>  */
/* { dg-do compile { target *-*-darwin* } } */
/* { dg-options "-fnext-runtime -fobjc-gc -Wassign-intercept" } */

#ifndef __OBJC_GC__
#error Missing __OBJC_GC__ manifest constant
#endif

#include <objc/Object.h>

@class Underspecified;
@class MyClass;

@interface AnotherClass: Object {
@public
  __strong void *storage;
  MyClass *SomeObj;
}
- (id)assignObj:(id)obj;
@end

struct Struct1 {
  MyClass *someobj;
  void *obj2;
  __strong void *obj3;
};

struct Struct1 *str1a, str1aa;
__strong struct Struct1 *str1b, str1bb, **str1c, *str1d[3][3];

extern MyClass *externFunc(void);

@interface MyClass: Object {
@public
  id ivar1, *ivar1a;
  void *ivar2;
  __strong void *ivar3;
  Underspecified *ivar4[2], **ivar4a;
  union {
    struct {
      Underspecified *data;
      const unsigned char *dataBytes;
    } d;
    struct {
      __strong void *storage;
      AnotherClass *another;
    } s;
  } contents;
  struct {
    struct {
      void *yy;
    } z;
  } y;
}
@end

@implementation AnotherClass
- (id)assignObj:(id)obj {
  static MyClass *m_myclass;
  static id *indirect;
  str1a = 0;
  str1b = 0; /* { dg-warning "global\\/static variable assignment" } */
  str1c = 0; /* { dg-warning "global\\/static variable assignment" } */
  str1d[1][1] = 0; /* { dg-warning "global\\/static variable assignment" } */
  str1a->someobj = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
  str1b->someobj = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
  str1aa.someobj = 0; /* { dg-warning "global\\/static variable assignment" } */
  str1bb.someobj = 0; /* { dg-warning "global\\/static variable assignment" } */
  str1a->obj2 = 0;
  str1b->obj2 = 0;
  str1a->obj3 = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
  str1b->obj3 = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
  SomeObj->contents.s.another = 0; /* { dg-warning "instance variable assignment" } */
  obj = 0;
  externFunc()->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
  externFunc()->contents.s.another->SomeObj = 0; /* { dg-warning "instance variable assignment" } */
  m_myclass = 0; /* { dg-warning "global\\/static variable assignment" } */
  *indirect = obj; /* { dg-warning "strong\\-cast may possibly be needed" } */
  (__strong id)*indirect = obj; /* { dg-warning "strong\\-cast assignment" } */
  self = 0;
  self->isa = 0; /* { dg-warning "instance variable assignment" } */
  return SomeObj = obj; /* { dg-warning "instance variable assignment" } */
}
@end

typedef MyClass MyClass1;
@compatibility_alias MyClass2 MyClass;

MyClass *g_myclass;
MyClass1 *g_myclass1;
MyClass2 *g_myclass2;
MyClass2 **g_myclass2a, ***g_myclass2b;
MyClass2 *g_myclass2c[6], *g_myclass2d[4][5];
__strong void *g_myclass2e[3];

id *g_myid, ***g_myid3;

void function(void) {
	static MyClass *l_myclass;
	MyClass2 *l_myclass2;
	
	g_myclass = 0; /* { dg-warning "global\\/static variable assignment" } */
	l_myclass = 0; /* { dg-warning "global\\/static variable assignment" } */
	g_myclass->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	*g_myclass->ivar1a = 0;
	l_myclass2 = 0;
	l_myclass2->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	(__strong id)*g_myclass->ivar1a = 0; /* { dg-warning "strong\\-cast assignment" } */
	g_myclass->ivar2 = 0;
	(__strong void *)g_myclass->ivar2 = 0; /* { dg-warning "strong\\-cast assignment" } */
	g_myclass->ivar3 = 0; /* { dg-warning "instance variable assignment" } */
	l_myclass->ivar4[1] = 0; /* { dg-warning "instance variable assignment" } */
        l_myclass->ivar4a = 0;
        *l_myclass->ivar4a = 0;
        (__strong id)*l_myclass->ivar4a = 0; /* { dg-warning "strong\\-cast assignment" } */
	l_myclass->contents.d.data = 0; /* { dg-warning "instance variable assignment" } */
	l_myclass->contents.d.dataBytes = 0;
	(__strong const unsigned char *)l_myclass->contents.d.dataBytes = 0; /* { dg-warning "strong\\-cast assignment" } */
	l_myclass->contents.s.storage = 0; /* { dg-warning "instance variable assignment" } */
	l_myclass->contents.s.another->SomeObj = 0; /* { dg-warning "instance variable assignment" } */
	l_myclass->contents.s.another->storage = 0; /* { dg-warning "instance variable assignment" } */
	(__strong void *)l_myclass->contents.s.another->storage = 0; /* { dg-warning "strong\\-cast assignment" } */
	g_myclass->y.z.yy = 0;
	(__strong void *)g_myclass->y.z.yy = 0; /* { dg-warning "strong\\-cast assignment" } */
	g_myclass1->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	g_myclass2->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
        (*g_myclass2a)->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	*g_myid = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
	***g_myid3 = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
	(__strong id)*g_myid = 0; /* { dg-warning "strong\\-cast assignment" } */
	(__strong id)***g_myid3 = 0; /* { dg-warning "strong\\-cast assignment" } */
	g_myclass2[3] = g_myclass1[4];
	g_myclass2a[1] = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
	g_myclass2b[1][2] = 0; /* { dg-warning "strong\\-cast may possibly be needed" } */
	g_myclass2c[1] = 0; /* { dg-warning "global\\/static variable assignment" } */
	g_myclass2e[1] = 0; /* { dg-warning "global\\/static variable assignment" } */
	g_myclass2d[1][2] = 0; /* { dg-warning "global\\/static variable assignment" } */
	g_myclass2a[1]->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	g_myclass2b[1][2]->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	g_myclass2c[1]->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
	g_myclass2d[1][2]->ivar1 = 0; /* { dg-warning "instance variable assignment" } */
}