Bug 95560 - [8/11 Regression] ICE in comptypes, at cp/typeck.c:1498 since r7-4206-g84ff4775d41b716c
Summary: [8/11 Regression] ICE in comptypes, at cp/typeck.c:1498 since r7-4206-g84ff47...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.1.0
: P3 normal
Target Milestone: 8.5
Assignee: Marek Polacek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-06-06 10:02 UTC by RJE
Modified: 2020-06-16 17:12 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.1.0
Last reconfirmed: 2020-06-09 00:00:00


Attachments
C++ program to compile (3.56 KB, text/plain)
2020-06-06 10:02 UTC, RJE
Details
Compile information .ii file compressed (197.71 KB, application/x-7z-compressed)
2020-06-06 10:10 UTC, RJE
Details
assembler source (30 bytes, text/plain)
2020-06-06 10:12 UTC, RJE
Details

Note You need to log in before you can comment on or make changes to this bug.
Description RJE 2020-06-06 10:02:11 UTC
Created attachment 48690 [details]
C++ program to compile

g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=d:/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/d/temp/gcc/dest --with-sysroot=/d/temp/gcc/dest --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls --disable-shared --disable-win32-registry --with-architechture=native --enable-threads=posix --enable-libgomp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC)


g++ -std=c++20 -Wall -Wextra test_cv.cpp
test_cv.cpp: In function 'void testTimedIWait(bool, bool, Dur)':
test_cv.cpp:464:28: internal compiler error: Segmentation fault
  464 |   enum class State { loop, ready, interrupted };
      |                            ^~~~~
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 RJE 2020-06-06 10:10:36 UTC
Created attachment 48691 [details]
Compile information .ii file compressed
Comment 2 RJE 2020-06-06 10:12:00 UTC
Created attachment 48692 [details]
assembler source
Comment 3 Martin Liška 2020-06-09 12:00:14 UTC
Confirmed, started with r10-4254-ge0d91792eec490d1.

Reduced test-case:

$ cat pr95560.ii
template <typename> void fn1() {
  bool ready;
  enum class State { ready };
}

$ g++ -c -std=c++2a pr95560.ii
pr95560.ii: In function ‘void fn1()’:
pr95560.ii:3:22: internal compiler error: in comptypes, at cp/typeck.c:1498
    3 |   enum class State { ready };
      |                      ^~~~~
0x6be442 comptypes(tree_node*, tree_node*, int)
	/home/marxin/Programming/gcc/gcc/cp/typeck.c:1498
0x9ab7ea check_local_shadow
	/home/marxin/Programming/gcc/gcc/cp/name-lookup.c:2765
0x9ab7ea do_pushdecl
	/home/marxin/Programming/gcc/gcc/cp/name-lookup.c:3112
0x9ac140 pushdecl(tree_node*, bool)
	/home/marxin/Programming/gcc/gcc/cp/name-lookup.c:3177
0x93c722 build_enumerator(tree_node*, tree_node*, tree_node*, tree_node*, unsigned int)
	/home/marxin/Programming/gcc/gcc/cp/decl.c:15922
0x9cd7a7 cp_parser_enumerator_definition
	/home/marxin/Programming/gcc/gcc/cp/parser.c:19544
0x9cd7a7 cp_parser_enumerator_list
	/home/marxin/Programming/gcc/gcc/cp/parser.c:19473
0x9cd7a7 cp_parser_enum_specifier
	/home/marxin/Programming/gcc/gcc/cp/parser.c:19404
0x9cd7a7 cp_parser_type_specifier
	/home/marxin/Programming/gcc/gcc/cp/parser.c:17734
0x9cdd62 cp_parser_decl_specifier_seq
	/home/marxin/Programming/gcc/gcc/cp/parser.c:14410
0x9ce941 cp_parser_simple_declaration
	/home/marxin/Programming/gcc/gcc/cp/parser.c:13664
0x9d07ea cp_parser_declaration_statement
	/home/marxin/Programming/gcc/gcc/cp/parser.c:13217
0x9d146a cp_parser_statement
	/home/marxin/Programming/gcc/gcc/cp/parser.c:11523
0x9d2398 cp_parser_statement_seq_opt
	/home/marxin/Programming/gcc/gcc/cp/parser.c:11889
0x9d2478 cp_parser_compound_statement
	/home/marxin/Programming/gcc/gcc/cp/parser.c:11839
0x9e9a65 cp_parser_function_body
	/home/marxin/Programming/gcc/gcc/cp/parser.c:23110
0x9e9a65 cp_parser_ctor_initializer_opt_and_function_body
	/home/marxin/Programming/gcc/gcc/cp/parser.c:23161
0x9ecd9d cp_parser_function_definition_after_declarator
	/home/marxin/Programming/gcc/gcc/cp/parser.c:29057
0x9edd89 cp_parser_function_definition_from_specifiers_and_declarator
	/home/marxin/Programming/gcc/gcc/cp/parser.c:28973
0x9edd89 cp_parser_init_declarator
	/home/marxin/Programming/gcc/gcc/cp/parser.c:20721
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 4 Bernd Edlinger 2020-06-09 12:36:13 UTC
don't know if it helps, but with -Wshadow=compatible-local
the regression begins probably earlier.
Comment 5 Martin Liška 2020-06-09 12:50:39 UTC
You are right, with:
g++ pr95560.ii -std=c++17 -c -Wshadow=compatible-local

it started with r7-4206-g84ff4775d41b716c.
Comment 6 Marek Polacek 2020-06-10 18:50:31 UTC
We have a CONST_DECL with null type -- it's the case when the underlying type is not fixed, and finish_enum_value_list hasn't yet run.  A stopgap fix would be

--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2762,7 +2762,9 @@ check_local_shadow (tree decl)
       enum opt_code warning_code;
       if (warn_shadow)
    warning_code = OPT_Wshadow;
-      else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))
+      else if ((TREE_TYPE (old)
+       && TREE_TYPE (decl)
+       && same_type_p (TREE_TYPE (old), TREE_TYPE (decl)))
           || TREE_CODE (decl) == TYPE_DECL
           || TREE_CODE (old) == TYPE_DECL
           || (!dependent_type_p (TREE_TYPE (decl))
Comment 7 GCC Commits 2020-06-11 20:36:15 UTC
The releases/gcc-10 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:23dd42562369911a92d7da045ebe2c03b286a769

commit r10-8281-g23dd42562369911a92d7da045ebe2c03b286a769
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Jun 11 16:35:33 2020 -0400

    c++: Fix ICE in check_local_shadow with enum [PR95560]
    
    Another indication that perhaps this warning is emitted too early.  We
    crash because same_type_p gets a null type: we have an enumerator
    without a fixed underlying type and finish_enum_value_list hasn't yet
    run.  So check if the type is null before calling same_type_p.
    
            PR c++/95560
            * name-lookup.c (check_local_shadow): Check if types are
            non-null before calling same_type_p.
    
            * g++.dg/warn/Wshadow-local-3.C: New test.
Comment 8 GCC Commits 2020-06-11 22:36:39 UTC
The releases/gcc-9 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:02f6c5b711b8188c3f49a79c730911b0bd216585

commit r9-8668-g02f6c5b711b8188c3f49a79c730911b0bd216585
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Jun 11 17:58:21 2020 -0400

    c++: Fix ICE in check_local_shadow with enum [PR95560]
    
    Another indication that perhaps this warning is emitted too early.  We
    crash because same_type_p gets a null type: we have an enumerator
    without a fixed underlying type and finish_enum_value_list hasn't yet
    run.  So check if the type is null before calling same_type_p.
    
            PR c++/95560
            * name-lookup.c (check_local_shadow): Check if types are
            non-null before calling same_type_p.
    
            * g++.dg/warn/Wshadow-compatible-local-3.C: New test.
Comment 9 Marek Polacek 2020-06-11 22:37:09 UTC
Fixed.
Comment 10 Marek Polacek 2020-06-11 22:37:30 UTC
Actually not on trunk yet.
Comment 11 GCC Commits 2020-06-16 17:09:29 UTC
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:2661635323bd44410f1a154683eccecd2c163b46

commit r11-1391-g2661635323bd44410f1a154683eccecd2c163b46
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jun 16 13:02:23 2020 -0400

    c++: Fix ICE in check_local_shadow with enum [PR95560]
    
    Another indication that perhaps this warning is emitted too early.  We
    crash because same_type_p gets a null type: we have an enumerator
    without a fixed underlying type and finish_enum_value_list hasn't yet
    run.  So check if the type is null before calling same_type_p.
    
            PR c++/95560
            * name-lookup.c (check_local_shadow): Check if types are
            non-null before calling same_type_p.
    
            * g++.dg/warn/Wshadow-local-3.C: New test.
Comment 12 Marek Polacek 2020-06-16 17:12:47 UTC
Fixed.