I've run into an issue in a simple project which I just can't solve. It's really strange and I suspected a compiler bug but 99.9% a developer suspects that, the problem is actually in front of the computer... hopefully that's the case here as well.
The hardware setup looks like this: I've got an ATtiny45 on a breadboard, connected VSS, GND, MOSI, MISO, RST and SCK to a programmer. Pin 2 (PB3) is connected to 24 NeoPixels (WS2812).
Now I've got a little program to output a Knight-Rider-like effect on the NeoPixels and it works... if I use a stack-local array. Once I turn the 12-byte array into a global variable, the program doesn't work any more. By this I mean it usually doesn't even execute the "clear all pixels" of the setup() call, but only if I write to the array somewhere! Simply reading from the array works, but even a simple "kitt = 0;" suffices to make the program not work any more.
So as soon as write access to the global array is made in loop(), the program doesn't work any more.
You can see the arrays in lines 44 and 49.
I tried this using Arduino 1.8.2 on Mac with ATtiny support (GCC 4.9.2) and with Arduino 1.8.2 using GCC 4.8.1 from Arduino 1.6.9 since I suspected it to be a compiler/linker issue. Same behaviour. Also using PlatformIO using GCC 4.9.2.
When building with the stack-local array Arduino says that global variables use 44 bytes and 212 bytes remain for local variables. When using the global array, the numbers are 56 bytes and 212 bytes, like you'd expect.
So, what's going on here? I this really already a stack/heap collision? Any more ideas to investigate/fix this?