Bug 115165 - ICE on -ftime-report with module and c++2b
Summary: ICE on -ftime-report with module and c++2b
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.2
Assignee: Nathaniel Shead
URL:
Keywords:
Depends on:
Blocks: c++-modules
  Show dependency treegraph
 
Reported: 2024-05-20 17:15 UTC by porten
Modified: 2024-07-18 03:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description porten 2024-05-20 17:15:19 UTC
Purely by accident, I ran into an ICE when using -ftime-report on a file including a system header with a .gcm file of that header present. The scenario appeared after an attempt to improve compilation speed.

timevar.cc line 490 performs gcc_assert (!tv->standalone).

Note 1: A combination of #include <x> with x.gcm present may be unsupported.

Note 2: The error goes away when compiling with c++2a or c++20 rather than c++2b.

$ cat main.cpp
#include <iostream>
int main(int, char **) { std::cout; }

$ g++ -fmodules-ts -std=c++2b -x c++-system-header iostream

$ g++ -ftime-report -fmodules-ts -std=c++2b main.cpp
main.cpp: In destructor ‘std::__codecvt_abstract_base<_InternT, _ExternT, _StateT>::~__codecvt_abstract_base() [with _InternT = char16_t; _ExternT = char; _StateT = __mbstate_t]’:
main.cpp:2:31: internal compiler error: in start, at timevar.cc:490
    2 | int main(int, char **) { std::cout; }
      |                               ^~~~
0x74294d timer::start(timevar_id_t)
	/home/user/git/gcc/gcc/timevar.cc:490
0x74294d timer::start(timevar_id_t)
	/home/user/git/gcc/gcc/timevar.cc:481
0x74294d timevar_start(timevar_id_t)
	/home/user/git/gcc/gcc/timevar.cc:475
0x87b7ec lazy_load_pendings(tree_node*)
	/home/user/git/gcc/gcc/cp/module.cc:19470
0x881c48 maybe_lazily_declare
	/home/user/git/gcc/gcc/cp/name-lookup.cc:2002
0x881c48 get_class_binding(tree_node*, tree_node*, bool)
	/home/user/git/gcc/gcc/cp/name-lookup.cc:2038
0x9342fd lookup_field_r
	/home/user/git/gcc/gcc/cp/search.cc:1061
0x934c18 dfs_walk_all(tree_node*, tree_node* (*)(tree_node*, void*), tree_node* (*)(tree_node*, void*), void*)
	/home/user/git/gcc/gcc/cp/search.cc:1507
0x934c18 lookup_member(tree_node*, tree_node*, int, bool, int, access_failure_info*)
	/home/user/git/gcc/gcc/cp/search.cc:1216
0x9350d0 lookup_fnfields(tree_node*, tree_node*, int, int)
	/home/user/git/gcc/gcc/cp/search.cc:1426
0x773277 build_op_delete_call(tree_code, tree_node*, tree_node*, bool, tree_node*, tree_node*, int)
	/home/user/git/gcc/gcc/cp/call.cc:7864
0x892372 build_delete_destructor_body
	/home/user/git/gcc/gcc/cp/optimize.cc:140
0x893738 maybe_clone_body(tree_node*)
	/home/user/git/gcc/gcc/cp/optimize.cc:610
0x85f01f post_load_processing
	/home/user/git/gcc/gcc/cp/module.cc:17758
0x877793 lazy_load_binding(unsigned int, tree_node*, tree_node*, binding_slot*)
	/home/user/git/gcc/gcc/cp/module.cc:19424
0x889b64 name_lookup::search_namespace_only(tree_node*)
	/home/user/git/gcc/gcc/cp/name-lookup.cc:920
0x889ca4 name_lookup::search_namespace(tree_node*)
	/home/user/git/gcc/gcc/cp/name-lookup.cc:1006
0x889f8f name_lookup::search_namespace(tree_node*)
	/home/user/git/gcc/gcc/cp/name-lookup.cc:1001
0x889f8f name_lookup::search_qualified(tree_node*, bool)
	/home/user/git/gcc/gcc/cp/name-lookup.cc:1067
0x88d161 qualified_namespace_lookup
	/home/user/git/gcc/gcc/cp/name-lookup.cc:7278
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.

GCC was built with today's state of the releases/gcc-14 branch. 

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc-14/libexec/gcc/x86_64-pc-linux-gnu/14.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/porten/git/gcc/configure --disable-multilib --prefix=/opt/gcc-14 --enable-languages=c,c++ : (reconfigured) /home/porten/git/gcc/configure --disable-multilib --prefix=/opt/gcc-14 --enable-languages=c,c++ : (reconfigured) /home/porten/git/gcc/configure --disable-multilib --prefix=/opt/gcc-14 --enable-languages=c,c++,lto --no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.1.1 20240520 (GCC)
Comment 1 Marek Polacek 2024-05-20 17:17:53 UTC
Confirmed.
Comment 2 GCC Commits 2024-07-18 03:07:56 UTC
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

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

commit r15-2121-gb7b2434cc7e712dc5055bde02c441393ae881f06
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sun Jul 7 23:19:52 2024 +1000

    c++/modules: Conditionally start timer during lazy load [PR115165]
    
    While lazy loading, instantiation of pendings can sometimes recursively
    perform name lookup and begin further lazy loading.  When using the
    '-ftime-report' functionality this causes ICEs as we could start an
    already-running timer for the importing.
    
    This patch fixes the issue by using the 'timevar_cond*' API instead to
    support such recursive calls.
    
            PR c++/115165
    
    gcc/cp/ChangeLog:
    
            * module.cc (lazy_load_binding): Use 'timevar_cond*' APIs.
            (lazy_load_pendings): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/timevar-1_a.H: New test.
            * g++.dg/modules/timevar-1_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Comment 3 GCC Commits 2024-07-18 03:08:51 UTC
The releases/gcc-14 branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

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

commit r14-10453-gf0c3a1c16af234b55f48cf1cfe299417f93f163c
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sun Jul 7 23:19:52 2024 +1000

    c++/modules: Conditionally start timer during lazy load [PR115165]
    
    While lazy loading, instantiation of pendings can sometimes recursively
    perform name lookup and begin further lazy loading.  When using the
    '-ftime-report' functionality this causes ICEs as we could start an
    already-running timer for the importing.
    
    This patch fixes the issue by using the 'timevar_cond*' API instead to
    support such recursive calls.
    
            PR c++/115165
    
    gcc/cp/ChangeLog:
    
            * module.cc (lazy_load_binding): Use 'timevar_cond*' APIs.
            (lazy_load_pendings): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/timevar-1_a.H: New test.
            * g++.dg/modules/timevar-1_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Comment 4 Nathaniel Shead 2024-07-18 03:10:57 UTC
Fixed for GCC 14.2 / trunk.