public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch,avr] PR81407: Error if progmem variable needs constructing.
@ 2017-07-12  8:45 Georg-Johann Lay
  2017-07-12 11:02 ` Denis Chertykov
  0 siblings, 1 reply; 2+ messages in thread
From: Georg-Johann Lay @ 2017-07-12  8:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

Hi, if the C++ front-end decides that something will need constructing,
it will silently put the stuff into .rodata so that according
pgm_read_xxx will read garbage from .progmem.

As proposed by Jason, this patch diagnoses such situations.

Ok to commit?

Johann

	PR target/81407
	* config/avr/avr.c (avr_encode_section_info)
	[progmem && !TREE_READONLY]: Error if progmem object needs
	constructing.

[-- Attachment #2: pr81407-progmem-construct.diff --]
[-- Type: text/x-patch, Size: 1254 bytes --]

Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 250093)
+++ config/avr/avr.c	(working copy)
@@ -10380,14 +10380,22 @@ avr_encode_section_info (tree decl, rtx
       && !DECL_EXTERNAL (decl)
       && avr_progmem_p (decl, DECL_ATTRIBUTES (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);
+      if (!TREE_READONLY (decl))
+        {
+          // This might happen with C++ if stuff needs constructing.
+          error ("variable %q+D with dynamic initialization put "
+                 "into program memory area", decl);
+        }
+      else if (!alias_p)
+        {
+          // Don't warn for (implicit) aliases like in PR80462.
+          warning (OPT_Wuninitialized, "uninitialized variable %q+D put "
+                   "into program memory area", decl);
+        }
     }
 
   default_encode_section_info (decl, rtl, new_decl_p);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch,avr] PR81407: Error if progmem variable needs constructing.
  2017-07-12  8:45 [patch,avr] PR81407: Error if progmem variable needs constructing Georg-Johann Lay
@ 2017-07-12 11:02 ` Denis Chertykov
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Chertykov @ 2017-07-12 11:02 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-patches

2017-07-12 12:45 GMT+04:00 Georg-Johann Lay <avr@gjlay.de>:
> Hi, if the C++ front-end decides that something will need constructing,
> it will silently put the stuff into .rodata so that according
> pgm_read_xxx will read garbage from .progmem.
>
> As proposed by Jason, this patch diagnoses such situations.
>
> Ok to commit?
>
> Johann
>
>         PR target/81407
>         * config/avr/avr.c (avr_encode_section_info)
>         [progmem && !TREE_READONLY]: Error if progmem object needs
>         constructing.

Approved.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-12 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-12  8:45 [patch,avr] PR81407: Error if progmem variable needs constructing Georg-Johann Lay
2017-07-12 11:02 ` Denis Chertykov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).