public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error
@ 2021-07-08 5:44 warren_graeme at yahoo dot co.uk
2021-07-08 7:42 ` [Bug c++/101371] " rguenth at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: warren_graeme at yahoo dot co.uk @ 2021-07-08 5:44 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
@ 2021-07-08 7:42 ` rguenth at gcc dot gnu.org
2021-07-08 13:50 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-08 7:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-07-08
Status|UNCONFIRMED |NEW
Known to fail| |12.0
Ever confirmed|0 |1
Version|unknown |10.3.1
Keywords| |ice-on-valid-code
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Also fails on trunk. clang accepts it.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
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
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-08 13:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Reduced, even g++ 7 ICEs. We only ICE with -std=c++14.
struct berry_set_CX;
template <int _Nm> struct __array_traits { typedef berry_set_CX _Type[_Nm]; };
template <int _Nm> struct array {
typename __array_traits<_Nm>::_Type _M_elems;
};
struct _Base_bitset {
long _M_w;
};
struct berry_set_CX {
_Base_bitset bset;
constexpr berry_set_CX() : bset() {}
constexpr berry_set_CX(berry_set_CX &rhs) : bset(rhs.bset) {}
};
struct bersets_by_citrus_CX {
array<8> berrysets;
};
struct entree0_CX {
constexpr entree0_CX(bersets_by_citrus_CX) {}
};
struct berrybox_CX {
constexpr entree0_CX make_entree() const {
bersets_by_citrus_CX bsbc{};
return bsbc;
}
berrybox_CX(berry_set_CX);
};
void init() {
berry_set_CX fixed;
berrybox_CX nu_cs0(fixed);
entree0_CX pas = nu_cs0.make_entree();
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
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
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-08 14:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The ICE started with r247813.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (2 preceding siblings ...)
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
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-09 0:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Reduced more:
struct A {
int i;
};
struct B {
A a{};
constexpr B() : a() {}
constexpr B(const B &rhs) : a(rhs.a) {}
};
struct C {
B arr[1];
};
constexpr C
fn ()
{
C c{};
return c;
}
C c = fn();
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10/11/12 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (3 preceding siblings ...)
2021-07-09 0:33 ` mpolacek at gcc dot gnu.org
@ 2021-07-09 0:38 ` mpolacek at gcc dot gnu.org
2021-07-09 0:38 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-09 0:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.5
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Summary|constexpr expansions |[9/10/11/12 Regression]
|trigger internal Compiler |constexpr expansions
|Error |trigger internal Compiler
| |Error
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
...which started with my r272217.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10/11/12 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (4 preceding siblings ...)
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
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-09 0:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10/11/12 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (5 preceding siblings ...)
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
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-10 2:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
And this should compile fine but doesn't since r269078:
struct A {
int i;
};
struct B {
A a{};
constexpr B() : a() {}
constexpr B(const B &rhs) : a(rhs.a) {}
};
struct C {
B arr[1];
};
constexpr C
fn ()
{
C c{};
return c;
}
constexpr C c = fn();
$ ./cc1plus -quiet 101371.C
101371.C:20:20: in ‘constexpr’ expansion of ‘fn()()’
101371.C:17:10: in ‘constexpr’ expansion of ‘C(c)’
101371.C:20:20: in ‘constexpr’ expansion of ‘B(<anonymous>.C::arr[0])’
101371.C:20:20: in ‘constexpr’ expansion of ‘B()’
101371.C:20:20: error: accessing value of ‘<anonymous>.B::a’ through a ‘B’
glvalue in a constant expression
20 | constexpr C c = fn();
| ^
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10/11 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (6 preceding siblings ...)
2021-07-10 2:40 ` mpolacek at gcc dot gnu.org
@ 2021-07-14 15:56 ` 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
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-14 15:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12 Regression] |[9/10/11 Regression]
|constexpr expansions |constexpr expansions
|trigger internal Compiler |trigger internal Compiler
|Error |Error
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10/11 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (7 preceding siblings ...)
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
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-29 1:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:da47a84e277c7fbeebbf9c1e7dc1e8ba3277fe53
commit r11-9710-gda47a84e277c7fbeebbf9c1e7dc1e8ba3277fe53
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Jul 13 17:16:54 2021 -0400
c++: constexpr array reference and value-initialization [PR101371]
This PR gave me a hard time: I saw multiple issues starting with
different revisions. But ultimately the root cause seems to be
the following, and the attached patch fixes all issues I've found
here.
In cxx_eval_array_reference we create a new constexpr context for the
CP_AGGREGATE_TYPE_P case, but we also have to create it for the
non-aggregate case. In this test, we are evaluating
((B *)this)->a = rhs->a
which means that we set ctx.object to ((B *)this)->a. Then we proceed
to evaluate the initializer, rhs->a. For *rhs, we eval rhs, a PARM_DECL,
for which we have (const B &) &c.arr[0] in the hash table. Then
cxx_fold_indirect_ref gives us c.arr[0]. c is evaluated to {.arr={}} so
c.arr is {}. Now we want c.arr[0], so we end up in
cxx_eval_array_reference
and since we're initializing from {}, we call build_value_init which
gives us an AGGR_INIT_EXPR that calls 'constexpr B::B()'. Then we
evaluate this AGGR_INIT_EXPR and since its first argument is dummy,
we take ctx.object instead. But that is the wrong object, we're not
initializing ((B *)this)->a here. And so we wound up with an
initializer for A, and then crash in cxx_eval_component_reference:
gcc_assert (DECL_CONTEXT (part) == TYPE_MAIN_VARIANT (TREE_TYPE
(whole)));
where DECL_CONTEXT (part) is B (as it should be) but the type of whole
was A.
So create a new object, if there already was one, and the element type
is not a scalar.
PR c++/101371
gcc/cp/ChangeLog:
* constexpr.c (cxx_eval_array_reference): Create a new .object
and .ctor for the non-aggregate non-scalar case too when
value-initializing.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-101371-2.C: New test.
* g++.dg/cpp1y/constexpr-101371.C: New test.
(cherry picked from commit a42f8120442cf3ba25d621bed857b5be19019d0c)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/101371] [9/10 Regression] constexpr expansions trigger internal Compiler Error
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
` (8 preceding siblings ...)
2022-03-29 1:44 ` cvs-commit at gcc dot gnu.org
@ 2022-03-29 1:47 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-29 1:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Summary|[9/10/11 Regression] |[9/10 Regression] constexpr
|constexpr expansions |expansions trigger internal
|trigger internal Compiler |Compiler Error
|Error |
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-03-29 1:47 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 5:44 [Bug c++/101371] New: constexpr expansions trigger internal Compiler Error warren_graeme at yahoo dot co.uk
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
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).