Bug 80856 - [7/8 Regression] ICE from template local overload resolution
Summary: [7/8 Regression] ICE from template local overload resolution
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.0
: P2 normal
Target Milestone: 7.2
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2017-05-22 13:40 UTC by Josh Kelley
Modified: 2017-05-31 18:49 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-05-22 00:00:00


Attachments
Test case (159 bytes, text/plain)
2017-05-22 13:40 UTC, Josh Kelley
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Kelley 2017-05-22 13:40:31 UTC
Created attachment 41402 [details]
Test case

Compiling the attached source file with no flags ("g++-7 EngineReportWriter.cpp") results in an internal compiler error:

EngineReportWriter.cpp: In function ‘T WrapToCycle(T) [with T = int]’:
EngineReportWriter.cpp:2:10: internal compiler error: Segmentation fault
 inline T WrapToCycle(T degrees)
          ^~~~~~~~~~~
0x86f4b4a crash_signal
        ../../src/gcc/toplev.c:337
0x84d576b useless_type_conversion_p(tree_node*, tree_node*)
        ../../src/gcc/gimple-expr.c:85
0x83b4b8f types_compatible_p
        ../../src/gcc/gimple-expr.h:66
0x83b4b8f gimple_check_call_args
        ../../src/gcc/cgraph.c:3733
0x83b4b8f gimple_check_call_matching_types(gimple*, tree_node*, bool)
        ../../src/gcc/cgraph.c:3783
0x83b6304 symbol_table::create_edge(cgraph_node*, cgraph_node*, gcall*, long long, int, bool)
        ../../src/gcc/cgraph.c:864
0x83b6529 cgraph_node::create_edge(cgraph_node*, gcall*, long long, int)
        ../../src/gcc/cgraph.c:900
0x83bbb06 execute
        ../../src/gcc/cgraphbuild.c:337
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.


The bug appears to be triggered by the combination of a template plus local function declarations plus overload resolution.  If I move the local scope function declarations to global scope, or if I change the function declarations so that overload resolution isn't necessary, then the bug goes away.

This is on Ubuntu 14.04 x86, running GCC 7.1.0 from the Ubuntu Toolchain Test PPA (https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test).

Previous versions of GCC (including GCC 6.3.0 from the Ubuntu Toolchain Test PPA) are unaffected.

GCC 7.1 on godbolt.org is also reporting errors: https://godbolt.org/g/eAYhqd
Comment 1 Markus Trippelsdorf 2017-05-22 14:45:46 UTC
Started with r236221:

commit eee80116a8d0e277930da56aaf57a3d7e880bc86
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri May 13 19:18:35 2016 +0000

            Fix type-dependence and the current instantiation.
    
            PR c++/10200
            PR c++/69753
Comment 2 Jason Merrill 2017-05-30 21:13:59 UTC
Author: jason
Date: Tue May 30 21:13:27 2017
New Revision: 248699

URL: https://gcc.gnu.org/viewcvs?rev=248699&root=gcc&view=rev
Log:
	PR c++/80856 - ICE with local extern in template

	* semantics.c (finish_call_expr): Replace a local extern overload
	set in a template with the IDENTIFIER_NODE.

Added:
    trunk/gcc/testsuite/g++.dg/template/local-fn2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
Comment 3 Jason Merrill 2017-05-31 17:53:44 UTC
Author: jason
Date: Wed May 31 17:53:12 2017
New Revision: 248754

URL: https://gcc.gnu.org/viewcvs?rev=248754&root=gcc&view=rev
Log:
	PR c++/80856 - ICE with local extern in template

	* semantics.c (finish_call_expr): Replace a local extern overload
	set in a template with the IDENTIFIER_NODE.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/template/local-fn2.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/semantics.c
Comment 4 Jason Merrill 2017-05-31 18:49:35 UTC
Fixed.