[avr] Fix PR80462

Submitted by Georg-Johann Lay on April 19, 2017, 10:43 a.m.

Details

Message ID 33edbd36-e09f-63d4-7b5f-1eb149c17a78@gjlay.de
State New
Headers show

Commit Message

Georg-Johann Lay April 19, 2017, 10:43 a.m.
This PR is about an incorrect warning for variables in progmem
without initializer.  If the variable is just an alias like in
and with -fmerge-all-constants

const __flash char string1[] = "same string";
const __flash char string2[] = "same string";

this will result in an incorrect

warning: uninitialized variable 'string2' put into program memory area 
[-Wuninitialized]

Hence, this patch tests whether the decl is just an alias.

Ok to apply?

Johann

	PR target/80462
	* config/avr/avr.c (tree.h): Include it.
	(cgraph.h): Include it.
	(avr_encode_section_info): Don't warn for uninitialized progmem
	variable if it's just an alias.

Comments

Denis Chertykov April 19, 2017, 11:46 a.m.
2017-04-19 14:43 GMT+04:00 Georg-Johann Lay <avr@gjlay.de>:
> This PR is about an incorrect warning for variables in progmem
> without initializer.  If the variable is just an alias like in
> and with -fmerge-all-constants
>
> const __flash char string1[] = "same string";
> const __flash char string2[] = "same string";
>
> this will result in an incorrect
>
> warning: uninitialized variable 'string2' put into program memory area
> [-Wuninitialized]
>
> Hence, this patch tests whether the decl is just an alias.
>
> Ok to apply?
>
> Johann
>
>         PR target/80462
>         * config/avr/avr.c (tree.h): Include it.
>         (cgraph.h): Include it.
>         (avr_encode_section_info): Don't warn for uninitialized progmem
>         variable if it's just an alias.
>


Please apply.

Patch hide | download patch | download mbox

Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 246966)
+++ config/avr/avr.c	(working copy)
@@ -25,6 +25,8 @@ 
 #include "backend.h"
 #include "target.h"
 #include "rtl.h"
+#include "tree.h"
+#include "cgraph.h"
 #include "c-family/c-common.h"
 #include "cfghooks.h"
 #include "df.h"
@@ -10127,9 +10129,14 @@  avr_encode_section_info (tree decl, rtx
       && !DECL_EXTERNAL (decl)
       && avr_progmem_p (decl, DECL_ATTRIBUTES (decl)))
     {
-      warning (OPT_Wuninitialized,
-               "uninitialized variable %q+D put into "
-               "program memory area", decl);
+      // Don't warn for (implicit) aliases like in PR80462.
+      tree asmname = DECL_ASSEMBLER_NAME (decl);
+      varpool_node *node = varpool_node::get_for_asmname (asmname);
+      bool alias_p = node && node->alias;
+
+      if (!alias_p)
+        warning (OPT_Wuninitialized, "uninitialized variable %q+D put into "
+                 "program memory area", decl);
     }
 
   default_encode_section_info (decl, rtl, new_decl_p);