User account creation filtered due to spam.

Bug 48446 - [4.3/4.4/4.5/4.6 Regression] internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1946
Summary: [4.3/4.4/4.5/4.6 Regression] internal compiler error: in gimplify_var_or_parm...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.5
: P2 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-04-05 03:54 UTC by Christopher Head
Modified: 2011-05-07 01:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.3, 4.1.2, 4.7.0
Known to fail: 4.3.5, 4.5.2, 4.6.0
Last reconfirmed: 2011-04-05 11:13:04


Attachments
The failing source file (1.25 KB, text/plain)
2011-04-05 03:54 UTC, Christopher Head
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Head 2011-04-05 03:54:20 UTC
Created attachment 23878 [details]
The failing source file

I compile the attached file using this command:

$ g++ -std=gnu++0x -Wall -Wextra -c test.cpp

with this version of GCC:

$ gcc --version
gcc (Gentoo 4.4.5 p1.2, pie-0.4.5) 4.4.5
Copyright (C) 2010 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.

on Gentoo x86-64 and x86 (both produce identical error messages). I get this output:

test.cpp: In member function ‘void Sender::flush()’:
test.cpp:168: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1946
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.gentoo.org/> for instructions.

I also have access to an OpenSUSE x86-64 environment reading out this version:

$ gcc --version
gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292]
Copyright (C) 2010 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.

This gives the following output:

test.cpp: In member function ‘void Sender::flush()’:
test.cpp:175:71: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1816
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.opensuse.org/> for instructions.

(yes, the source line number of the error in test.cpp is different for this GCC version even though the sources are identical).

Finally, a friend using Arch Linux x86-64 tested the same code on GCC 4.6 and also reproduced the bug, though I don't have the line numbers from that test.

I can attach preprocessed source if you want, though the source doesn't use anything but standard headers and the problem seems quite easily reproducible as I already described.
Comment 1 Richard Biener 2011-04-05 11:13:04 UTC
Confirmed.  Seems to have always crashed.  ICC accepts it.

Reduced testcase:

namespace std {
    typedef long unsigned int size_t;
}
typedef unsigned char uint8_t;
template<typename T> class RefPtr {
public:
    ~RefPtr();
    T *operator->() const;
};
class Message {
public:
    typedef RefPtr<Message> Ptr;
    static Ptr create(const void *data, std::size_t len);
};
template<std::size_t N> class BitArray {
public:
    static const std::size_t byte_count = (N + 7) / 8;
};
class Recipient {
public:
    typedef RefPtr<Recipient> Ptr;
    BitArray<80> data;
};
class Sender {
    Recipient::Ptr recipient(unsigned int i);
    void flush();
};
void Sender::flush()
{
    uint8_t buffer[64 / (recipient(0)->data.byte_count + 2)][recipient(0)->data.byte_count + 2];
    std::size_t wptr = 0;
    if (wptr == sizeof(buffer) / sizeof(*buffer)) {
        Message::Ptr msg = Message::create(buffer, wptr * sizeof(buffer[0]));
    }
}
Comment 2 Jonathan Wakely 2011-04-05 11:21:35 UTC
slightly further reduced:

template<typename T> struct RefPtr {
        ~RefPtr();

        T *operator->() const;
};

struct Message  {
        typedef RefPtr<Message> Ptr;

        static Ptr create(int);
};


struct Recipient  {
        typedef RefPtr<Recipient> Ptr;

        static const int byte_count = 80;
};


Recipient::Ptr recipient();

void flush()
{
    char buffer[(recipient()->byte_count)];

    {
        Message::Ptr msg = Message::create(sizeof(buffer));
    }
}


This is a regression as it compiles OK with GCC 4.1
Comment 3 Jonathan Wakely 2011-04-05 11:28:17 UTC
(In reply to comment #2)
> This is a regression as it compiles OK with GCC 4.1

... and 3.4
Comment 4 Jakub Jelinek 2011-04-07 08:30:57 UTC
template<typename T>
struct A
{
  ~A ();
  T *operator-> () const;
};

struct B
{
  typedef A <B> P;
  static P foo (int);
};

struct C
{
  typedef A<C> P;
  static const int c = 80;
};

C::P bar ();

void
baz ()
{
  char z[bar ()->c];
  {
    B::P m = B::foo (sizeof (z));
  }
}

Yeah, apparently some problem on the FE side with cleanups, where CLEANUP_POINT_EXPR already for z is given the cleanups for m, which are in a nested bind though and thus m wasn't seen in bind expr yet.
Comment 5 Jakub Jelinek 2011-04-07 08:36:41 UTC
Most likely caused by
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128979
(r128750 works, r129000 ICEs, am lazy to bisect it exactly).
Comment 6 Jakub Jelinek 2011-04-07 08:55:37 UTC
Actually now verified that it is r128979.
Comment 7 Jason Merrill 2011-04-14 15:00:03 UTC
Author: jason
Date: Thu Apr 14 14:59:58 2011
New Revision: 172432

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172432
Log:
	PR c++/48446
	* decl.c (compute_array_index_type): Use get_temp_regvar instead
	of variable_size.
	* init.c (get_temp_regvar): No longer static.
	* cp-tree.h: Declare it.

Added:
    trunk/gcc/testsuite/g++.dg/ext/vla10.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Jason Merrill 2011-04-14 15:22:41 UTC
This is now fixed for 4.7.0.  The fix seems reasonably safe to backport since it only affects bounds expressions with side-effects, but it also seems easy to work around in user code: just factor out the bounds expression into a local variable.
Comment 9 Jason Merrill 2011-05-02 18:38:49 UTC
Author: jason
Date: Mon May  2 18:38:44 2011
New Revision: 173264

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173264
Log:
	PR c++/48446
	* decl.c (stabilize_save_expr_r, stabilize_vla_size): New.
	(compute_array_index_type): Revert earlier 48446 changes.
	(grokdeclarator): Use stabilize_vla_size.

Added:
    trunk/gcc/testsuite/c-c++-common/vla-1.c
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jason Merrill 2011-05-06 21:58:32 UTC
Author: jason
Date: Fri May  6 21:58:30 2011
New Revision: 173514

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173514
Log:
	PR c++/48446
	* decl.c (stabilize_save_expr_r, stabilize_vla_size): New.
	(grokdeclarator): Use stabilize_vla_size.
	* init.c (get_temp_regvar): No longer static.
	* cp-tree.h: Declare it.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/c-c++-common/vla-1.c
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/ext/vla10.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/cp-tree.h
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/cp/init.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 11 Jason Merrill 2011-05-07 01:41:03 UTC
Fixed for 4.6.1.