From ddab16007a23c0b489ac63b9d25dac67d5390229 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 11 Dec 2022 12:08:30 +0100 Subject: [PATCH] run branch fixer again after replacing BRA by JMP. should fix #1936 --- src/cc65/codeopt.c | 4 ++ test/misc/bug1936.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 test/misc/bug1936.c diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 440b10751..208ada134 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -850,6 +850,10 @@ static unsigned RunOptGroup7 (CodeSeg* S) C += RunOptFunc (S, &DOptJumpCascades, 1); C += RunOptFunc (S, &DOptBranchDist2, 1); + /* Adjust branch distances again, since the previous step may change code + between branches */ + C += RunOptFunc (S, &DOptBranchDist, 3); + Changes += C; /* If we had changes, we must run dead code elimination again, ** since the changes may have introduced dead code. diff --git a/test/misc/bug1936.c b/test/misc/bug1936.c new file mode 100644 index 000000000..788313bd2 --- /dev/null +++ b/test/misc/bug1936.c @@ -0,0 +1,93 @@ + +/* bug #1936 - Compiler produces broken Assembly (129 operand for bne) */ + +#include + +static uint8_t item_counter; + + +static uint8_t freeze; +static uint8_t powerUp; + +static uint8_t wall_appeared; +static uint8_t freeze_locked; +static uint8_t zombie_locked; + + +struct ItemStruct +{ + uint8_t _active; + void(*_effect)(void); +} ; +typedef struct ItemStruct Item; + +static Item freezeItem; +static Item powerUpItem; +static Item wallItem; +static Item zombieItem; + + +static Item extraPointsItem[1]; + + +uint8_t find_inactive(Item* itemArray) +{ +} + + +void drop_item(register Item *item, uint8_t max_counter) +{ +} + + +void handle_item_drop(void) +{ + { + if(item_counter==1) + { + if(!powerUpItem._active) + { + drop_item(&powerUpItem,35); + } + } + else if((!freeze_locked)&&(!freeze)) + { + if(!freezeItem._active) + { + drop_item(&freezeItem,45); + } + } + else if(!wall_appeared&&(powerUp>=9)) + { + if(!wallItem._active) + { + drop_item(&wallItem,35); + } + } + else if(!zombie_locked && !zombieItem._active) + { + drop_item(&zombieItem,50); + } + else + { + uint8_t index; + + index = find_inactive(extraPointsItem); + if(index!=1) // REMARK: compilation does not fail with 0 + { + drop_item(&extraPointsItem[index],90); + } + } + } +} + +int main(void) +{ + + while(1) // Game (re-)start + { + } + + return 0; +} +