From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1147 invoked by alias); 22 Nov 2012 00:33:16 -0000 Received: (qmail 1036 invoked by uid 48); 22 Nov 2012 00:33:01 -0000 From: "t56xjcu6dh at snkmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55434] New: const array with elements initialized by constructor marked non-const in debug info Date: Thu, 22 Nov 2012 00:33:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: t56xjcu6dh at snkmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02102.txt.bz2 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. */