Bug 82155 - [7 Regression] ICE in dwarf2out_abstract_function, at dwarf2out.c:21655
Summary: [7 Regression] ICE in dwarf2out_abstract_function, at dwarf2out.c:21655
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 82998 84736 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-09-08 21:51 UTC by Sergei Trofimovich
Modified: 2018-03-07 10:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-09-11 00:00:00


Attachments
ECBackend.ii (247 bytes, text/plain)
2017-09-08 21:54 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2017-09-08 21:51:44 UTC
The crash is extracted from ceph-10.2.9.
[1] is the minimal reproducer (a bit big as I did not clean it after 'creduce'):

Crashes on both gcc-7.2.0 anf gcc-master (x86_64-pc-linux-gnu)

$ LANG=C g++ -O2 -g -c -o ECBackend.o ECBackend.ii
    ECBackend.ii: In member function 'virtual void m::m()::n::k(int)':
    ECBackend.ii:23:12: internal compiler error: in force_type_die, at dwarf2out.c:25099
           void k(int) {}
                ^
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <https://bugs.gentoo.org/> for instructions.

// [1] : reproducer

template <typename a> struct b { a c; };
template <typename d> struct e { d *operator->(); };
template <typename d> class h {
public:
  typedef e<d> ag;
};
class i {
protected:
  i(int);
};
class j {
  virtual void k(int) = 0;

public:
  int f;
  void l() { k(f); }
};
struct m : i {
  int cn;
  m() : i(cn) {
    struct n : j {
      n() {}
      void k(int) {}
    };
  }
};
struct o {
  o() {
    for (h<b<b<j *>>>::ag g;;)
      g->c.c->l();
  }
};
void fn1() { o(); }
Comment 1 Sergei Trofimovich 2017-09-08 21:54:30 UTC
Created attachment 42143 [details]
ECBackend.ii

Attaching original reproducer as well.
Comment 2 Martin Liška 2017-09-11 07:09:11 UTC
Started with r242035
Comment 3 Pierre-Marie de Rodat 2017-09-11 07:15:03 UTC
Thank you for reporting this. I’m having a look.
Comment 4 Pierre-Marie de Rodat 2017-09-12 06:03:56 UTC
I have a candidate fix, which I submitted on gcc-patches@: <https://gcc.gnu.org/ml/gcc-patches/2017-09/msg00647.html>
Comment 5 pmderodat 2017-09-25 12:27:07 UTC
Author: pmderodat
Date: Mon Sep 25 12:26:36 2017
New Revision: 253147

URL: https://gcc.gnu.org/viewcvs?rev=253147&root=gcc&view=rev
Log:
[PR82155] Fix crash in dwarf2out_abstract_function

This patch is an attempt to fix the crash reported in PR82155.

When generating a C++ class method for a class that is itself nested in
a class method, dwarf2out_early_global_decl currently leaves the
existing context DIE as it is if it already exists.  However, it is
possible that this call happens at a point where this context DIE is
just a declaration that is itself not located in its own context.

From there, if dwarf2out_early_global_decl is not called on any of the
FUNCTION_DECL in the context chain, DIEs will be left badly scoped and
some (such as the nested method) will be removed by the type pruning
machinery.  As a consequence, dwarf2out_abstract_function will will
crash when called on the corresponding DECL because it asserts that the
DECL has a DIE.

This patch fixes this crash making dwarf2out_early_global_decl process
context DIEs the same way we process abstract origins for FUNCTION_DECL:
if the corresponding DIE exists but is only a declaration, call
dwarf2out_decl anyway on it so that it is turned into a more complete
DIE and so that it is relocated in the proper context.

Bootstrapped and regtested on x86_64-linux.

gcc/

	PR debug/82155
	* dwarf2out.c (dwarf2out_early_global_decl): Call dwarf2out_decl
	on the FUNCTION_DECL function context if it has a DIE that is a
	declaration.

gcc/testsuite/

	* g++.dg/pr82155.C: New testcase.

Added:
    trunk/gcc/testsuite/g++.dg/pr82155.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2017-10-11 10:36:15 UTC
Assuming fixed on the trunk.
Comment 7 Martin Liška 2017-11-15 07:08:39 UTC
*** Bug 82998 has been marked as a duplicate of this bug. ***
Comment 8 pmderodat 2017-11-15 11:54:43 UTC
Author: pmderodat
Date: Wed Nov 15 11:54:11 2017
New Revision: 254761

URL: https://gcc.gnu.org/viewcvs?rev=254761&root=gcc&view=rev
Log:
[PATCH] [PR82155] Fix crash in dwarf2out_abstract_function

Backport from mainline (r253147):

This patch is an attempt to fix the crash reported in PR82155.

When generating a C++ class method for a class that is itself nested in
a class method, dwarf2out_early_global_decl currently leaves the
existing context DIE as it is if it already exists.  However, it is
possible that this call happens at a point where this context DIE is
just a declaration that is itself not located in its own context.

From there, if dwarf2out_early_global_decl is not called on any of the
FUNCTION_DECL in the context chain, DIEs will be left badly scoped and
some (such as the nested method) will be removed by the type pruning
machinery.  As a consequence, dwarf2out_abstract_function will will
crash when called on the corresponding DECL because it asserts that the
DECL has a DIE.

This patch fixes this crash making dwarf2out_early_global_decl process
context DIEs the same way we process abstract origins for FUNCTION_DECL:
if the corresponding DIE exists but is only a declaration, call
dwarf2out_decl anyway on it so that it is turned into a more complete
DIE and so that it is relocated in the proper context.

Bootstrapped and regtested on x86_64-linux.

gcc/

	PR debug/82155
	* dwarf2out.c (dwarf2out_early_global_decl): Call dwarf2out_decl
	on the FUNCTION_DECL function context if it has a DIE that is a
	declaration.

gcc/testsuite/

	* g++.dg/pr82155.C: New testcase.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/pr82155.C
Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/dwarf2out.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 9 Pierre-Marie de Rodat 2017-11-15 11:57:06 UTC
Fix is on trunk and I just merged it in the gcc-7 branch. I’ve left the target milestone to 7.3 even though 7.4 is available since according to https://gcc.gnu.org/gcc-7/, the last release was 7.2. Hoping I got it right!
Comment 10 Martin Liška 2018-03-07 10:17:42 UTC
*** Bug 84736 has been marked as a duplicate of this bug. ***