public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55434] New: const array with elements initialized by constructor marked non-const in debug info
@ 2012-11-22  0:33 t56xjcu6dh at snkmail dot com
  2012-11-22  0:37 ` [Bug c++/55434] " t56xjcu6dh at snkmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: t56xjcu6dh at snkmail dot com @ 2012-11-22  0:33 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55434

             Bug #: 55434
           Summary: const array with elements initialized by constructor
                    marked non-const in debug info
    Classification: Unclassified
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: t56xjcu6dh@snkmail.com


Created attachment 28758
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28758
C++ source file

In this code:

struct s
{
    int i1, i2;
};

const s c1 = { 1, 2 };
const s ca1[] = { { 1, 2} };
const s c2 = c1;
const s ca2[] = { c1 };

int main(void)
{
    return 0;
}


gdb sees all variables as const except for ca2:

(gdb) ptype ca1
type = const struct s {
    int i1;
    int i2;
} [1]
(gdb) ptype ca2
type = struct s {
    int i1;
    int i2;
} [1]

The problem seems to be in split_nonconstant_init() in cp/typeck2.c;  when
TREE_READONLY (dest) is set to zero, the information that it was ever read-only
is lost before the DWARF record is written.

The following patch seems to fix the problem.  I would not be surprised if
there were a more elegant way of doing this.

(You might be wondering:  How did I find this, and why do I care?  I've been
working on something to read object files and then flag variables that raise
thread-safety issues because they are (1) global or static and (2) not const. 
Reading DWARF records works really well, except for this particular problem.)

Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c    (revision 193640)
+++ gcc/cp/typeck2.c    (working copy)
@@ -633,6 +633,7 @@
     init = NULL_TREE;
       code = pop_stmt_list (code);
       DECL_INITIAL (dest) = init;
+      TREE_WASREADONLY (dest) = TREE_READONLY (dest);
       TREE_READONLY (dest) = 0;
     }
   else
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c    (revision 193640)
+++ gcc/dwarf2out.c    (working copy)
@@ -18031,7 +18031,9 @@
       if (decl_by_reference_p (decl_or_origin))
     add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
       else
-    add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
+    add_type_attribute (var_die, type,
+                        TREE_READONLY (decl_or_origin) ||
+                        TREE_WASREADONLY (decl_or_origin),
                 TREE_THIS_VOLATILE (decl_or_origin), context_die);
     }

Index: gcc/tree.h
===================================================================
--- gcc/tree.h    (revision 193640)
+++ gcc/tree.h    (working copy)
@@ -464,8 +464,9 @@
   unsigned packed_flag : 1;
   unsigned user_align : 1;
   unsigned nameless_flag : 1;
+  unsigned wasreadonly_flag : 1;

-  unsigned spare : 12;
+  unsigned spare : 11;

   /* This field is only used with type nodes; the only reason it is present
      in tree_base instead of tree_type is to save space.  The size of the
@@ -1344,6 +1345,7 @@
    Nonzero in a FUNCTION_DECL means this function should be treated
    as "const" function (can only read its arguments).  */
 #define TREE_READONLY(NODE) (NON_TYPE_CHECK (NODE)->base.readonly_flag)
+#define TREE_WASREADONLY(NODE) (NON_TYPE_CHECK (NODE)->base.wasreadonly_flag)

 /* Value of expression is constant.  Always on in all ..._CST nodes.  May
    also appear in an expression or decl where the value is constant.  */


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

end of thread, other threads:[~2013-08-07 23:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22  0:33 [Bug c++/55434] New: const array with elements initialized by constructor marked non-const in debug info t56xjcu6dh at snkmail dot com
2012-11-22  0:37 ` [Bug c++/55434] " t56xjcu6dh at snkmail dot com
2012-11-22  0:41 ` t56xjcu6dh at snkmail dot com
2012-11-22  9:57 ` paolo.carlini at oracle dot com
2013-08-07 22:28 ` paolo.carlini at oracle dot com
2013-08-07 23:57 ` paolo.carlini at oracle dot com

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).