struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3461.c
blob9172c8bc4aa5d67064c562c90e3de51d57de9946
1 /* bug-3459.c
2 Multiple codegen issues related to bit-fields and pointers to pointers to structs containing them.
3 */
5 #include <testfwk.h>
7 /// Test derived from code by SF user "Under4Mhz" in 2022.
9 // GPL Version 2.0
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <stdio.h>
14 typedef struct { unsigned char x; unsigned char y; } maths_point_u8;
15 typedef struct { int x; int y; } maths_point;
17 typedef struct {
19 maths_point_u8 position;
20 unsigned char direction : 4;
21 unsigned char type : 4;
23 } ObjectData;
25 typedef struct {
27 const ObjectData *objects;
28 unsigned int objectCount;
29 const char * const *map;
30 const ObjectData *start;
32 } LevelData;
34 const ObjectData level1Start = { .direction = 1, .type = 1, .position = { 34, 57 } };
36 const LevelData level1Data = { .objects = 0, .objectCount = 37, .map = 0, .start = &level1Start };
38 const LevelData *levelData = &level1Data;
40 void MapStart( maths_point *position, unsigned char *direction ) {
42 position->x = levelData->start->position.x + 1;
43 position->y = levelData->start->position.y;
44 *direction = levelData->start->direction; // The write to *direction was generated as if it was a write to a bit-field.
47 void testBug( void ) {
48 maths_point p;
49 unsigned char direction;
51 MapStart( &p, &direction );
53 ASSERT (direction == 1);