struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug1928022.c
blob36a69b25c8e3b24835b3f3c5f6ce32597ded6230
1 /*
2 bug 1928022 & 1503239
3 */
5 // the following "C"
6 //
7 // struct st { char a[1]; };
8 // char __xdata * const Ptr = &(((struct st __xdata *) 0x1234) -> a[0]);
9 //
10 // will generate an .asm where a label for `Ptr' is generated,
11 // but no space is allocated, and no initialization is done.
13 // In this piece of regression test,
14 // the `Fill...' variables are used to work around
15 // the missing space allocation.
16 // The cmp() will then reliably bump into those Fill.. locations
18 #include <testfwk.h>
20 struct st_a {
21 char b;
22 char a[2];
23 struct { char c; } s;
26 char __xdata * const Ptr_a1 = &(((struct st_a __xdata *) 0x1234) -> a[0]);
27 char __xdata * const Ptr_a2 = &(((struct st_a __xdata *) 0x1234) -> a[1]);
28 long const Fill_a = -1;
30 char __xdata * const Ptr_c1 = &(((struct st_a __xdata *) 0x1234) -> s.c);
31 long const Fill_c = -1;
33 char
34 cmp (void *a, void *b)
36 return a == b;
39 void
40 testBug (void)
42 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // I have no idea yet, how integers cast to pointers should behave here on pdk14.
43 ASSERT (cmp(Ptr_a1, (char __xdata *) 0x1235));
44 ASSERT (cmp(Ptr_a2, (char __xdata *) 0x1236));
45 ASSERT (cmp(Ptr_c1, (char __xdata *) 0x1237));
46 #endif
49 // bug 1503239
50 struct st_a foo;
52 const char * __code bob = &foo.b; // validateLink failed
54 char * Ptr1 = &(foo.a[0]); // this works
55 char * Ptr2 = foo.a; // caused internal compiler error
57 char * __code Ptr3 = &(foo.a[0]);
58 char * __code Ptr4 = foo.a; // compile error 129: pointer types incompatible
60 char * const Ptr5 = &(foo.a[0]);
61 char * const Ptr6 = foo.a; // compile error 129: pointer types incompatible