Bug 109241 - [12/13/14 Regression] ICE Segmentation fault for statement expression with a local type inside inside a generic lambda inside a generic lambda since r13-6722-gb323f52ccf966800
Summary: [12/13/14 Regression] ICE Segmentation fault for statement expression with a ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.0
: P1 normal
Target Milestone: 12.4
Assignee: Jason Merrill
URL:
Keywords: c++-lambda, ice-on-valid-code
: 106398 109803 109850 109872 110306 115195 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-03-21 20:47 UTC by Martin Liška
Modified: 2024-05-22 19:13 UTC (History)
12 users (show)

See Also:
Host:
Target:
Build:
Known to work: 12.2.0
Known to fail: 12.3.0, 13.0
Last reconfirmed: 2023-03-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2023-03-21 20:47:06 UTC
Reduced from ccache package:

$ cat LocalStorage.ii
template <int __v> struct integral_constant {
  static constexpr int value = __v;
};
template <bool, typename _Tp> using __enable_if_t = _Tp;
template <typename> using __void_t = void;
template <typename _Tp> _Tp __declval(long);
template <typename _Tp> auto declval() -> decltype(__declval<_Tp>(0));
template <typename> struct __result_of_success;
template <bool, bool, typename...> struct __result_of_impl;
template <typename _Fn, typename... _Args>
__result_of_success<decltype(declval<_Fn>()(declval<_Args>...))> _S_test;
template <typename _Functor, typename... _ArgTypes>
struct __result_of_impl<false, false, _Functor, _ArgTypes...> {
  typedef decltype(_S_test<_Functor, _ArgTypes...>) type;
};
template <typename _Functor, typename... _ArgTypes>
struct __invoke_result : __result_of_impl<integral_constant<false>::value,
                                          integral_constant<false>::value,
                                          _Functor, _ArgTypes...> {};
template <typename, typename, typename = void> struct __is_invocable_impl;
template <typename _Result, typename _Ret>
struct __is_invocable_impl<_Result, _Ret, __void_t<typename _Result::type>>
    : integral_constant<true> {};
template <typename> class function;
template <typename _Cond, typename _Tp = void>
using _Requires = __enable_if_t<_Cond::value, _Tp>;
template <typename _Res, typename... _ArgTypes>
struct function<_Res(_ArgTypes...)> {
  template <typename _Func, typename _DFunc = _Func,
            typename _Res2 = __invoke_result<_DFunc, _ArgTypes...>>
  struct _Callable : __is_invocable_impl<_Res2, _Res> {};
  template <typename _Functor, typename = _Requires<_Callable<_Functor>>>
  function(_Functor) {}
};
void for_each_cache_subdir(function<void(char, function<void>)>) {
  for_each_cache_subdir([](auto, auto) {
    [](auto) {
      ({
        struct __attribute__FMT_COMPILE_STRING {};
      });
    };
  });
}

$ g++ LocalStorage.ii -c
LocalStorage.ii: In instantiation of ‘for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)> [with auto:1 = char (*)(); auto:2 = function<void> (*)()]’:
LocalStorage.ii:11:44:   required from ‘struct __result_of_impl<false, false, for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, char, function<void> >’
LocalStorage.ii:31:10:   recursively required by substitution of ‘template<class _Result, class _Ret> struct __is_invocable_impl<_Result, _Ret, __void_t<typename _Result::type> > [with _Result = __invoke_result<for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, char, function<void> >; _Ret = void]’
LocalStorage.ii:31:10:   required from ‘struct function<void(char, function<void>)>::_Callable<for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, __invoke_result<for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, char, function<void> > >’
LocalStorage.ii:26:7:   required by substitution of ‘template<class _Cond, class _Tp> using _Requires = __enable_if_t<_Cond::value, _Tp> [with _Cond = function<void(char, function<void>)>::_Callable<for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, __invoke_result<for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>, char, function<void> > >; _Tp = void]’
LocalStorage.ii:32:32:   required by substitution of ‘template<class _Functor, class> function<void(char, function<void>)>::function(_Functor) [with _Functor = for_each_cache_subdir(function<void(char, function<void>)>)::<lambda(auto:1, auto:2)>; <template-parameter-1-2> = <missing>]’
LocalStorage.ii:36:24:   required from here
LocalStorage.ii:38:7: internal compiler error: Segmentation fault
   38 |       ({
      |       ^
0x11978cf crash_signal
	/home/marxin/Programming/gcc/gcc/toplev.cc:314
0x7ffff78b1edf ???
	/usr/src/debug/glibc-2.37/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xb19347 tree_check(tree_node*, char const*, int, char const*, tree_code)
	/home/marxin/Programming/gcc/gcc/tree.h:3539
0xb19347 find_parameter_packs_r
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:4073
0x14873cd walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	/home/marxin/Programming/gcc/gcc/tree.cc:11327
0x1487a40 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	/home/marxin/Programming/gcc/gcc/tree.cc:11442
0xb1b105 check_for_bare_parameter_packs(tree_node*, unsigned int)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:4283
0xb7b5a5 finish_expr_stmt(tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/semantics.cc:904
0xb3c3d2 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:18856
0xb3bbb4 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:19204
0xb66e68 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:18810
0xb66e68 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:20203
0xb2f796 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:21715
0xb3977f tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:19872
0xb3ae47 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:18852
0xb3a201 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:18824
0xb3bbb4 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:19204
0xb3bbb4 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:19204
0xb46215 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:18810
0xb46215 instantiate_body
	/home/marxin/Programming/gcc/gcc/cp/pt.cc:26815
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 Andrew Pinski 2023-03-21 21:01:43 UTC
Reduced almost all the way:
```
void g() {
  [](auto) {
    []<int>() {
      ({
        struct __attribute__FMT_COMPILE_STRING {};
      });
    };
  }(1);
}
```
Comment 2 GCC Commits 2023-03-23 03:24:07 UTC
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:4872e46e080c6695dfe1f9dc9db26b4703bc348c

commit r13-6824-g4872e46e080c6695dfe1f9dc9db26b4703bc348c
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 22 16:11:47 2023 -0400

    c++: local class in nested generic lambda [PR109241]
    
    In this testcase, the tree walk to look for bare parameter packs was
    confused by finding a type with no TREE_BINFO.  But it should be fine that
    it's unset; we already checked for unexpanded packs at parse time.
    
    I also tried doing the partial instantiation of the local class, which is
    probably the long-term direction we want to go, but for stage 4 let's go
    with this safer change.
    
            PR c++/109241
    
    gcc/cp/ChangeLog:
    
            * pt.cc (find_parameter_packs_r): Handle null TREE_BINFO.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1y/lambda-generic-local-class2.C: New test.
Comment 3 Martin Liška 2023-03-23 08:08:57 UTC
I guess it's fixed now.
Comment 4 GCC Commits 2023-04-26 21:16:37 UTC
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:d60cbbfaa9a3ad3bd1f613be95add939c16fc9a1

commit r14-278-gd60cbbfaa9a3ad3bd1f613be95add939c16fc9a1
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 22 16:11:47 2023 -0400

    c++: local class in nested generic lambda [PR109241]
    
    The earlier fix for PR109241 avoided the crash by handling a type with no
    TREE_BINFO.  But we want to move toward doing the partial substitution of
    classes in generic lambdas, so let's take a step in that direction.
    
            PR c++/109241
    
    gcc/cp/ChangeLog:
    
            * pt.cc (instantiate_class_template): Do partially instantiate.
            (tsubst_expr): Do call complete_type for partial instantiations.
Comment 5 Marek Polacek 2023-05-10 20:41:29 UTC
In GCC 12 this test still ICEs:

template<class T>
void foo(T) {
    [](auto){
        [] {
            struct X {};
        };
    };
}

template void foo(int);
Comment 6 Marek Polacek 2023-05-10 20:41:46 UTC
*** Bug 109803 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2023-05-13 22:51:52 UTC
*** Bug 109850 has been marked as a duplicate of this bug. ***
Comment 8 Richard Biener 2023-05-15 07:54:17 UTC
(In reply to Marek Polacek from comment #5)
> In GCC 12 this test still ICEs:
> 
> template<class T>
> void foo(T) {
>     [](auto){
>         [] {
>             struct X {};
>         };
>     };
> }
> 
> template void foo(int);

How so?  I can't reproduce.  Likewise for PR109850.  Is trunk actually fixed?
Please update known-to-work.
Comment 9 GCC Commits 2023-05-15 15:12:30 UTC
The releases/gcc-12 branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:396a4e76afec30d2461638f569cae18955eb4ad2

commit r12-9539-g396a4e76afec30d2461638f569cae18955eb4ad2
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 22 16:11:47 2023 -0400

    c++: local class in nested generic lambda [PR109241]
    
    In this testcase, the tree walk to look for bare parameter packs was
    confused by finding a type with no TREE_BINFO.  But it should be fine that
    it's unset; we already checked for unexpanded packs at parse time.
    
    I also tried doing the partial instantiation of the local class, which is
    probably the long-term direction we want to go, but for stage 4 let's go
    with this safer change.
    
            PR c++/109241
    
    gcc/cp/ChangeLog:
    
            * pt.cc (find_parameter_packs_r): Handle null TREE_BINFO.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1y/lambda-generic-local-class2.C: New test.
Comment 10 Andrew Pinski 2023-05-16 10:11:39 UTC
*** Bug 109872 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2023-06-19 12:42:10 UTC
*** Bug 110306 has been marked as a duplicate of this bug. ***
Comment 12 Richard Biener 2023-07-18 13:55:05 UTC
Closing again.
Comment 13 Andrew Pinski 2024-04-13 08:11:11 UTC
*** Bug 106398 has been marked as a duplicate of this bug. ***
Comment 14 Andrew Pinski 2024-05-22 19:13:48 UTC
*** Bug 115195 has been marked as a duplicate of this bug. ***