https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128202
Bug ID: 128202
Summary: ICE when the contract violation handler is declared
consteval
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: programmer00001h at gmail dot com
Target Milestone: ---
Created attachment 65980
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65980&action=edit
output of -freport-bug
For the following code, saved as ice.cpp:
#include<contracts>
consteval void handle_contract_violation(const
std::contracts::contract_violation&){}
int main(){
contract_assert(false);
}
g++ -std=c++26 ice.cpp causes the following crash:
ice.cpp: In function ‘void __tu_has_violation(const
__builtin_contract_violation_type&, short unsigned int)’:
ice.cpp:5:1: internal compiler error: in build_call_a, at cp/call.cc:393
5 | }
| ^
0x2815bf8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2818207 internal_error(char const*, ...)
???:0
0x7379dd fancy_abort(char const*, int, char const*)
???:0
0x7437c1 build_call_n(tree_node*, int, ...)
???:0
0x7d7a8e maybe_emit_violation_handler_wrappers()
???:0
0x82eaba c_parse_final_cleanups()
???:0
0xaa564a c_common_parse_file()
???:0
When a contract evaluation semantic is explicitly specified via
-fcontract-evaluation-semantic, the `observe` and `enforce` semantics trigger
the bug while `ignore` and `quick_enforce` don't (which is reasonable, only
observe and enforce will actually need to call the violation handler)
Output of gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260810 (GCC)