public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
@ 2020-06-10  4:43 ` lyberta at lyberta dot net
  2020-07-16 16:15 ` jakub at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: lyberta at lyberta dot net @ 2020-06-10  4:43 UTC (permalink / raw)
  To: gcc-bugs

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

Lyberta <lyberta at lyberta dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lyberta at lyberta dot net

--- Comment #2 from Lyberta <lyberta at lyberta dot net> ---
This should block bug 88322

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
  2020-06-10  4:43 ` [Bug libstdc++/93121] std::bit_cast missing lyberta at lyberta dot net
@ 2020-07-16 16:15 ` jakub at gcc dot gnu.org
  2020-07-17 11:59 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-16 16:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48883
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48883&action=edit
gcc11-pr93121-wip.patch

Untested WIP on this (well, only the compiler builtin).
What needs still doing is
1) handle bitfields (both in the middle-end in native_encode_initializer and in
2) punt on trying to read padding bits - perhaps if arg is a CONSTRUCTOR
compute
in addition to the memory representation a mask which bits are uninitialized,
and diagnose if we try to read from those
3) verify handling of flexible array members and zero length arrays

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
  2020-06-10  4:43 ` [Bug libstdc++/93121] std::bit_cast missing lyberta at lyberta dot net
  2020-07-16 16:15 ` jakub at gcc dot gnu.org
@ 2020-07-17 11:59 ` jakub at gcc dot gnu.org
  2020-07-17 16:24 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-17 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48887
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48887&action=edit
gcc11-pr93121-me.patch

Middle-end patch to handle bit-fields (except for PDP11 and those that lack
DECL_BIT_FIELD_REPRESENTATIVE) in native_encode_initializer.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-07-17 11:59 ` jakub at gcc dot gnu.org
@ 2020-07-17 16:24 ` jakub at gcc dot gnu.org
  2020-07-17 16:27 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-17 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #48883|0                           |1
        is obsolete|                            |
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2020-07-17
     Ever confirmed|0                           |1

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48890
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48890&action=edit
gcc11-pr93121.patch

Untested full patch, zero sized arrays work fine, but flexible arrays don't and
it is unclear what exactly do we want to do with them.
Treat them always as zero sized arrays?  Or have a special case if the argument
is a reference to a VAR_DECL or VAR_DECL itself which has type with flexible
array member and in that case assume the flexible array size from the
initializer?

struct A { int a; int b[]; };
struct B { int a; int b[0]; };
constexpr A a = { 1, {} };
constexpr B b = { 2, {} };
static_assert (__builtin_bit_cast (int, a) == 1, "");
static_assert (__builtin_bit_cast (int, b) == 2, "");
static_assert ((__builtin_bit_cast (B, a)).a == 1, "");
static_assert ((__builtin_bit_cast (A, b)).a == 2, "");

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-07-17 16:24 ` jakub at gcc dot gnu.org
@ 2020-07-17 16:27 ` jakub at gcc dot gnu.org
  2020-07-20  8:09 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-17 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Oh, and the patch doesn't differentiate between storing of indeterminate values
into unsigned char or std::byte and other stores, all of them are treated as
problematic.  Will defer that to PR96223, but the code knows from the
indeterminate bits mask and type it is stored to whether that would be a case
or not.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-07-17 16:27 ` jakub at gcc dot gnu.org
@ 2020-07-20  8:09 ` cvs-commit at gcc dot gnu.org
  2020-07-20  8:25 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-20  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:83b171655dc0785262a444f5d5c2be7195977987

commit r11-2224-g83b171655dc0785262a444f5d5c2be7195977987
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jul 20 10:08:28 2020 +0200

    fold-const: Handle bitfields in native_encode_initializer [PR93121]

    When working on __builtin_bit_cast that needs to handle bitfields too,
    I've made the following change to handle at least some bitfields in
    native_encode_initializer (those that have integral representative).

    2020-07-20  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/93121
            * fold-const.c (native_encode_initializer): Handle bit-fields.

            * gcc.dg/tree-ssa/pr93121-1.c: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-07-20  8:09 ` cvs-commit at gcc dot gnu.org
@ 2020-07-20  8:25 ` cvs-commit at gcc dot gnu.org
  2020-12-03 14:49 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-20  8:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:e4f1cbc35b1e823a0a6e58eeca61c8c6ca351875

commit r11-2225-ge4f1cbc35b1e823a0a6e58eeca61c8c6ca351875
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jul 20 10:24:19 2020 +0200

    gimple-fold: Handle bitfields in fold_const_aggregate_ref_1 [PR93121]

    When working on __builtin_bit_cast that needs to handle bitfields too,
    I've made the following change to handle at least some bitfields in
    fold_const_aggregate_ref_1 (those that have integral representative).
    It already handles some, but only those that start and end at byte
    boundaries.

    2020-07-20  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/93121
            * gimple-fold.c (fold_const_aggregate_ref_1): For COMPONENT_REF
            of a bitfield not aligned on byte boundaries try to
            fold_ctor_reference DECL_BIT_FIELD_REPRESENTATIVE if any and
            adjust it depending on endianity.

            * gcc.dg/tree-ssa/pr93121-2.c: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2020-07-20  8:25 ` cvs-commit at gcc dot gnu.org
@ 2020-12-03 14:49 ` cvs-commit at gcc dot gnu.org
  2020-12-03 19:17 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-03 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:896048cf43d5eb21ab7c16553bb9d13b0f890b81

commit r11-5704-g896048cf43d5eb21ab7c16553bb9d13b0f890b81
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 3 15:46:54 2020 +0100

    c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]

    The following patch adds __builtin_bit_cast builtin, similarly to
    clang or MSVC which implement std::bit_cast using such an builtin too.
    It checks the various std::bit_cast requirements, when not constexpr
    evaluated acts pretty much like VIEW_CONVERT_EXPR of the source argument
    to the destination type and the hardest part is obviously the constexpr
    evaluation.
    I've left out PDP11 handling of those, couldn't figure out how exactly are
    bitfields laid out there

    2020-12-03  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/93121
            * fold-const.h (native_encode_initializer): Add mask argument
            defaulted to nullptr.
            (find_bitfield_repr_type): Declare.
            (native_interpret_aggregate): Declare.
            * fold-const.c (find_bitfield_repr_type): New function.
            (native_encode_initializer): Add mask argument and support for
            filling it.  Handle also some bitfields without integral
            DECL_BIT_FIELD_REPRESENTATIVE.
            (native_interpret_aggregate): New function.
            * gimple-fold.h (clear_type_padding_in_mask): Declare.
            * gimple-fold.c (struct clear_padding_struct): Add clear_in_mask
            member.
            (clear_padding_flush): Handle buf->clear_in_mask.
            (clear_padding_union): Copy clear_in_mask.  Don't error if
            buf->clear_in_mask is set.
            (clear_padding_type): Don't error if buf->clear_in_mask is set.
            (clear_type_padding_in_mask): New function.
            (gimple_fold_builtin_clear_padding): Set buf.clear_in_mask to
false.
            * doc/extend.texi (__builtin_bit_cast): Document.

            * c-common.h (enum rid): Add RID_BUILTIN_BIT_CAST.
            * c-common.c (c_common_reswords): Add __builtin_bit_cast.

            * cp-tree.h (cp_build_bit_cast): Declare.
            * cp-tree.def (BIT_CAST_EXPR): New tree code.
            * cp-objcp-common.c (names_builtin_p): Handle RID_BUILTIN_BIT_CAST.
            (cp_common_init_ts): Handle BIT_CAST_EXPR.
            * cxx-pretty-print.c (cxx_pretty_printer::postfix_expression):
            Likewise.
            * parser.c (cp_parser_postfix_expression): Handle
            RID_BUILTIN_BIT_CAST.
            * semantics.c (cp_build_bit_cast): New function.
            * tree.c (cp_tree_equal): Handle BIT_CAST_EXPR.
            (cp_walk_subtrees): Likewise.
            * pt.c (tsubst_copy): Likewise.
            * constexpr.c (check_bit_cast_type, cxx_eval_bit_cast): New
functions.
            (cxx_eval_constant_expression): Handle BIT_CAST_EXPR.
            (potential_constant_expression_1): Likewise.
            * cp-gimplify.c (cp_genericize_r): Likewise.

            * g++.dg/cpp2a/bit-cast1.C: New test.
            * g++.dg/cpp2a/bit-cast2.C: New test.
            * g++.dg/cpp2a/bit-cast3.C: New test.
            * g++.dg/cpp2a/bit-cast4.C: New test.
            * g++.dg/cpp2a/bit-cast5.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2020-12-03 14:49 ` cvs-commit at gcc dot gnu.org
@ 2020-12-03 19:17 ` cvs-commit at gcc dot gnu.org
  2020-12-03 19:26 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-03 19:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:9e433b3461ab64b38350817392a77efb67bb78b4

commit r11-5722-g9e433b3461ab64b38350817392a77efb67bb78b4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Dec 3 19:17:13 2020 +0000

    libstdc++: Add std::bit_cast for C++20 [PR 93121]

    Thanks to Jakub's addition of the built-in, we can add this to the
    library now. The compiler tests for the built-in are quite extensive,
    including verifying the constraints, so this only adds minimal tests to
    the library testsuite.

    This doesn't add a new _GLIBCXX_HAVE_BUILTIN_BIT_CAST because using
    __has_builtin(__builtin_bit_cast) works for GCC and versions of Clang
    that provide the built-in.

    libstdc++-v3/ChangeLog:

            PR libstdc++/93121
            * include/std/bit (__cpp_lib_bit_cast, bit_cast): Define.
            * include/std/version (__cpp_lib_bit_cast): Define.
            * testsuite/26_numerics/bit/bit.cast/bit_cast.cc: New test.
            * testsuite/26_numerics/bit/bit.cast/version.cc: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2020-12-03 19:17 ` cvs-commit at gcc dot gnu.org
@ 2020-12-03 19:26 ` redi at gcc dot gnu.org
  2020-12-04  8:30 ` klaus.doldinger64 at googlemail dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-03 19:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0
             Status|ASSIGNED                    |RESOLVED

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Added for GCC 11.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2020-12-03 19:26 ` redi at gcc dot gnu.org
@ 2020-12-04  8:30 ` klaus.doldinger64 at googlemail dot com
  2020-12-04 10:45 ` jakub at gcc dot gnu.org
  2020-12-04 17:02 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: klaus.doldinger64 at googlemail dot com @ 2020-12-04  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Wilhelm M <klaus.doldinger64 at googlemail dot com> ---
The following does not work:

# include <cstdint>
# include <cstring>
# include <cstddef>
# include <bit>
# include <array>

using to_t   = std::array<int16_t, 2>;

int main() {
    constexpr std::byte from1[4]{};
    constexpr auto v1 = std::bit_cast<to_t>(from1);    
    return v1[0];
}

gives:

/usr/local/include/c++/11.0.0/bit: In function 'int main()':
/home/lmeier/Projekte/wmucpp/host/test88.cc:11:50:   in 'constexpr' expansion
of 'std::bit_cast<std::array<short int, 2>, std::byte [4]>(from1)'
/usr/local/include/c++/11.0.0/bit:60:33: sorry, unimplemented:
'__builtin_bit_cast' cannot be constant evaluated because the argument cannot
be encoded
60 |       return __builtin_bit_cast(_To, __from);
|                                 ^~~

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2020-12-04  8:30 ` klaus.doldinger64 at googlemail dot com
@ 2020-12-04 10:45 ` jakub at gcc dot gnu.org
  2020-12-04 17:02 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-04 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561119.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/93121] std::bit_cast missing
       [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2020-12-04 10:45 ` jakub at gcc dot gnu.org
@ 2020-12-04 17:02 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-04 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:33be07be9e46f15b9556521050356c47460651ee

commit r11-5746-g33be07be9e46f15b9556521050356c47460651ee
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 4 18:00:54 2020 +0100

    fold-const: Don't use build_constructor for non-aggregate types in
native_encode_initializer [PR93121]

    The following testcase is rejected, because when trying to encode a zeroing
    CONSTRUCTOR, the code was using build_constructor to build initializers for
    the elements but when recursing the function handles CONSTRUCTOR only for
    aggregate types.

    The following patch fixes that by using build_zero_cst instead for
    non-aggregates.  Another option would be add handling CONSTRUCTOR for
    non-aggregates in native_encode_initializer.  Or we can do both, I guess
    the middle-end generally doesn't like CONSTRUCTORs for scalar variables,
but
    am not 100% sure if the FE doesn't produce those sometimes.

    2020-12-04  Jakub Jelinek  <jakub@redhat.com>

            PR libstdc++/93121
            * fold-const.c (native_encode_initializer): Use build_zero_cst
            instead of build_constructor.

            * g++.dg/cpp2a/bit-cast6.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-04 17:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93121-4@http.gcc.gnu.org/bugzilla/>
2020-06-10  4:43 ` [Bug libstdc++/93121] std::bit_cast missing lyberta at lyberta dot net
2020-07-16 16:15 ` jakub at gcc dot gnu.org
2020-07-17 11:59 ` jakub at gcc dot gnu.org
2020-07-17 16:24 ` jakub at gcc dot gnu.org
2020-07-17 16:27 ` jakub at gcc dot gnu.org
2020-07-20  8:09 ` cvs-commit at gcc dot gnu.org
2020-07-20  8:25 ` cvs-commit at gcc dot gnu.org
2020-12-03 14:49 ` cvs-commit at gcc dot gnu.org
2020-12-03 19:17 ` cvs-commit at gcc dot gnu.org
2020-12-03 19:26 ` redi at gcc dot gnu.org
2020-12-04  8:30 ` klaus.doldinger64 at googlemail dot com
2020-12-04 10:45 ` jakub at gcc dot gnu.org
2020-12-04 17:02 ` cvs-commit 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).