arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.24k stars 1.05k forks source link

unable to find a register to spill in class 'POINTER_REGS' #158

Closed danlu01 closed 5 years ago

danlu01 commented 9 years ago

I upgraded from Arduino IDE 1.0.6 to 1.6.5 and now my sketch have compile error:

unable to find a register to spill in class 'POINTER_REGS'

I've narrow it down to a function (I've modified it to try to understand the compile error). Odd thing is if I remove any of the 4 line of code in the for loop, then it compiles ok. Here's the test sketch with this issue:

float dhistory[10];
float test;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

  test = getSlope(dhistory);
}

float getSlope(float history[]) {
  float sumx = 0;
  float sumy = 0;
  float sumxy = 0;
  float sumxsq = 0;
  float rate = 0;
  int n = 10;

  for (int i=1; i< 11; i++) {
    sumx = sumx + i;
    sumy = sumy + history[i-1];
    sumy = sumy + history[i-1];
    sumxsq = sumxsq + (i*i);
  } 

  rate = sumy+sumx+sumxsq;
  return rate;
}
NicoHood commented 9 years ago

Please put your code into "```" brackets so it can be read better. The simple solution to this is: Just DONT us floats on AVR. It just makes no sense at all. also it is important to know what board you used.

danlu01 commented 9 years ago

I'm compiling for Mega2560 but get same error if compile for UNO as well. To me it's a compiler optimization error with pointers.

facchinm commented 9 years ago

Yep, it's a gcc bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60040). If you feel brave you could test if gcc 5.1.0 solves it following these instructions (https://github.com/arduino/Arduino/issues/660#issuecomment-120433193)

matthijskooijman commented 9 years ago

I just tried 5.1, still broken. I've reduced this testcase to work outside of Arduino and added it to the gcc bug report.

@danlu01, it seems that enabling O2 (more optimizations) prevents this issue from occurring with your code. As a workaround, you could add this near the top of your sketch, to compile just that one function with O2 optimizations:

float getSlope(float history[]) __attribute__((__optimize__("O2")));

(just tried, works for me)

danlu01 commented 9 years ago

Thanks for the workaround.. run into another compiler bug. I'll create another ticket.

dgholstein commented 8 years ago

All;

I have the same problem and it doesn't involve floats (though I use floats elsewhere).

As I uncomment more of my class, the constructor, _AD_Synth::AD_Synth(ThreeWire& comport), I get the "register to spill" message. I tried the attribute workaround with no success.

BTW: When I wrote it all as C-based (not a class) code, the large struct worked just peachy, with essentially the same function as the method.

Sorry about the length of the code and especially the attributes -- but the ADF4351 synthesizer is a complicated device.

Regards, Dan synth.ino.txt AD_synth.cpp.txt AD_Synth.h.txt ThreeWire.cpp.txt ThreeWire.h.txt

islamelhadi commented 8 years ago

I was having the same issue and I simply resolved it. All what I did is downloading the LAST UPDATE (4 October 2016 14:52:59 GMT) for Arduino software in the software download page (Arduino software hourly builds) at the bottom left of the page. The sketch was successfully compiled. HOPE this helps ! https://www.arduino.cc/en/Main/Software untitled

njh commented 8 years ago

I just tried an hourly build "21 October 2016 16:13:52 GMT" - which came with 'avr-gcc (GCC) 4.9.2' but it didn't solve the problem for me.

error: unable to find a register to spill in class 'POINTER_REGS'
vitasam commented 8 years ago

Looks like I just got the same problem with Arduino 1.6.11 This line compiles Ok in multiple places of sketch: sprintf(msg_payload, "%s is ON", module_config.client_name);

but in one place of the sketch this line: sprintf(msg_payload, "%s connected", module_config.client_name); returns an error:

...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.14\cores\arduino\main.cpp:51:1: error: unable to find a register to spill in class 'NO_REGS'
...
        (subreg:QI (reg/f:HI 458) 1)) ...\GITprojects\Sourceforge\home-controller-code\Arduino\AERCM\AERCM.ino:185 1 {pushqi1}

     (expr_list:REG_ARGS_SIZE (const_int 1 [0x1])

        (nil)))

With just one parameter a compilation is Ok: sprintf(msg_payload, "%s", module_config.client_name);

matthijskooijman commented 8 years ago

According to the GCC bug, this will be fixed in GCC 7.0. They might backport the fix to earlier versions, if so I think it should be mentioned in the bug report as well. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60040

ZeusDataBinder commented 6 years ago

Hello All, I am still getting the PONITER_REGS error in the UNO board. I am using 1.8.5 IDE!

reivaxy commented 6 years ago

So am I. Used to work, I don't remember what was the IDE version (had to reinstall everything after hdd crash)

facchinm commented 5 years ago

Looks like it's fixed by avr core version 1.8.1 (using toolchain 7.4.0)