public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "warren_graeme at yahoo dot co.uk" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error
Date: Thu, 08 Jul 2021 05:44:16 +0000	[thread overview]
Message-ID: <bug-101371-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 101371
           Summary: constexpr expansions trigger internal Compiler Error
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: warren_graeme at yahoo dot co.uk
  Target Milestone: ---

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

Hello,

When attempting to compile a C++ function with gcc I have triggered an Internal
Compiler Error. I achieved this with the following commands:

g++-7 --std=c++17 -E init.cc > init.ii
g++-7 --std=c++17 -c init.ii



1) the peccant function (init.cc) follows:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <array>
#include <bitset>
using namespace std;

constexpr unsigned short N_citruss = 8;

enum class berry: unsigned{cran, straw, rasp, bil, black, huckle, elder,
goose};
constexpr berry operator++(berry& b, int) noexcept {
        return b = berry(static_cast<int>(b) + 1); }

struct berry_set_CX{
        bitset<8> bset;
        constexpr berry_set_CX(const bitset<8>& bits) noexcept: bset(bits) {}
        constexpr berry_set_CX(const char  bits) noexcept: bset(bits) {}
        constexpr berry_set_CX() noexcept : bset() {}
        constexpr berry_set_CX(const berry_set_CX& rhs) noexcept :
bset(rhs.bset) {}
};

struct bersets_by_citrus_CX{
        array<berry_set_CX, N_citruss> berrysets;
};

struct entree0_CX{
        bersets_by_citrus_CX passes;
        constexpr entree0_CX(const bersets_by_citrus_CX& bsbc) noexcept :
passes(bsbc) {}
};

struct berrybox_CX{
        constexpr entree0_CX make_entree() const noexcept {
                bersets_by_citrus_CX bsbc {};
                return entree0_CX(bsbc);
        }
        constexpr berrybox_CX(berry w, berry_set_CX hs) noexcept {}
};

void init() noexcept{
        const berry_set_CX fixed(bitset<8>(1));
        for (berry root_berry = berry::cran; root_berry <= berry::goose;
root_berry++){
                berrybox_CX nu_cs0(root_berry, fixed);
                const entree0_CX& pas = nu_cs0.make_entree();
        }
        return;
}
--------------------------------------------------------------------------

2) the preprocessed source file (init.ii) is attached;

3) the compiler version used (gcc -v output)  is:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=hsa:nvptx-none
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,ada,go
--enable-offload-targets=hsa,nvptx-none, --without-cuda-driver
--enable-checking=release --disable-werror
--with-gxx-include-dir=/usr/include/c++/7 --enable-ssp --disable-libssp
--disable-libvtv --disable-libcc1 --disable-plugin
--with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --enable-version-specific-runtime-libs
--with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex
--enable-gnu-indirect-function --program-suffix=-7 --without-system-libunwind
--enable-multilib --with-arch-32=x86-64 --with-tune=generic
--build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
gcc version 7.5.0 (SUSE Linux) 

--------------------------------------------------------------------------

4) the compiler output is:

i+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
init.cc: In function ‘void init()’:
init.cc:40:46:   in constexpr expansion of ‘berrybox_CX::make_entree() const()’
init.cc:40:46:   in constexpr expansion of ‘entree0_CX(((const
bersets_by_citrus_CX&)(& bsbc)))’
init.cc:25:79:   in constexpr expansion of
‘((entree0_CX*)this)->entree0_CX::passes.bersets_by_citrus_CX::bersets_by_citrus_CX(bsbc)’
init.cc:19:8:   in constexpr expansion of
‘((bersets_by_citrus_CX*)this)->bersets_by_citrus_CX::berrysets.std::array<berry_set_CX,
8>::array(bersets_by_citrus_CX::berrysets)’
init.cc:40:46:   in constexpr expansion of
‘berry_set_CX(std::array<berry_set_CX, 8>::_M_elems[0])’
init.cc:40:46: internal compiler error: in cxx_eval_component_reference, at
cp/constexpr.c:2479
   const entree0_CX& pas = nu_cs0.make_entree();
                                              ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.opensuse.org/> for instructions.

--------------------------------------------------------------------------

Initially the program which incorporated this function was developed under
OpenSuse Leap 42.3 . The default compiler on that OS did not support the
constexpr functionality I needed, so I installed g++-7 and used that. The code,
including this function, compiled (and ran) correctly.

Later I upgraded to OpenSuse Leap 15.2, my present OS; and as I had not changed
my code I was not expecting trouble. But it fell over as described. I was
puzzled as I was using the 15.2 default compiler, namely  g++-7. 

However I see now that there has been more than one edition of gcc-7, so if I
had silently changed from an earlier to a later version, there could be changes
which trigger the ICE. Unfortunately I no longer have Leap 42.3 so have no
record of which edition of gcc-7 I used then. 

I have tried compiling with gccs -8, -9 and -10: they all produce the same
output as gcc-7 above, except with different line numbers in "constexpr.c".

Yours faithfully,

Graeme A. Warren

             reply	other threads:[~2021-07-08  5:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08  5:44 warren_graeme at yahoo dot co.uk [this message]
2021-07-08  7:42 ` [Bug c++/101371] " rguenth at gcc dot gnu.org
2021-07-08 13:50 ` mpolacek at gcc dot gnu.org
2021-07-08 14:30 ` mpolacek at gcc dot gnu.org
2021-07-09  0:33 ` mpolacek at gcc dot gnu.org
2021-07-09  0:38 ` [Bug c++/101371] [9/10/11/12 Regression] " mpolacek at gcc dot gnu.org
2021-07-09  0:38 ` mpolacek at gcc dot gnu.org
2021-07-10  2:40 ` mpolacek at gcc dot gnu.org
2021-07-14 15:56 ` [Bug c++/101371] [9/10/11 " mpolacek at gcc dot gnu.org
2022-03-29  1:44 ` cvs-commit at gcc dot gnu.org
2022-03-29  1:47 ` [Bug c++/101371] [9/10 " mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101371-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).