This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, AVR]: Hack around PR34734


PR34734 is an annoying, false C++ warning for code like

const int x __attribute__((progmem)) = 1;

progmem.c:1:30: warning: only initialized variables can be placed into
program memory area [enabled by default]

The problem is that DECL_INITIAL is NULL at the specific point in
space and time (avr_handle_progmem_attribute) even though tree.def
promises otherwise.

The patch hacks around by explicitly querying for C++ front end.

Johann

--

	PR target/34734
	* config/avr/avr.c (avr_handle_progmem_attribute): Hack around
	non-present DECL_INITIAL if front end is C++.
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(Revision 175036)
+++ config/avr/avr.c	(Arbeitskopie)
@@ -5099,7 +5099,15 @@ avr_handle_progmem_attribute (tree *node
 	}
       else if (TREE_STATIC (*node) || DECL_EXTERNAL (*node))
 	{
-	  if (DECL_INITIAL (*node) == NULL_TREE && !DECL_EXTERNAL (*node))
+	  if (DECL_INITIAL (*node) == NULL_TREE && !DECL_EXTERNAL (*node)
+              /* FIXME: Despite documentation in tree.def,
+                 DECL_INITIAL is NULL if an initializer is
+                 present in C++.  This is presumably due to
+                 different parsers for C resp. C++.
+                 We hack around that annoying warning (PR34734)
+                 by quering for the front end and emit a warning
+                 just for non-C++.  */
+              && NULL == strcasestr (lang_hooks.name, "c++"))
 	    {
 	      warning (0, "only initialized variables can be placed into "
 		       "program memory area");

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]