Bug 81765 - Internal compiler error: Segmentation fault with -O2 -fnon-call-exceptions
Summary: Internal compiler error: Segmentation fault with -O2 -fnon-call-exceptions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-08 07:33 UTC by Ubikovich
Modified: 2017-08-08 10:20 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 6.4.0
Known to fail: 6.3.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ubikovich 2017-08-08 07:33:19 UTC
// begin main.cpp
struct A
{
  virtual void do1() { }
};

struct B
{
  A* m_a;
  B() : m_a(nullptr) {}
  B(A* a) : m_a(a) {}
  ~B() { if (m_a) m_a->do1(); }
  void do2(B& other)
  {
    A* tmp = m_a;
    m_a = other.m_a;
    other.m_a = tmp;
  }
  B& operator=(A* a)
  {
    B(a).do2(*this);
    return *this;
  }
};

int main()
{
  int ar[] = { 0, 1 };
  for (int i = 0; i < 2; ++i)
  {
    int j = ar[i];
    B b;
    b = nullptr;
  }
  return 0;
}
// end main.cpp

$ g++ -S -std=c++11 -O2 -fnon-call-exceptions main.cpp
main.cpp: In function ‘int main()’:
main.cpp:25:5: internal compiler error: Segmentation fault
int main()
    ^~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions

$ g++ --version
gcc (Debian 6.3.0-18) 6.3.0 20170516
Copyright (C) 2016 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 machine 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) x86_64 GNU/Linux
Comment 1 Ubikovich 2017-08-08 09:17:35 UTC
How to avoid this bug?
Comment 2 Ubikovich 2017-08-08 09:40:19 UTC
(In reply to Ubikovich from comment #1)
> How to avoid this bug?

Compiling this code with optimization -O1 helps to avoid the problem.
Comment 3 Richard Biener 2017-08-08 10:20:19 UTC
This has been fixed in GCC 6.4.