https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128064
Bug ID: 128064
Summary: ICE (segfault) using a precompiled header that defines
a function with a nested function
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: pch
Assignee: unassigned at gcc dot gnu.org
Reporter: yqtian668 at gmail dot com
Target Milestone: ---
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Created attachment 65912
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65912&action=edit
Reproducer and complete GCC 16.2 / trunk sessions
A precompiled header that defines a function containing a GNU C nested
function makes the compilation that uses it crash. The PCH is built and
used with the same options; without the PCH the program compiles and
runs. The sources need no preprocessing (no #include other than h.h).
Complete session (GCC 16.2.0), including gcc -v, all output and every
exit status:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-gnu/16.2.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: /usr/src/gcc/configure --build=x86_64-linux-gnu
--disable-multilib --enable-languages=c,c++,fortran,go
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.0 (GCC)
$ cat h.h
int outer (int x) { int inner (int y) { return y + x; } return inner (1); }
$ cat t.c
#include "h.h"
int main (void) { return outer (2) != 3; }
$ gcc -O2 t.c -o textual
[exit status: 0]
$ ./textual
[exit status: 0]
$ gcc -O2 -x c-header h.h -o h.h.gch
[exit status: 0]
$ gcc -O2 -Winvalid-pch -H t.c -o pch
! h.h.gch
t.c
t.c:2:1: internal compiler error: Segmentation fault
2 | int main (void) { return outer (2) != 3; }
| ^~~
0x221d376 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x221633f internal_error(char const*, ...)
???:0
0x9a0443 symbol_table::add_cgraph_removal_hook(void (*)(cgraph_node*, void*),
void*)
???:0
0xdb7a76 execute_ipa_pass_list(opt_pass*)
???:0
0x9b3e22 symbol_table::finalize_compilation_unit()
???:0
/usr/local/libexec/gcc/x86_64-linux-gnu/16.2.0/cc1 -quiet -imultiarch
x86_64-linux-gnu -H t.c -quiet -dumpdir pch- -dumpbase t.c -dumpbase-ext .c
-mtune=generic -march=x86-64 -O2 -Winvalid-pch -o /tmp/cc7BbrRG.s
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.
[exit status: 1]
The same happens at -O0, with GCC 13.5.0 and with trunk (17.0.0 20260905,
configured with --enable-checking=yes; output attached). Passing the
nested function's address elsewhere (trampoline) crashes the same way.