https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126038

            Bug ID: 126038
           Summary: [contracts] Internal compiler error in
                    gimplify_var_or_parm_decl, at gimplify.cc:3426 via
                    lambda contract captures
           Product: gcc
           Version: 16.1.1
               URL: https://github.com/Zuhaitz-dev/cpp26-contracts/tree/ma
                    in/bugs
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zuhaitz.zechhub at gmail dot com
  Target Milestone: ---
              Host: x86_64-redhat-linux
            Target: x86_64-redhat-linux
             Build: x86_64-redhat-linux

Created attachment 64896
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64896&action=edit
Preprocessed source.

Placing a C++26 pre() or post() contract condition on a C++11 lambda expression
that captures variables from the surrounding local scope by reference (or
value) triggers an Internal Compiler Error (ICE). The middle-end fails to
properly resolve captured variables within the compiler-synthesized contract
validation block during the Gimplification phase.

EXACT GCC VERSION:
gcc version 16.1.1 20260515 (Red Hat 16.1.1-2) (GCC) 

SYSTEM TYPE / TARGET:
Target: x86_64-redhat-linux

CONFIGURE OPTIONS:
../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,cobol,algol68,lto
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugzilla.redhat.com/ --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-16.1.1-build/gcc-16.1.1-20260515/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-tls=gnu2 --with-arch_32=i686
--build=x86_64-redhat-linux --with-build-config=bootstrap-lto
--enable-link-serialization=1 --disable-libssp

COMPLETE COMMAND LINE TRIGGERING THE BUG:
g++ -std=c++26 -fcontracts -save-temps bug_lambda_ice.cpp

COMPILER OUTPUT:
bug_lambda_ice.cpp: In lambda function:
bug_lambda_ice.cpp:5:56: internal compiler error: in gimplify_var_or_parm_decl,
at gimplify.cc:3426
    5 |      auto dynamic_check = [&limit](int value) pre(value < limit) {};
      |                                                   ~~~~~~^~~~~~~
/usr/libexec/gcc/x86_64-redhat-linux/16/cc1plus -fpreprocessed
a-bug_lambda_ice.ii -quiet -dumpdir a- -dumpbase bug_lambda_ice.cpp
-dumpbase-ext .cpp -mtune=generic -march=x86-64 -mtls-dialect=gnu2 -std=c++26
-fcontracts -foffload-options=-l_GCC_stdc++ -foffload-options=-l_GCC_m -o
a-bug_lambda_ice.s

MINIMAL STANDALONE SOURCE CODE:
#include <contracts>

int main() {
    int limit = 10;
    auto dynamic_check = [&limit](int value) pre(value < limit) {};
    dynamic_check(5);
}
  • [Bug c++/126038] New: [contr... zuhaitz.zechhub at gmail dot com via Gcc-bugs

Reply via email to