1 // This is a reproducer for a crash during codegen. The base issue is when we
2 // Import the DeclContext we force FieldDecl that are RecordType to be defined
3 // since we need these to be defined in order to layout the class.
4 // This case involves an array member whose ElementType are records. In this
5 // case we need to check the ElementType of an ArrayType and if it is a record
6 // we need to import the definition.
7 struct A {
8 int x;
9 };
10
11 struct B {
12 // When we import the all the FieldDecl we need to check if we have an
13 // ArrayType and then check if the ElementType is a RecordDecl and if so
14 // import the definition. Otherwise during codegen we will attempt to layout A
15 // but won't be able to.
16 A s1[2];
17 A s2[2][2][3];
18 char o;
19 };
20
21 class FB {
22 public:
23 union {
24 struct {
25 unsigned char *_s;
26 } t;
27 char *tt[1];
28 } U;
29
FB(B * p)30 FB(B *p) : __private(p) {}
31
32 // We import A but we don't import the definition.
f(A ** bounds)33 void f(A **bounds) {}
34
35 void init();
36
37 private:
38 B *__private;
39 };
40
init()41 void FB::init() {
42 return; // break here
43 }
44
main()45 int main() {
46 B b;
47 FB fb(&b);
48
49 b.o = 'A';
50
51 fb.init();
52 }
53