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

* [Bug c++/55434] const array with elements initialized by constructor marked non-const in debug info
  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 ` t56xjcu6dh at snkmail dot com
  2012-11-22  0:41 ` t56xjcu6dh at snkmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: t56xjcu6dh at snkmail dot com @ 2012-11-22  0:37 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Louis Krupp <t56xjcu6dh at snkmail dot com> 2012-11-22 00:37:04 UTC ---
Created attachment 28759
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28759
Proposed patch

I wouldn't describe this as elegant, but it seems to work.


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

* [Bug c++/55434] const array with elements initialized by constructor marked non-const in debug info
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: t56xjcu6dh at snkmail dot com @ 2012-11-22  0:41 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Louis Krupp <t56xjcu6dh at snkmail dot com> 2012-11-22 00:40:49 UTC ---
g++ -v output from a version known to have this problem:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --disable-build-with-cxx
--disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC)


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

* [Bug c++/55434] const array with elements initialized by constructor marked non-const in debug info
  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
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-22  9:57 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-22 09:57:02 UTC ---
Note that in any case patches should be posted to gcc-patches.


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

* [Bug c++/55434] const array with elements initialized by constructor marked non-const in debug info
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-07 22:28 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-08-07
     Ever confirmed|0                           |1


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

* [Bug c++/55434] const array with elements initialized by constructor marked non-const in debug info
  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
                   ` (3 preceding siblings ...)
  2013-08-07 22:28 ` paolo.carlini at oracle dot com
@ 2013-08-07 23:57 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-07 23:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
With C++11 constexpr things are fine. I think this is an indication that before
fiddling with dwarf2out we should make sure const is handled like constexpr, in
C++98 mode too, for this testcase, thus ca2 is "r". ICC, for example, does
that.


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