Bug 95984 - [11 Regression] Internal compiler error: Error reporting routines re-entered. since r11-1697-g75ff24e1920ea6b1
Summary: [11 Regression] Internal compiler error: Error reporting routines re-entered....
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Martin Sebor
URL:
Keywords: ice-on-valid-code
: 96008 96107 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-06-29 18:36 UTC by Martin Liška
Modified: 2020-07-08 07:55 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-06-29 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 2020-06-29 18:36:16 UTC
Since the revision I see:

$ cat /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C
// PR c++/78816
// { dg-do compile { target c++14 } }

void f(void (*f1)(int)) {
  f1(42);
}

template <typename Lambda>
static auto callback(Lambda &&l)
{
  static auto* p = &l;
  p = &l;
  return [](auto... x){ return (*p)(x...); };
}

int main() {
  int x = 5;
  f(callback([=](int y){}));
}

$ g++ /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C -Wnonnull
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C: In substitution of ‘template<class ... auto:1> constexpr callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>::operator decltype (((const callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>*)0)->operator()<auto:1 ...>(static_cast<auto:1&&>(callback::._anon_2::_FUN::<unnamed>) ...)) (*)(auto:1 ...)() const [with auto:1 = {int}]’:
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C:18:27:   required from here
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C:13:10: warning: ‘this’ pointer null [-Wnonnull]
   13 |   return [](auto... x){ return (*p)(x...); };
      |          ^
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic6.C:13:10: note: in a call to non-static member function ‘callback<main()::<lambda(int)> >::<lambda(auto:1 ...)> [with auto:1 = {int}]’
‘
Internal compiler error: Error reporting routines re-entered.
0xb04ef1 check_nonnull_arg
	/home/marxin/Programming/gcc/gcc/c-family/c-common.c:5523
0xb05f72 check_function_arguments_recurse(void (*)(void*, tree_node*, unsigned long), void*, tree_node*, unsigned long)
	/home/marxin/Programming/gcc/gcc/c-family/c-common.c:5881
0xb05cd1 check_function_arguments_recurse(void (*)(void*, tree_node*, unsigned long), void*, tree_node*, unsigned long)
	/home/marxin/Programming/gcc/gcc/c-family/c-common.c:5813
0xb043e8 check_function_nonnull
	/home/marxin/Programming/gcc/gcc/c-family/c-common.c:5315
0xb05a9e check_function_arguments(unsigned int, tree_node const*, tree_node const*, int, tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
	/home/marxin/Programming/gcc/gcc/c-family/c-common.c:5764
0x867a94 build_over_call
	/home/marxin/Programming/gcc/gcc/cp/call.c:8868
0x869e3c build_new_method_call_1
	/home/marxin/Programming/gcc/gcc/cp/call.c:10348
0x86ad5f build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int)
	/home/marxin/Programming/gcc/gcc/cp/call.c:10423
0xa2b3f2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	/home/marxin/Programming/gcc/gcc/cp/pt.c:20042
0xa2d1c0 tsubst(tree_node*, tree_node*, int, tree_node*)
	/home/marxin/Programming/gcc/gcc/cp/pt.c:15913
0x935ad7 dump_template_bindings
	/home/marxin/Programming/gcc/gcc/cp/error.c:416
0x935d30 dump_substitution
	/home/marxin/Programming/gcc/gcc/cp/error.c:1562
0x935d30 dump_substitution
	/home/marxin/Programming/gcc/gcc/cp/error.c:1550
0x92f610 dump_function_decl
	/home/marxin/Programming/gcc/gcc/cp/error.c:1720
0x937178 decl_to_string
	/home/marxin/Programming/gcc/gcc/cp/error.c:3101
0x937178 cp_printer
	/home/marxin/Programming/gcc/gcc/cp/error.c:4261
0x1e2aafc pp_format(pretty_printer*, text_info*)
	/home/marxin/Programming/gcc/gcc/pretty-print.c:1475
0x1e2cb80 pp_format_verbatim(pretty_printer*, text_info*)
	/home/marxin/Programming/gcc/gcc/pretty-print.c:1536
0x1e2cb80 pp_verbatim(pretty_printer*, char const*, ...)
	/home/marxin/Programming/gcc/gcc/pretty-print.c:1790
0x92ce56 print_instantiation_full_context
	/home/marxin/Programming/gcc/gcc/cp/error.c:3503
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 Martin Sebor 2020-06-29 20:46:04 UTC
If I'm reading the dump right the front end constructs a lambda object and calls its member operator() with a null this pointer:

;; Function static decltype (((const callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>*)0)->operator()<auto:1 ...>(static_cast<auto:1&&>(callback::._anon_2::_FUN::<unnamed>) ...)) callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>::_FUN(auto:1 ...) [with auto:1 = {int}; decltype (((const callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>*)0)->operator()<auto:1 ...>(static_cast<auto:1&&>(callback::._anon_2::_FUN::<unnamed>) ...)) = void] (null)
;; enabled by -tree-original


<<cleanup_point <<< Unknown tree: expr_stmt
  callback<main()::<lambda(int)> >::<lambda(auto:1 ...)>::operator()<int> (0B, D.2439) >>>>>;
return;

So it seems like the warning code is doing what it's supposed to.

The ICE is triggered by the C++ front end printing the instantiation context (print_instantiation_full_context), the pretty printer formatting the template specialization, calling into the C++ front end to perform type substitution, and the FE ending up calling check_nonnull_arg() on the call, which ends up triggering the warning and re-entering the diagnostic machinery.  There is nothing out of the ordinary the warning does to do this so it must be a latent problem in the C++ front end that the warning exposed.  I expect Jason or Marek have seen and deal with something like this before.
Comment 2 Martin Sebor 2020-06-30 17:57:12 UTC
*** Bug 96008 has been marked as a duplicate of this bug. ***
Comment 3 Martin Sebor 2020-07-01 16:37:44 UTC
I'm testing a fix.
Comment 4 GCC Commits 2020-07-06 21:24:54 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:67a493a0b9e7ce6caba4b8bedf1f3295e477ec00

commit r11-1860-g67a493a0b9e7ce6caba4b8bedf1f3295e477ec00
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Jul 6 15:23:37 2020 -0600

    Exclude calls to variadic lambda stubs from -Wnonnull checking (PR c++/95984).
    
    Resolves:
    PR c++/95984 - Internal compiler error: Error reporting routines re-entered in -Wnonnull on a variadic lamnda
    PR c++/96021 - missing -Wnonnull passing nullptr to a nonnull variadic lambda
    
    gcc/c-family/ChangeLog:
    
            PR c++/95984
            * c-common.c (check_function_nonnull): Avoid checking syntesized calls
            to stub lambda objects with null this pointer.
            (check_nonnull_arg): Handle C++ nullptr.
    
    gcc/cp/ChangeLog:
    
            PR c++/95984
            * call.c (build_over_call): Check calls only when tf_warning is set.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95984
            * g++.dg/warn/Wnonnull6.C: New test.
Comment 5 Martin Sebor 2020-07-06 21:25:50 UTC
Fixed by r11-1860.
Comment 6 Sergei Trofimovich 2020-07-08 07:55:03 UTC
*** Bug 96107 has been marked as a duplicate of this bug. ***