struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3523.c
blob78e0d09020809085f13002c84d45cff9b690ee4a
1 /* bug-3523.c
2 Variables on the stack were incorrectly allocated overlapping.
3 */
5 #include <testfwk.h>
7 #pragma disable_warning 85
9 // Based on code by "Under4Mhz" licensed under GPL 2.0 or later
11 #include <stdint.h>
12 #include <stdbool.h>
14 typedef struct {
16 int x;
17 int y;
19 } maths_point;
21 void PlayerGridNextGet( maths_point *next ) {
23 next->x = 1;
24 next->y = 2;
27 void PlayerGridGet( maths_point *current ) {
29 current->x = 3;
30 current->y = 4;
33 int MapGet( int x, int y ) { return 0; }
35 int StateDoorHiddenOpenSet( int x, int y ) { ASSERT (x == 1); ASSERT (y == 2);} // Bug visible via x == 3 && y == 4 here.
37 bool ObjectIsHiddenDoor( char ch ) { return true; }
39 void SoundDoorOpen() {} // Weirdly, this empty function definition is necesssary to trigger the bug.
41 void Action() {
43 maths_point next;
44 PlayerGridNextGet( &next );
45 char ch = MapGet( next.x, next.y );
47 maths_point current;
48 PlayerGridGet( &current );
49 char chCurrent = MapGet( current.x, current.y );
51 // Hidden door open
52 StateDoorHiddenOpenSet( next.x, next.y );
55 void
56 testBug (void) {
57 Action();