public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union
@ 2024-04-12 20:13 cuzdav at gmail dot com
2024-04-12 20:17 ` [Bug c++/114706] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: cuzdav at gmail dot com @ 2024-04-12 20:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Bug ID: 114706
Summary: ICE - std::bit_cast in consteval function involving
union
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cuzdav at gmail dot com
Target Milestone: ---
ICE in a consteval function bit_casting an array of unions. The code isn't
valid due to the union, but the compiler is not handling it properly (since
gcc11...trunk). Reduced to the following program:
CODE
#include <bit>
union U { int u; };
consteval void f() {
U result[]{0, 0};
auto x = std::bit_cast<long>(result);
}
int main() { f(); }
LIVE:
https://godbolt.org/z/Y943bc5zK
OUTPUT
/opt/compiler-explorer/gcc-trunk-20240412/include/c++/14.0.1/bit:94:33:
internal compiler error: in native_encode_initializer, at fold-const.cc:8468
94 | return __builtin_bit_cast(_To, __from);
| ^~~
0x267826c internal_error(char const*, ...)
???:0
0xa58c63 fancy_abort(char const*, int, char const*)
???:0
0xfa0eaf native_encode_initializer(tree_node*, unsigned char*, int, int,
unsigned char*)
???:0
0xacf0f0 maybe_constant_value(tree_node*, tree_node*, mce_value)
???:0
0xd3a75f store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xb474fe cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???:0
0xc5c81a c_parse_file()
???:0
0xdb1489 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/114706] ICE - std::bit_cast in consteval function involving union
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
@ 2024-04-12 20:17 ` pinskia at gcc dot gnu.org
2024-04-12 20:21 ` [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-12 20:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2024-04-12
Keywords| |ice-on-invalid-code
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
2024-04-12 20:17 ` [Bug c++/114706] " pinskia at gcc dot gnu.org
@ 2024-04-12 20:21 ` pinskia at gcc dot gnu.org
2024-04-15 15:40 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-12 20:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|ICE - std::bit_cast in |ICE - std::bit_cast in
|consteval function |consteval function
|involving union |involving array of union
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks like check_bit_cast_type does not check ARRAY_TYPE recusively ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
2024-04-12 20:17 ` [Bug c++/114706] " pinskia at gcc dot gnu.org
2024-04-12 20:21 ` [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union pinskia at gcc dot gnu.org
@ 2024-04-15 15:40 ` jakub at gcc dot gnu.org
2024-04-16 8:02 ` jakub at gcc dot gnu.org
2024-04-16 8:02 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-15 15:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57947
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57947&action=edit
gcc14-pr114706.patch
Untested obvious patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
` (2 preceding siblings ...)
2024-04-15 15:40 ` jakub at gcc dot gnu.org
@ 2024-04-16 8:02 ` jakub at gcc dot gnu.org
2024-04-16 8:02 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-16 8:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:79ff53453e88e40c4f2ecf6f7f7409afc41b46fc
commit r14-9987-g79ff53453e88e40c4f2ecf6f7f7409afc41b46fc
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Apr 16 09:39:19 2024 +0200
c++: Handle ARRAY_TYPE in check_bit_cast_type [PR114706]
https://eel.is/c++draft/bit.cast#3 says that std::bit_cast isn't constexpr
if To, From and the types of all subobjects have certain properties which
the
check_bit_cast_type checks (such as it isn't a pointer, reference, union,
member pointer, volatile). The function doesn't cp_walk_tree though, so
I've missed one important case, for ARRAY_TYPEs we need to recurse on the
element type. I think we don't need to handle VECTOR_TYPEs/COMPLEX_TYPEs,
because those will not have a pointer/reference/union/member pointer in
the element type and if the element type is volatile, I think the whole
derived type is volatile as well.
2024-04-16 Jakub Jelinek <jakub@redhat.com>
PR c++/114706
* constexpr.cc (check_bit_cast_type): Handle ARRAY_TYPE.
* g++.dg/cpp2a/bit-cast17.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
` (3 preceding siblings ...)
2024-04-16 8:02 ` jakub at gcc dot gnu.org
@ 2024-04-16 8:02 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-16 8:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-04-16 8:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 20:13 [Bug c++/114706] New: ICE - std::bit_cast in consteval function involving union cuzdav at gmail dot com
2024-04-12 20:17 ` [Bug c++/114706] " pinskia at gcc dot gnu.org
2024-04-12 20:21 ` [Bug c++/114706] ICE - std::bit_cast in consteval function involving array of union pinskia at gcc dot gnu.org
2024-04-15 15:40 ` jakub at gcc dot gnu.org
2024-04-16 8:02 ` jakub at gcc dot gnu.org
2024-04-16 8:02 ` jakub 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).