4.9 series reproducibly corrupts register R7

Bug #1527413 reported by David Smoot
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Confirmed
Undecided
Unassigned

Bug Description

Host OS is windows 8.1 64 bit. Toolchains were all prebuilt
Target processor is an Arm Cortex M0, specifically a Nordic Semiconductor NRF51422_xxAC.
Language is C.
Bug is reproducible on all three of the 2015 4.9.3 series. Does not occur on 4.8 2014q3.

Here is a minimal test case the demonstrates the issue:

Begin cut and paste of "r7lost.c"
//This is a minimal test case to demonstrate a believed bug.
//Host platform is Windows 8.1 x64.
//Target is a Cortex M0.
//tested with 4 different toolchains, all binary downloads from GCC ARM Launchpad site.
//Code below does not exhibit problem when compiled with 4.8 2014q3
//Code trashes register R7 with 4.9 2015q1, q2, or q3 and the flagged braces are uncommented.
//Commenting out the flagged braces removes the problem with the 4.9 series.
//Compile with arm-none-eabi-gcc -fverbose-asm -Wa,-adhln=r7lost.listing -mcpu=cortex-m0 -mthumb -mabi=aapcs --std=gnu99 -O1 -c r7lost.c

#include <inttypes.h>
#include <string.h>

#define RING_SIZE 64
int16_t readingBuffer[RING_SIZE];
uint8_t readingGetIndex;

extern _Bool TryEstimate(uint16_t * result);

inline uint8_t incrementRingIndex(uint8_t old)
{
 ++old;
 if (old >= RING_SIZE) old = 0;
 return old;
}

void process()
{
 const uint32_t data_size = 3;
 //if braces uncommented, bug is triggered.
 {
  uint8_t flash_buffer[data_size];
  memcpy(flash_buffer + 1, (void *) &readingBuffer[0], 2);

  uint16_t n;
  if (TryEstimate(&n))
  {
   memcpy(flash_buffer, (void *) &n, 2);
  }
 }
 readingGetIndex = incrementRingIndex(readingGetIndex);
}
End cut and paste of "r7lost.c"

On my system, I see the following results:
If the flagged braces are commented out, the register assignments are such that R7 is not used for any of the 4 compilers mentioned.

If the flagged braces are present, the 4.8 series compiler correctly preserves R7 but none of the three 4.9 series versions do.

Thanks for your attention, let me know if I need to provide more info.

Revision history for this message
David Smoot (davidsmoot) wrote :
Revision history for this message
Andre Vieira (andre-simoesdiasvieira) wrote :

Hi David,

Thank you for reporting this. I can confirm this occurs on 4.9 q3 release. I checked with the 5.0 q4 release and the bug doesn't seem to be present there. At least not with the code you provided even when using '-fno-omit-frame-pointer'. If possible I suggest you use that release.

I will try to look into why this code was generated for 4.9.

Cheers,
Andre

Changed in gcc-arm-embedded:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.