Bug 56635 - [4.8/4.9 regression] internal compiler error: in find_lattice_value, at tree-complex.c:15
Summary: [4.8/4.9 regression] internal compiler error: in find_lattice_value, at tree-...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-16 15:11 UTC by Orion Poplawski
Modified: 2013-03-20 08:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-03-18 00:00:00


Attachments
Preprocessed source (247.49 KB, application/x-xz)
2013-03-17 01:44 UTC, Orion Poplawski
Details
gcc48-pr56635.patch (731 bytes, patch)
2013-03-18 09:02 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Orion Poplawski 2013-03-16 15:11:17 UTC
In file included from /builddir/build/BUILD/gdl-0.9.3/src/datatypes.cpp:67:0:
/builddir/build/BUILD/gdl-0.9.3/src/basic_op.cpp: In function '<built-in>':
/builddir/build/BUILD/gdl-0.9.3/src/basic_op.cpp:3791:9: internal compiler error: in find_lattice_value, at tree-complex.c:151
 #pragma omp parallel if (nEl >= CpuTPOOL_MIN_ELTS && (CpuTPOOL_MAX_ELTS == 0 || CpuTPOOL_MAX_ELTS <= nEl))
         ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccXWRPxa.out file, please attach this to your bugreport.

gcc-4.8.0-0.16.fc19.x86_64
Comment 1 Jakub Jelinek 2013-03-16 16:19:56 UTC
Preprocessed source stored into /tmp/ccXWRPxa.out file, please attach this to your bugreport.
Comment 2 Orion Poplawski 2013-03-17 01:44:29 UTC
Created attachment 29682 [details]
Preprocessed source

Sorry, looks like it was too big.  Here it is compressed.
Comment 3 Markus Trippelsdorf 2013-03-17 04:44:38 UTC
markus@x4 tmp % cat test.ii
template<typename>struct A;
template<typename _Tp>A<_Tp>operator/(A<_Tp>, A<_Tp>& p2)
{
  A<_Tp> a;
  a /= p2;
  return a;
}

template<typename _Tp>bool operator!=(A<_Tp>& p1, A<_Tp>&)
{
  return p1.real();
}

template<>struct A<double>
{
  double& real()
  {
    return __real__ _M_value;
  }

  template<typename _Tp>void operator/=(A<_Tp>&)
  {
    _M_value /= 10;
  }

  _Complex double _M_value;
};

template<class T>class B {
  T *buf;

public:

  B(int, bool);
  T& operator[](int)
  {
    return buf[0];
  }
};

struct C
{
  C(const int&);
  typedef A<double>Ty;
  typedef B<Ty>    DataT;
  A<double>zero;
  enum InitType
  { NOZERO };
  virtual C* DivInv(C *);
};
template<class Sp>class D : Sp {
  typedef typename Sp::Ty    Ty;
  typedef typename Sp::DataT DataT;
  DataT dd;

public:

  D(const int&, C::InitType);
  Ty& operator[](int)
  {
    return dd[0];
  }

  D* DivInv(C *);
};

template<class Sp>D<Sp> *D<Sp>::DivInv(C *)
{
  if ((*this)[0] != this->zero) (*this)[0] = (*static_cast<D *>(0))[0] /
                                             (*this)[0];
  else (*this)[0] = (*static_cast<D *>(0))[0];
  return 0;
}

D<C> *b = new D<C>(0, C::NOZERO);
template<class Sp>D<Sp>::D(const int&, C::InitType) : Sp(0), dd(0, 0)
{}

markus@x4 tmp % c++ -Wextra -Wall -c -O3 test.ii
test.ii: In member function ‘D<Sp>* D<Sp>::DivInv(C*) [with Sp = C]’:
test.ii:67:26: internal compiler error: in find_lattice_value, at tree-complex.c:151
 template<class Sp>D<Sp> *D<Sp>::DivInv(C *)
                          ^
Comment 4 Jakub Jelinek 2013-03-18 08:26:32 UTC
Reduced testcase (-O3):
struct A { _Complex double a; };
struct B { A *b; void foo (void *); };

A
operator / (A x, A y)
{
  A r;
  r.a = x.a / y.a;
  return r;
}

void
B::foo (void *x)
{
  if (__real__ b[0].a)
    b[0] = (static_cast <B *>(x))->b[0] / b[0];
  else
    b[0] = (static_cast <B *>(x))->b[0];
}

The ICE is actually
pr56635.C: In member function ‘void B::foo(void*)’:
pr56635.C:13:1: error: invalid PHI argument
 B::foo (void *x)
 ^
MEM[(const struct A &)_9]
pr56635.C:13:1: error: incompatible types in PHI argument 1
complex double

const struct A

cstore_10 = PHI <_11(3), MEM[(const struct A &)_9](4)>

pr56635.C:13:1: internal compiler error: verify_gimple failed

and looks like cselim bug.
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186501 but guess it just has been latent before that.
Comment 5 Jakub Jelinek 2013-03-18 08:46:43 UTC
Even more reduced (-O3):
struct A { _Complex double a; };

void
foo (A **x, A **y)
{
  A r;
  if (__real__ x[0]->a)
    {
      r.a = y[0]->a / x[0]->a;
      **x = r;
    }
  else
    **x = **y;
}
Comment 6 Jakub Jelinek 2013-03-18 09:02:22 UTC
Created attachment 29688 [details]
gcc48-pr56635.patch

Untested fix.
Comment 7 Jakub Jelinek 2013-03-18 13:02:01 UTC
Author: jakub
Date: Mon Mar 18 13:01:49 2013
New Revision: 196781

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196781
Log:
	PR tree-optimization/56635
	* fold-const.c (operand_equal_p): For MEM_REF and TARGET_MEM_REF,
	require types_compatible_p types.

	* g++.dg/torture/pr56635.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr56635.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2013-03-20 08:42:52 UTC
Author: jakub
Date: Wed Mar 20 08:40:08 2013
New Revision: 196808

URL: http://gcc.gnu.org/viewcvs?rev=196808&root=gcc&view=rev
Log:
	PR tree-optimization/56635
	* tree-ssa-phiopt.c (cond_if_else_store_replacement_1): Give up
	if lhs of then_assign and else_assign don't have compatible types.

	* g++.dg/torture/pr56635.C: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/torture/pr56635.C
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-ssa-phiopt.c
Comment 9 Jakub Jelinek 2013-03-20 08:43:18 UTC
Fixed.