This is a straight forward 4.7 -> 4.6 backport for PR44643 http://gcc.gnu.org/ml/gcc-patches/2011-04/msg00544.html http://gcc.gnu.org/viewcvs?view=revision&revision=172415
Johann PR target/44643 * config/avr/avr.c (avr_insert_attributes): Leave TREE_READONLY alone. Error if non-const data has attribute progmem.
Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (Revision 174269) +++ config/avr/avr.c (Arbeitskopie) @@ -4995,14 +4995,20 @@ avr_insert_attributes (tree node, tree * && (TREE_STATIC (node) || DECL_EXTERNAL (node)) && avr_progmem_p (node, *attributes)) { - static const char dsec[] = ".progmem.data"; - *attributes = tree_cons (get_identifier ("section"), - build_tree_list (NULL, build_string (strlen (dsec), dsec)), - *attributes); + if (TREE_READONLY (node)) + { + static const char dsec[] = ".progmem.data"; - /* ??? This seems sketchy. Why can't the user declare the - thing const in the first place? */ - TREE_READONLY (node) = 1; + *attributes = tree_cons (get_identifier ("section"), + build_tree_list (NULL, build_string (strlen (dsec), dsec)), + *attributes); + } + else + { + error ("variable %q+D must be const in order to be put into" + " read-only section by means of %<__attribute__((progmem))%>", + node); + } } }