cpu/avr*: Fix compilation with GCC 12.2.0#18532
Closed
maribu wants to merge 1 commit intoRIOT-OS:masterfrom
Closed
cpu/avr*: Fix compilation with GCC 12.2.0#18532maribu wants to merge 1 commit intoRIOT-OS:masterfrom
maribu wants to merge 1 commit intoRIOT-OS:masterfrom
Conversation
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: ``` #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" ... #pragma GCC diagnostic pop ``` 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 the `CFLAGS`, 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.
Member
Author
|
Closing in favor of #18533 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.LKPRis macro, the diagnostic would be still triggered when that macro is used in RIOT's C code.Instead, we add
-Wno-array-boundsto 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-boundswarnings.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
masterUsing this PR
Issues/PRs references
None