Bug 1217267

Summary: internal compiler error: in fold_convert_loc, at fold-const.c:1922
Product: Red Hat Enterprise Linux 7 Reporter: Robert Thornthwaite <robert.thornthwaite>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Miroslav Franc <mfranc>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.1CC: mcermak, mfranc, mpolacek, ohudlick
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: gcc-4.8.5-1.el7 Doc Type: Bug Fix
Doc Text:
Previously, GCC could generate wrong code from code that passed a union data type with a signed and an unsigned integer between two functions as a parameter. The compiler could incorrectly insert the __builtin_unreachable call into a codepath in the program that was, in fact, reachable, which resulted in a crash. This bug in the IPA inline analysis has been fixed, and GCC now generates correct code also in the described scenario.
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 12:22:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Preprocessed source none

Description Robert Thornthwaite 2015-04-29 22:34:27 UTC
Created attachment 1020351 [details]
Preprocessed source

Description of problem:
  I got this error while trying to compile.

Version-Release number of selected component (if applicable):
  gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) 


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 2 Marek Polacek 2015-04-30 09:25:25 UTC
Reproduced with vanilla 4.8; 4.9 is fine.  Bisecting...

Comment 3 Jakub Jelinek 2015-04-30 09:32:35 UTC
http://gcc.gnu.org/r218205

Comment 4 Jakub Jelinek 2015-04-30 09:37:17 UTC
And that commit had a follow-up:
http://gcc.gnu.org/r218316

Comment 5 Marek Polacek 2015-04-30 10:38:22 UTC
Reduced.  Only -O is needed to show the ICE.

class A
{
    int _M_p;
};
template < typename _Key, typename _Tp > class B
{
public:
    _Tp operator[](_Key);
};

union U
{
    long double ld;
    void *v;
};
A a;
void
fn1 (U p1)
{
    if (p1.v)
      *reinterpret_cast < A * >(p1.v) = a;
}

class C
{
public:
    C (A)
    {
        m_data.ld = 0;
        fn1 (m_data);
    }
    U m_data;
};

class D
{
public:
    A a1;
    A a2;
    void m_fn1 ()
    {
        arr[2][a1] = a2;
    } B < int, B < A, C > >arr;
};

void
fn2 ()
{
    D b;
    b.m_fn1 ();
}

Comment 6 Jakub Jelinek 2015-04-30 11:14:01 UTC
Slightly more cleaned up:

// { dg-options "-O -Wno-psabi" }
// { dg-do compile }

struct A { int a; };
template <typename T, typename V> struct B { V operator[] (T); };
union U { long double ld; void *v; };
A a;

void
bar (U &x)
{
  if (x.v) *reinterpret_cast <A *>(x.v) = a;
}

struct C { C (A) { c.ld = 0; bar (c); } U c; };
struct D { A d, e; void foo () { f[0][d] = e; } B <int, B <A, C> > f; };

void
baz ()
{
  D d;
  d.foo ();
}

Comment 7 Marek Polacek 2015-04-30 18:44:11 UTC
I've backported the relevant fixes to the 4.8 branch.

Comment 8 Robert Thornthwaite 2015-04-30 19:19:34 UTC
(In reply to Marek Polacek from comment #7)
> I've backported the relevant fixes to the 4.8 branch.

You guys are awesome!    Thank you.    Will this be out in a patch to the compiler sometime soon?

Comment 9 Jakub Jelinek 2015-04-30 19:20:57 UTC
Most likely in RHEL 7.2.

Comment 10 Marek Polacek 2015-05-18 16:47:01 UTC
*** Bug 1222631 has been marked as a duplicate of this bug. ***

Comment 13 errata-xmlrpc 2015-11-19 12:22:45 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2080.html