Open
Description
When compiling the Blink example from the Arduino IDE for AVR using Clang with LTO enabled, the program fails to function correctly. The LED blinks once and then remains stuck in the ON position indefinitely. Disabling LTO for wiring.c
from Arduino AVR core resolves the issue.
LLVM version: 20.1.0-rc2
Blink example code:
#include <Arduino.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Compiler flags used (other than -flto -fno-fat-lto-objects):
--target=avr -c -g -Os -Wall -Wextra --sysroot=/home/dakkshesh/.arduino15/packages/ClangBuiltArduino/tools/cba-avr-sysroot/12022025 -std=gnu11 -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L
Expected Behavior
The LED should continue blinking at a 1-second interval indefinitely.
Attachments
LLVM IR files for wiring.c with LTO turned on and off.
wiring.c-lto.ll.txt
wiring.c-nonlto.ll.txt