Bug 86740 - [8 Regression] ICE with hana and nested lambdas (likely a regression, tsubst_copy, at cp/pt.c:15325)
Summary: [8 Regression] ICE with hana and nested lambdas (likely a regression, tsubst_...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P2 normal
Target Milestone: 8.3
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-07-30 14:26 UTC by Markus Dreseler
Modified: 2019-01-29 15:46 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0, 9.0
Known to fail: 8.1.0, 8.2.0
Last reconfirmed: 2018-11-27 00:00:00


Attachments
Test case (448 bytes, text/x-csrc)
2018-07-30 14:26 UTC, Markus Dreseler
Details
Preprocessed Source (trunk) (120.65 KB, text/plain)
2018-07-31 09:32 UTC, Markus Dreseler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Dreseler 2018-07-30 14:26:25 UTC
Created attachment 44467 [details]
Test case

The attached file causes the following ICE:

gccice.cpp:35:26: internal compiler error: in tsubst_copy, at cp/pt.c:15325
             std::cout << params << std::endl;
                          ^~~~~~
0x599570 tsubst_copy
	../../src/gcc/cp/pt.c:15325
0x6ce257 tsubst_copy
	../../src/gcc/cp/pt.c:15301
0x6ce257 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:18843
0x6cf567 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:17782
0x6cf640 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:18630
0x6c1641 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:17412
0x6c4a04 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16584
0x6c4a04 tsubst_decl
	../../src/gcc/cp/pt.c:13723
0x6bcdf7 tsubst_copy
	../../src/gcc/cp/pt.c:15431
0x6ce257 tsubst_copy
	../../src/gcc/cp/pt.c:15301
0x6ce257 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:18843
0x6cf567 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:17782
0x6d0c69 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
	../../src/gcc/cp/pt.c:17553
0x6ce2df tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:18923
0x6ce8f6 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:18248
0x6c1641 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:17412
0x6c1425 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16613
0x6c0cc8 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16599
0x6c0bab tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16896
0x6c1ffb tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16866


I tried to cut the test case down as much as possible, but even seemingly unrelated changes make the bug disappear. For example, try replacing YESSIR with true.

First seen on g++-8 (Ubuntu 8.1.0-1ubuntu1) 8.1.0, but reproduced with svn revision 263064. Command line is 'g++-8 -std=c++17 gccice.cpp'. Clang compiles the file.

There is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67411, which looks somewhat similar, but the bug described there is already fixed.
Comment 1 Richard Biener 2018-07-31 09:30:58 UTC
Can you attach preprocessed source please?
Comment 2 Markus Dreseler 2018-07-31 09:32:14 UTC
Created attachment 44470 [details]
Preprocessed Source (trunk)
Comment 3 Richard Biener 2018-07-31 10:33:11 UTC
Confirmed.
Comment 4 Michal Urbanczyk 2018-09-04 15:44:32 UTC
I have encountered a similar issue without using Boost.Hana. My code worked with GCC 7.3 and stopped compiling with GCC 8.1.

The reduced testcase:

struct Constant
{
    static constexpr int value = 0;
};
template<typename F>
void invokeWithConstant(F &&f)
{
    f(Constant{});
}
int foo()
{
    int count = 0;
    invokeWithConstant([&] (auto id1)
    {
        invokeWithConstant([&] (auto id2)
        {
            if constexpr(id1.value == 0  &&  id2.value == 0)
            {
                [&] { count = 1; } ();
            }
        });
    });
    return count;
}

====

Can be tested online at https://godbolt.org/z/N5rNYl

My case yields ICE from the very same line.
Comment 5 Martin Liška 2018-10-09 09:13:45 UTC
Confirmed, started with r259043.
Comment 6 Jason Merrill 2019-01-17 20:37:03 UTC
Author: jason
Date: Thu Jan 17 20:36:31 2019
New Revision: 268046

URL: https://gcc.gnu.org/viewcvs?rev=268046&root=gcc&view=rev
Log:
	PR c++/86740, ICE with constexpr if and nested generic lambdas.

When we partially instantiate the constexpr if, we walk through its body to
see what it uses from the enclosing local_specializations.  That walk was
overlooking the use of 'count' in the captures of the innermost lambda,
because we weren't walking into the capture list.

	* tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
Comment 7 Jason Merrill 2019-01-17 21:06:00 UTC
Fixed on trunk so far.
Comment 8 Jason Merrill 2019-01-27 20:32:08 UTC
Author: jason
Date: Sun Jan 27 20:31:37 2019
New Revision: 268324

URL: https://gcc.gnu.org/viewcvs?rev=268324&root=gcc&view=rev
Log:
	PR c++/86740, ICE with constexpr if and nested generic lambdas.

When we partially instantiate the constexpr if, we walk through its body to
see what it uses from the enclosing local_specializations.  That walk was
overlooking the use of 'count' in the captures of the innermost lambda,
because we weren't walking into the capture list.

	* tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/tree.c
Comment 9 Jason Merrill 2019-01-29 15:46:03 UTC
Fixed for 8.3 as well.