Trying to use the UB sanitizer for AVR target gives:
avr-gcc -Wall -mmcu=attiny1614 -fsanitize=undefined bm02.c
/usr/local/lib/gcc/avr/10.0.0/../../../../avr/bin/ld: cannot find
-lubsan collect2: error: ld returned 1 exit status
Can one build the avr-gcc with UBsan support?
No.
Currently, avr-g++ has no full C++ support, and for such targets, the toplevel configure.ac switches off libsanitizer. This is because libsanitizer is written in C++, cf. ubsan sources.