cpu/avr*: Fix compilation with GCC 12.2.0 #18532
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
A statement like
LKPR = (1 << CLKPCE);
which for the ATmega328P translates to*((volatile uint8_t *)0x61) = (1 << 7);
is considered as accessing the first array element of a zero sized array by GCC 12.2.0. Assuming a zero size for memory not allocated by the compiler is quite insane, so we need to disable the diagnostics for the affected code. The most targeted approach would be using:But adding this around every memory mapped I/O access would render the code unreadable. Adding this around the
#include <avr/io.h>
instead would be ideal, but since e.g.LKPR
is macro, the diagnostic would be still triggered when that macro is used in RIOT's C code.Instead, we add
-Wno-array-bounds
to theCFLAGS
, but only for the low level AVR/ATmega/ATXmega code. As a result common code can still profit from the diagnostics, while code working with memory mapped I/O can still use the AVR libc.Finally, the common LED initialization code needed suppression of bogus
-Warray-bounds
warnings.Testing procedure
Compilation should now work with AVR GCC version 12.2.0 and still work for older versions as before. The latter is checked by Murdock, the former check I can provide:
Using
master
Using this PR
Issues/PRs references
None