[Bug lto/115359] New: ICE in warn_types_mismatch: lto1: internal compiler error: Segmentation fault

a.horodniceanu at proton dot me gcc-bugzilla@gcc.gnu.org
Wed Jun 5 14:46:09 GMT 2024


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115359

            Bug ID: 115359
           Summary: ICE in warn_types_mismatch: lto1: internal compiler
                    error: Segmentation fault
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: a.horodniceanu at proton dot me
  Target Milestone: ---

Given the two source files:

a.cpp:
-----
struct Foo { };
void bar(Foo foo);
int main() {
        bar({});
}
----

a.d:
----
extern(C++):
struct Foo { }
void bar(Foo foo) { }
----

Compile them with: `g++ a.d a.cpp -flto -freport-bug`:
----
a.cpp:2:6: warning: ‘bar’ violates the C++ One Definition Rule [-Wodr]
    2 | void bar(Foo foo);
      |      ^
a.d:3:6: note: type mismatch in parameter 1
    3 | void bar(Foo foo) { }
      |      ^
lto1: internal compiler error: Segmentation fault
0x5654dba30e94 internal_error(char const*, ...)
        ???:0
0x5654dbaccbd1 xstrdup
        ???:0
0x5654da59f465 warn_types_mismatch(tree_node*, tree_node*, unsigned int,
unsigned int)
        ???:0
0x5654da30d1e1 lto_symtab_merge_decls()
        ???:0
0x5654da3154a2 read_cgraph_and_symbols(unsigned int, char const**)
        ???:0
0x5654da2fdce6 lto_main()
        ???:0
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld:
error: lto-wrapper failed
collect2: error: ld returned 1 exit status
----

g++ --version:
----
g++ (Gentoo Hardened 14.1.1_p20240518 p1) 14.1.1 20240516
Copyright (C) 2024 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.
----

I think this can be fixed with:
----
diff --git a/gcc/ipa-devirt.cc b/gcc/ipa-devirt.cc
index a7ce434bf..efeb3766c 100644
--- a/gcc/ipa-devirt.cc
+++ b/gcc/ipa-devirt.cc
@@ -1084,7 +1084,9 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1,
location_t loc2)
   if (odr1 != NULL && odr2 != NULL && odr1 != odr2)
     {
       const int opts = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
-      char *name1 = xstrdup (cplus_demangle (odr1, opts));
+      char *name1 = cplus_demangle (odr1, opts);
+      if (name1)
+             name1 = xstrdup(name1);
       char *name2 = cplus_demangle (odr2, opts);
       if (name1 && name2 && strcmp (name1, name2))
        {
----
but I'm not sure if cplus_demangle failing to demangle the D symbol is the real
problem.


More information about the Gcc-bugs mailing list