Bug 31899 - [4.2 Regression] -g and using declaration causing ICE in reference_to_unused
Summary: [4.2 Regression] -g and using declaration causing ICE in reference_to_unused
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.2.0
: P1 major
Target Milestone: 4.2.3
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
: 33026 33580 33625 33668 35391 (view as bug list)
Depends on:
Blocks: 30700
  Show dependency treegraph
 
Reported: 2007-05-11 14:09 UTC by zak.kipling
Modified: 2008-02-27 13:23 UTC (History)
16 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64_pc_linux_gnu
Build: x86_64_pc_linux_gnu
Known to work: 4.3.0
Known to fail: 4.2.2
Last reconfirmed: 2007-10-02 17:12:15


Attachments
Proposed fix for SEGV problem in dwarf2out.c in bug 31899 (917 bytes, patch)
2007-07-27 20:54 UTC, Doug Kwan
Details | Diff
patch (677 bytes, patch)
2007-10-02 17:05 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zak.kipling 2007-05-11 14:09:18 UTC
The following code, compiled with -g, causes an ICE on 4.2.0 RC3 (20070501) and on my most recent 4.3.0 snapshot build (20070427):

---------------------
namespace NS {
  int x = 0;
  int &ref = x;
}

using NS::ref;
---------------------

test/ice.cc:6: internal compiler error: in reference_to_unused, at dwarf2out.c:10128


This compiles cleanly with both 4.1.2 and 4.2.0 RC1 (20070316), suggesting that this was exposed by a fairly recent patch.


Note that, in particular, this impacts code using Boost.Lambda in the following style:

#include <boost/lambda/lambda.hpp>
using boost::lambda::_1;
...
Comment 1 David Fang 2007-05-11 18:53:28 UTC
On your test case, 
$ g++-4 -g -c pr31899.cc -o pr31899.o
also works for me with 4.2.0 20070430 (prerelease), which was 4.2's RC2.

Configured with: ../gcc-4.2.0-20070430/configure --prefix=/sw --prefix=/sw/lib/gcc4.2 --mandir=/sw/share/man --infodir=/sw/share/info --enable-languages=c,c++,fortran,objc,java --host=powerpc-apple-darwin8 --with-gmp=/sw --with-libiconv-prefix=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
Comment 2 David Fang 2007-05-11 18:58:07 UTC
Ooops, strike that last comment, forgot -gdwarf-2:

g++-4 -gdwarf-2 -c pr31899.cc -o pr31899.o
ICEs with:
internal compiler error: in reference_to_unused, at dwarf2out.c:10010

(same compiler version, 4.2 RC2)
Comment 3 Andrew Pinski 2007-05-12 14:50:10 UTC
Confirmed, this was caused by the patch for PR 30700.
Comment 4 Mark Mitchell 2007-05-14 22:26:58 UTC
Will not be fixed in 4.2.0; retargeting at 4.2.1.
Comment 5 Doug Kwan 2007-07-27 20:54:19 UTC
Created attachment 13989 [details]
Proposed fix for SEGV problem in dwarf2out.c in bug 31899
Comment 6 Andrew Pinski 2007-08-08 18:58:57 UTC
*** Bug 33026 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2007-10-02 16:21:44 UTC
*** Bug 33625 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2007-10-02 16:21:52 UTC
*** Bug 33580 has been marked as a duplicate of this bug. ***
Comment 9 Richard Biener 2007-10-02 16:55:45 UTC
  else if (!cgraph_global_info_ready
           && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
    gcc_unreachable ();

the problem is that the C++ FE emits debug info for global using decls from
parsing:

...
#9  0x082a825e in cp_emit_debug_info_for_using (t=0xb7d6705c, context=0x0)
    at /home/richard/src/trunk/gcc/cp/name-lookup.c:5223
---Type <return> to continue, or q <return> to quit---
#10 0x0829f5ef in do_toplevel_using_decl (decl=0xb7d61870, scope=0xb7d61798, 
    name=0xb7d66708) at /home/richard/src/trunk/gcc/cp/name-lookup.c:3360
#11 0x081bca90 in cp_parser_using_declaration (parser=0xb7cd22a4, 
    access_declaration_p=0 '\0')
    at /home/richard/src/trunk/gcc/cp/parser.c:11695
...

via the imported_module_or_decl debug hook.  I guess we should simply queue
these with the varpool.  Or probably invent a new pool for just this use.
Or just weaken the sanity check.
Comment 10 Richard Biener 2007-10-02 17:05:55 UTC
Created attachment 14286 [details]
patch

Different patch.
Comment 11 Richard Biener 2007-10-03 10:02:03 UTC
Subject: Bug 31899

Author: rguenth
Date: Wed Oct  3 10:01:43 2007
New Revision: 128978

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128978
Log:
2007-10-03  Doug Kwan  <dougkwan@google.com>
	Richard Guenther  <rguenther@suse.de>

	PR debug/31899
	* dwarf2out.c (reference_to_unused): Disable sanity checking,
	be conservative instead.

	* g++.dg/debug/using3.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/debug/using3.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog

Comment 12 Richard Biener 2007-10-03 10:04:11 UTC
Fixed on the trunk, queued for 4.2.3.
Comment 13 Richard Biener 2007-10-05 12:14:27 UTC
*** Bug 33668 has been marked as a duplicate of this bug. ***
Comment 14 Richard Biener 2007-10-10 09:29:24 UTC
Subject: Bug 31899

Author: rguenth
Date: Wed Oct 10 09:29:13 2007
New Revision: 129199

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129199
Log:
2007-10-10  Richard Guenther  <rguenther@suse.de>

        Backport from mainline
        2007-10-03  Doug Kwan  <dougkwan@google.com>
                Richard Guenther  <rguenther@suse.de>

        PR debug/31899
        * dwarf2out.c (reference_to_unused): Disable sanity checking,
        be conservative instead.

        * g++.dg/debug/using3.C: New testcase.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/debug/using3.C
      - copied unchanged from r128978, trunk/gcc/testsuite/g++.dg/debug/using3.C
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/dwarf2out.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 15 Richard Biener 2007-10-10 09:29:39 UTC
Fixed.
Comment 16 Richard Biener 2008-02-27 13:23:29 UTC
*** Bug 35391 has been marked as a duplicate of this bug. ***