https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125574
Bug ID: 125574
Summary: [contracts] ICE when calling post twice in function
returning struct
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ulf.iversen at gmail dot com
Target Milestone: ---
If I have a function that returns a struct and that function have two post()
contracts, GCC 16 fails with an internal compiler error.
Minimal repro:
```
struct Vec {};
// Must be Vec&, Vec compiles
bool ok(const Vec&) {
return true;
}
Vec f()
post(r: true)
post(r: ok(r))
{
return {};
}
```
g++-16 -std=c++26 -fcontracts -c ice_main.cpp
during RTL pass: expand
ice_main.cpp: In function ‘Vec f()’:
ice_main.cpp:10:15: internal compiler error: in expand_expr_addr_expr_1, at
expr.cc:9318
10 | post(r: ok(r))
| ~~^~~
0x175b4d4 internal_error(char const*, ...)
../../src/gcc/diagnostic-global-context.cc:787
0x175f96b fancy_abort(char const*, int, char const*)
../../src/gcc/diagnostics/context.cc:1813
0xa87330 expand_expr_addr_expr_1
../../src/gcc/expr.cc:9318
0x1ba16cf expand_expr_addr_expr
../../src/gcc/expr.cc:9431
0x2192f84 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool) [clone .constprop.3]
../../src/gcc/expr.cc:12921
0x1ecca33 expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier,
rtx_def**, bool)
../../src/gcc/expr.cc:9619
0x1ecca33 expand_normal(tree_node*)
../../src/gcc/expr.h:329
0x1ecca33 precompute_register_parameters
../../src/gcc/calls.cc:1022
0x1ec20ce expand_call(tree_node*, rtx_def*, int)
../../src/gcc/calls.cc:3492
0x1b9c7e0 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool) [clone .constprop.1]
../../src/gcc/expr.cc:12678
0x1c8f3d5 expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier,
rtx_def**, bool)
../../src/gcc/expr.cc:9619
0x1c8f3d5 store_expr(tree_node*, rtx_def*, int, bool, bool) [clone
.constprop.0]
../../src/gcc/expr.cc:6803
0x1c88a9a expand_assignment(tree_node*, tree_node*, bool)
../../src/gcc/expr.cc:6499
0x1c878d1 expand_call_stmt
../../src/gcc/cfgexpand.cc:3203
0x1c878d1 expand_gimple_stmt_1
../../src/gcc/cfgexpand.cc:4243
0x1c878d1 expand_gimple_stmt
../../src/gcc/cfgexpand.cc:4390
0x1c24af2 expand_gimple_basic_block
../../src/gcc/cfgexpand.cc:6507
0x1c24af2 execute
../../src/gcc/cfgexpand.cc:7254
/usr/libexec/gcc/x86_64-linux-gnu/16/cc1plus -quiet -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE ice_main.cpp -quiet -dumpbase ice_main.cpp
-dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++26 -fcontracts
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection
-fzero-init-padding-bits=all -Wbidi-chars=any -o /tmp/ccdelcZ9.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-16/README.Bugs> for instructions.
---
g++-16 -v
Using built-in specs.
COLLECT_GCC=g++-16
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
16-20260322-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-16/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust,cobol,algol68
--prefix=/usr --with-gcc-major-version-only --program-suffix=-16
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-16-UBzkgO/gcc-16-16-20260322/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-16-UBzkgO/gcc-16-16-20260322/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.1 20260322 (experimental) [trunk r16-8246-g569ace1fa50]
(Ubuntu 16-20260322-1ubuntu1)
---
If I combine the two to a single post() using post(cond1 && cond2) it works.
Free functions and member functions behave the same.
Postcondition order does not appear to matter.
The function ok(const Vec&) must take a reference in the repro, but I've also
returned a std::vector where I got the same error when checking post(r: not
r.empty()) post(r: r.back() == 2).