Bug 82878 - [7 Regression] ICE in assign_temp, at function.c:968 when using optimization
Summary: [7 Regression] ICE in assign_temp, at function.c:968 when using optimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 7.2.0
: P3 normal
Target Milestone: 7.3
Assignee: Nathan Sidwell
URL:
Keywords:
: 79989 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-11-07 04:23 UTC by Kyle Sunden
Modified: 2018-01-26 14:43 UTC (History)
3 users (show)

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


Attachments
Preprocessed source file (174.92 KB, application/gzip)
2017-11-07 05:30 UTC, Kyle Sunden
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle Sunden 2017-11-07 04:23:52 UTC
This bug is possibly related to Bug 79989 and/or Bug 82148, but presents itself in a slightly different manner than in either of those examples.

The short version:
The following command, given the preprocessed source file provided, produces an ICE:

```
$ g++ --verbose -c fd_array.ii -O
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 7.2.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-c' '-O' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/cc1plus -fpreprocessed fd_array.ii -quiet -dumpbase fd_array.ii -mtune=generic -march=x86-64 -auxbase fd_array -O -version -o /tmp/ccOdsz5s.s
GNU C++14 (GCC) version 7.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.5-p2, MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 7.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.2.0, GMP version 6.1.2, MPFR version 3.1.5-p2, MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5931a2fe3d5a5365a85e56248f3f55d7
sim/fd_array.cc: In member function ‘void FDArray::restoreFileOffsets()’:
sim/fd_array.cc:143:5: internal compiler error: in assign_temp, at function.c:968
     };
     ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
```

Note, this report is from GCC 7.2.0 running on Arch Linux, but I also observed the same error message using GCC 7.2.1 running on OpenSUSE Tumbleweed.

Additional information:

This code does compile with no optimization flag or with '-O0', but any other '-O' flag triggers this bug (including '-Ofast' and '-Og').

I was unable to trigger the bug purely by adding optimization flags, even when specifying all flags listed under -O1 at: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html:

$ g++ -c fd_array.ii -fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments -fcompare-elim -fcprop-registers -fdce -fdefer-pop -fdelayed-branch -fdse -fforward-propagate -fguess-branch-probability -fif-conversion2 -fif-conversion -finline-functions-called-once -fipa-pure-const -fipa-profile -fipa-reference -fmerge-constants -fmove-loop-invariants -freorder-blocks -fshrink-wrap -fshrink-wrap-separate -fsplit-wide-types -fssa-backprop -fssa-phiopt -ftree-bit-ccp -ftree-ccp -ftree-ch -ftree-coalesce-vars -ftree-copy-prop -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-sink -ftree-slsr -ftree-sra -ftree-pta -ftree-ter -funit-at-a-time -fomit-frame-pointer


This produces one warning on my machine due to the -fdelayed-branch flag which is unsupported by the target machine.
In point of fact, I specified all flags from -O1, -O2, and -O3, and had no error.


I was able to trigger the ICE using the flags from Bug 79989 ('$ g++ -c fd_array.ii -mmpx -fcheck-pointer-bounds '), but this produced additional output and is not listed as flags which are provided by the '-O' flag (namely, this treated the function as a static member function rather than simply a "member function"):
    
    sim/fd_array.cc: In static member function ‘static void FDArray::restoreFileOffsets()::<lambda(std::shared_ptr<FileFDEntry>)>::_FUN.chkp(std::shared_ptr<FileFDEntry>, \xe2\x80\x98pointer_bounds_typ\xe2\x80\x99 not supported by dump_type#<type error>, void, ...)’:
sim/fd_array.cc:143:5: internal compiler error: in assign_temp, at function.c:968
     };
     ^


The original code compiles with g++-6 (though the g++-7 preprocessed file provided here does not complete compilation with g++-6)

The source file is from the gem5 cpu simulator, BSD 3-clause licensed
Comment 1 Kyle Sunden 2017-11-07 05:30:38 UTC
Created attachment 42554 [details]
Preprocessed source file

Needed to compress because the plain text is too large to submit.

Did not realize it did not attach on my original comment
Comment 2 Markus Trippelsdorf 2017-11-07 06:47:50 UTC
 % cat fd_array.ii
struct __shared_count {
  ~__shared_count();
};
struct A {
  operator int();
  __shared_count _M_refcount;
};
void fn1() {
  void (*seek)(A) = [](A) { fn1(); };
  A fdp;
  if (auto ffd = fdp)
    seek(ffd);
}

 % g++ -c fd_array.ii -O
during RTL pass: expand
fd_array.ii: In function ‘void fn1()’:
fd_array.ii:9:36: internal compiler error: in assign_temp, at function.c:970
   void (*seek)(A) = [](A) { fn1(); };
                                    ^
0xac2b3e assign_temp(tree_node*, int, int)
        /home/markus/gcc/gcc/function.c:970
0x9272bb initialize_argument_information
        /home/markus/gcc/gcc/calls.c:1820
0x92839a expand_call(tree_node*, rtx_def*, int)
        /home/markus/gcc/gcc/calls.c:3261
0xa5839d expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        /home/markus/gcc/gcc/expr.c:10853
0x93f19b expand_expr
        /home/markus/gcc/gcc/expr.h:276
0x93f19b expand_call_stmt
        /home/markus/gcc/gcc/cfgexpand.c:2674
0x93f19b expand_gimple_stmt_1
        /home/markus/gcc/gcc/cfgexpand.c:3608
0x93f19b expand_gimple_stmt
        /home/markus/gcc/gcc/cfgexpand.c:3774
0x9409b7 expand_gimple_basic_block
        /home/markus/gcc/gcc/cfgexpand.c:5779
0x946ed6 execute
        /home/markus/gcc/gcc/cfgexpand.c:6385
Comment 3 Martin Liška 2017-11-07 13:55:57 UTC
Started with r244728.
Comment 4 Jakub Jelinek 2017-11-07 14:26:10 UTC
Started with r244728.
Slightly adjusted testcase:
struct S { ~S (); };
struct A { operator int (); S a; };

void
bar ()
{
  void (*foo)(A) = [](A) { bar (); };
  A b;
  if (auto c = b)
    foo (c);
}
Comment 5 Nathan Sidwell 2017-11-20 14:39:33 UTC
Author: nathan
Date: Mon Nov 20 14:39:00 2017
New Revision: 254958

URL: https://gcc.gnu.org/viewcvs?rev=254958&root=gcc&view=rev
Log:
[PR c++/82878] pass-by-invisiref in lambda

https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01115.html
	PR c++/82878
	PR c++/78495
	* call.c (build_call_a): Don't set CALL_FROM_THUNK_P for inherited
	ctor.
	* cp-gimplify.c	(cp_genericize_r): Restore THUNK dereference
	inhibibition check removed in previous c++/78495 change.

	PR c++/82878
	* g++.dg/cpp0x/pr82878.C: New.
	* g++.dg/cpp1z/inh-ctor38.C: Check moves too.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr82878.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/cp/lambda.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C
    trunk/gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C
Comment 6 Jakub Jelinek 2017-11-21 15:47:41 UTC
Fixed on the trunk so far.
Comment 7 Nathan Sidwell 2017-11-21 16:36:42 UTC
Fixed r254958.
Comment 8 Jakub Jelinek 2017-12-01 11:50:51 UTC
Well, not fixed on the 7 branch, right?
Comment 9 Jakub Jelinek 2017-12-01 11:51:01 UTC
*** Bug 79989 has been marked as a duplicate of this bug. ***
Comment 10 Nathan Sidwell 2018-01-26 13:49:12 UTC
Author: nathan
Date: Fri Jan 26 13:48:37 2018
New Revision: 257089

URL: https://gcc.gnu.org/viewcvs?rev=257089&root=gcc&view=rev
Log:
[C++/82878] backport fix

https://gcc.gnu.org/ml/gcc-patches/2018-01/msg02170.html
	PR c++/82878
	PR c++/78495
	* call.c (build_call_a): Don't set CALL_FROM_THUNK_P for inherited
	ctor.
	* cp-gimplify.c	(cp_genericize_r): Restore THUNK dereference
	inhibibition check removed in previous c++/78495 change.

	PR c++/82878
	* g++.dg/cpp0x/pr82878.C: New.
	* g++.dg/cpp1z/inh-ctor38.C: Check moves too.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/pr82878.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/call.c
    branches/gcc-7-branch/gcc/cp/cp-gimplify.c
    branches/gcc-7-branch/gcc/cp/lambda.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp1z/inh-ctor38.C
Comment 11 Nathan Sidwell 2018-01-26 14:43:43 UTC
fixed on gcc-7 branch r257089.