Cannot do two simultaneous analogWrite unless I insert garbage

I have an Arduino MEGA 2560 and a red LED connected to pin 4.

#define RED 4
#define GREEN 2

void setup() {
  analogWrite(GREEN,  0);
  analogWrite(RED,  100);
}

void loop() {

}

This code lights up the red LED.

However, when I write 1 to the GREEN pin "analogWrite(GREEN, 1)", the red LED goes off. I'm expecting the red LED to stay on.

#define RED 4
#define GREEN 2

void setup() {
  analogWrite(GREEN,  1);
  analogWrite(RED,  100);
}

void loop() {

}

The red LED stays on when both written values are the same, e.g.

analogWrite(GREEN,  25);
  analogWrite(RED,  25);

I also found that adding some "garbage" code at the beginning fixes the issue. I wasn't able to get the garbage into a simpler form without both pins shutting off. (see third attached picture)

#define RED 4
#define GREEN 2

void setup() {
  // GARBAGE BEGIN ===
  unsigned long t = millis();
  const unsigned long period = 10;
  float progress = float(t % period)/period;
  float r = progress * 0;
  // GARBAGE END ===

  analogWrite(GREEN,  100 + r);
  analogWrite(RED,  50 + r);
}

void loop() {

}

I also posted about the issue here: arduino ide - MEGA 2560: Simple program - One analogWrite turns off the other - Arduino Stack Exchange for

When I run this on my Mega the red LED is ON

#define RED 4
#define GREEN 2

void setup() {
  // GARBAGE BEGIN ===
  //~ unsigned long t = millis();
  //~ const unsigned long period = 10;
  //~ float progress = float(t % period)/period;
  //~ float r = progress * 0;
  // GARBAGE END ===

  analogWrite(GREEN,  1);
  analogWrite(RED,  100);
}

void loop() {

}

How have you got the LEDs connected to the Mega - make a simple pencil drawing and post a photo of it. See this Simple Image Posting Guide

...R

Thanks Robin2. This has been diagnosed as a compiler bug on Windows. Let me update my post here to insert the pictures correctly.

More details here:

markisus:
This has been diagnosed as a compiler bug on Windows.

Interesting.

I use Linux.

...R

Is this the same bug? It's core related and not Windows.

Yeah it looks like the behavior I'm seeing.