Bug 48281 - [4.6/4.7 Regression] [C++0x] internal compiler error: in record_reference, at cgraphbuild.c:60
[4.6/4.7 Regression] [C++0x] internal compiler error: in record_reference, at...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
4.6.0
: P3 normal
: 4.6.1
Assigned To: Jason Merrill
: ice-on-valid-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-25 00:39 UTC by Stirling Westrup
Modified: 2011-03-30 18:08 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-03-25 01:03:15


Attachments
c++ code that was preprocessed to generated previous attachment. (1.82 KB, text/plain)
2011-03-25 00:41 UTC, Stirling Westrup
Details
Minimal test case that triggers the error. (213 bytes, text/plain)
2011-03-25 00:57 UTC, Stirling Westrup
Details
Preprocessed version of minimal test case. (25.32 KB, text/plain)
2011-03-25 00:59 UTC, Stirling Westrup
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stirling Westrup 2011-03-25 00:39:47 UTC
The code that triggered this bug is almost certainly in error, but as its caused an internal compiler error, it seemed worth reporting. That said, I don't really know *what* caused the bug, except to say that it happened when I declared my four matrix variables in the attached code (M a ... M d) to be static.

The code is one unit test from an ongoing project, and I've provided the plain .cpp code (for reference) and a pre-processed file so you have a chance to reproduce the bug.

In case it matters, here are my system specs:

$ g++ --version
g++ (Debian 4.6.0~rc1-2) 4.6.0 20110320 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -a
Linux timelord 2.6.36-zen2-sti-02 #4 ZEN SMP PREEMPT Fri Jan 7 13:21:12 EST 2011 x86_64 GNU/Linux
Comment 1 Stirling Westrup 2011-03-25 00:41:11 UTC
Created attachment 23770 [details]
c++ code that was preprocessed to generated previous attachment.
Comment 2 Stirling Westrup 2011-03-25 00:46:02 UTC
It seems that the preprocessed file that generates the error is 3KB in size, and is being rejected by Bugzilla. How the heck am I supposed to submit it now?
Comment 3 Jonathan Wakely 2011-03-25 00:52:44 UTC
compress the file e.g. with gzip
Comment 4 Stirling Westrup 2011-03-25 00:57:00 UTC
Created attachment 23771 [details]
Minimal test case that triggers the error.

Okay, I've managed to pare the original code down to the bare minimum that causes the error. This should be much easier to debug.
Comment 5 Stirling Westrup 2011-03-25 00:59:04 UTC
Created attachment 23772 [details]
Preprocessed version of minimal test case.

Here's a preprocessed version of the minimal test case, just in case you have some use for it.
Comment 6 Jonathan Wakely 2011-03-25 01:03:15 UTC
confirmed
Comment 7 Jason Merrill 2011-03-30 02:37:52 UTC
Interesting.
Comment 8 Jason Merrill 2011-03-30 16:01:21 UTC
This was broken by r163893, when I changed finish_compound_literal to always generate a TARGET_EXPR, rather than use a static variable in some cases.

I could (and probably will) partially revert that to fix this testcase, but looking into it reveals a deeper bug: we are generally failing to extend the lifetime of temporaries except in the simplest cases.  In this C++98 testcase we bind a temporary to the reference member of C, but don't extend its lifetime as we should.  This is probably pretty rare, but initializer_list subobjects are likely to be more common.

extern "C" void abort();
bool ok;

struct A {
  A(int) { }
  ~A() { if (!ok) abort(); }
};

struct C
{ 
  const A& ar;
};

int main()
{
  C c = { 1 };
  ok = true;
}
Comment 9 Jason Merrill 2011-03-30 18:05:48 UTC
Author: jason
Date: Wed Mar 30 18:05:43 2011
New Revision: 171738

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171738
Log:
	PR c++/48281
	* semantics.c (finish_compound_literal): Do put static/constant
	arrays in static variables.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/initlist46.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/semantics.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 10 Jason Merrill 2011-03-30 18:07:13 UTC
Author: jason
Date: Wed Mar 30 18:07:09 2011
New Revision: 171741

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171741
Log:
	PR c++/48281
	* semantics.c (finish_compound_literal): Do put static/constant
	arrays in static variables.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist46.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 11 Jason Merrill 2011-03-30 18:08:02 UTC
Fixed for 4.6.1.  Other bug filed as PR 48370.