Possible bug with 4.8.2 / 4.8.1

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe it's bad C on my part, maybe it's a bug.

 

The following happens with 4.8.1 from ATMEL. 4.8.2 from MHV.  It does not happen with 4.3.x and does not happen with 4.9.2 from MobileChess.

 

The C code is

uint8_t newObject(uint8_t obType, uint8_t lane, uint8_t z){

uint8_t NewObjNum;
ObjectDescStruct *Current;
drawFunctionPointer_t firstActionFunction;

NewObjNum = getFreeObject();             // Get the next free object from the store.  returns MAX+1 if no objects left

if(NewObjNum != (MAX_OBJS+1)) {

     ObjectStore[NewObjNum].obType     = obType;                 // Copy values into object structure.
     ObjectStore[NewObjNum].laneHi     = lane;
     ObjectStore[NewObjNum].z          = z;
     ObjectStore[NewObjNum].r          = pgm_read_byte(&laneAngles[web].lane[lane]);
     ObjectStore[NewObjNum].animation  = 0;

     Current = (ObjectDescStruct*)&ObjectStore[NewObjNum];      // create a pointer to the object structure

     firstActionFunction = (drawFunctionPointer_t)pgm_read_word(&firstActionFunctionPointers[obType]);
     if(firstActionFunction != NULL) {
          firstActionFunction(Current);
     }

     moveXYCommon(Current);                                    // call moveXYCommon to make sure object is on screen
}                                                              // before first call to renderer
return(NewObjNum);
}

The non working ASM that 4.8.x makes does this

 

ObjectStore[NewObjNum].animation 	= 0;
    adiw     r26, 0x07	; 7
    st	     X, r1

Current = (ObjectDescStruct*)&ObjectStore[NewObjNum];

moveXYCommon(Current);
    movw	r24, r26
    call	0x9944	; 0x9944 <moveXYCommon>

The compiler has previously gotten the address of ObjectStore[NewObjNum] into R26

 

It then does some ADIW to it for loading the structure.

 

It then takes this trashed version of R26 and passes it to moveXYCommon().

 

In 4.9.2 it makes a copy of the address into R16 before trashing it then does

ObjectStore[NewObjNum].animation 	= 0;
    adiw	r26, 0x07	; 7
    st  	X, r1
Current = (ObjectDescStruct*)&ObjectStore[NewObjNum];

moveXYCommon(Current);
    movw	r24, r16
    call	0x9984	; 0x9984 <moveXYCommon>

I can also force 4.8.x to work by moving the pointer assigment above all the assigments loading the structure with data.

 

thankfully looks like it is fixed in 4.9.x but just a heads that might save someone else a few days hunting phantom bugs.
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...trashed version of R26...

Hmmm--that has a very  familiar ring...

https://www.avrfreaks.net/forum/a...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not the same bug though I guess.  I am not using memx at all and this bug is fixed already in 4.9.2

 

BTW - I have changed the code to be more orthodox looking

uint8_t newObject(uint8_t obType, uint8_t lane, uint8_t z){

uint8_t NewObjNum;
ObjectDescStruct *Current;
drawFunctionPointer_t firstActionFunction;

NewObjNum = getFreeObject();

if(NewObjNum != (MAX_OBJS+1)) {

	Current = (ObjectDescStruct*)&ObjectStore[NewObjNum];

	Current->obType  	= obType;
	Current->laneHi		= lane;
	Current->z			= z;
	Current->r 			= pgm_read_byte(&laneAngles[web].lane[lane]);
	Current->animation 	= 0;

	firstActionFunction = (drawFunctionPointer_t)pgm_read_word(&firstActionFunctionPointers[obType]);
	if(firstActionFunction != NULL) {
		firstActionFunction(Current);
	}

	moveXYCommon(Current);
}
return(NewObjNum);
}

and now no versions of the compiler screw up
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Reading through the bug list I think it might have been related to this one

 

https://gcc.gnu.org/bugzilla/sho...