#1529 Incorrect assignment in array of structs

closed-fixed
Borut Ražem
5
2013-05-25
2009-04-07
Frank Cornett
No

Code:
#include "dp8051.h" //Define 8051 ports

typedef struct{
unsigned char Fail;
unsigned char Route;
unsigned char xor;
unsigned char RX_invert;
} DT_SERDES_PORT;

__xdata DT_SERDES_PORT doors[3];

void main(void){

unsigned char door;

for (door = 0x01; door <= 0x02; door++){ doors[door].Route = 0x24; }
for (door = 0x01; door <= 0x02; door++){
P2 = 0xAA;//Set 8051 ports to trigger display in Verilog
P1 = doors[door].Route;
P0 = door;
}
P3 = 0xA5;//Trigger simulation finish
}

This code is compiled and executed with a Verilog simulation of an 8051 processor. The output is:
P0, P1, P2 = 01, 24, aa
P0, P1, P2 = 02, 00, aa
Note that the second element in the doors array is not assigned correctly. This behavior appears to be associated with loop reversal, since setting the compiler option --noloopreverse results in the following output:
P0, P1, P2 = 01, 24, aa
P0, P1, P2 = 02, 24, aa
I've also observed that if the two for loops are combined into a single loop, the correct assignment occurs.
Please refer to the attached tarball for more details.

Thanks,
Frank Cornett
Cray Inc.

Discussion

  • Frank Cornett
    Frank Cornett
    2009-04-07

    Tarball with compiler output, simulation output, SDCC version, etc.

     
    Attachments
  • wek
    wek
    2009-06-07

    Robert,

    once you are in it, please check out and fix also the inadequate tests for case INC_OP: and case DEC_OP: just a few lines below the case for PTR_OP you have just patched.

    The regression test function could include perhaps the following function:
    void bar(void) {
    char i;
    for (i = 1; i <= 2; i++)
    doors[i].Route++;
    }

    Jan Waclawek

     
  • Robert Larice
    Robert Larice
    2009-06-08

    Jan,
    thank you for your vigilance, I've extended the patch

    Robert Larice

     
  • Borut Ražem
    Borut Ražem
    2009-07-18

    • milestone: 100454 --> fixed
    • assigned_to: nobody --> borutr
    • status: open --> closed-fixed