diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index c193430cf07..3abe8da9aae 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -51,6 +51,7 @@ #include "expr.h" #include "langhooks.h" #include "cfgrtl.h" +#include "opts.h" #include "builtins.h" #include "context.h" #include "tree-pass.h" @@ -756,6 +757,14 @@ avr_option_override (void) flag_omit_frame_pointer = 0; } + struct gcc_options *opts = &global_options; + struct gcc_options *opts_set = &global_options_set; + + /* PR105523: AVR memory starts at address 0. Avoid warning + "array subscript [0] is outside array bounds of 'volatile uint8_t[0]'" + so that SFR accesses won't throw silly warnings. */ + SET_OPTION_IF_UNSET (opts, opts_set, param_min_pagesize, 0); + if (flag_pic == 1) warning (OPT_fpic, "%<-fpic%> is not supported"); if (flag_pic == 2) diff --git a/gcc/testsuite/gcc.target/avr/torture/pr105523.c b/gcc/testsuite/gcc.target/avr/torture/pr105523.c new file mode 100644 index 00000000000..d510ab66949 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/pr105523.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror=all" } */ + +typedef __UINT8_TYPE__ uint8_t; + +#define SFR (*(volatile uint8_t*) (__AVR_SFR_OFFSET__ + 1)) + +void func (void) +{ + SFR = 1; +}