public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
@ 2021-07-24  4:00 hewillk at gmail dot com
  2021-08-02 17:14 ` [Bug libstdc++/101608] " hewillk at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hewillk at gmail dot com @ 2021-07-24  4:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101608
           Summary: ranges::fill/fill_n missing
                    std::is_constant_evaluated() condition for
                    __builtin_memset
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

ranges_algobase.h#L529:

    if constexpr (is_pointer_v<_Out>
                    // Note that __is_byte already implies !is_volatile.
                    && __is_byte<remove_pointer_t<_Out>>::__value
                    && integral<_Tp>)
    {
      __builtin_memset(__first, static_cast<unsigned char>(__value), __n);
      return __first + __n;
    }


We should ensure that std::is_constant_evaluated() is false before calling
__builtin_memset since it is not usable in constexpr contexts.


#include <algorithm>

constexpr auto unused = [] {
  std::array<unsigned char, 5> r{};
  std::ranges::fill(r, 0);
  return 0;
}();

https://godbolt.org/z/bnYxY78o8

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
@ 2021-08-02 17:14 ` hewillk at gmail dot com
  2021-11-23 16:55 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hewillk at gmail dot com @ 2021-08-02 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
This may help:

--- a/ranges_algobase.h
+++ b/ranges_algobase.h
@@ -525,16 +525,22 @@ namespace ranges
        if (__n <= 0)
          return __first;

-       // TODO: Generalize this optimization to contiguous iterators.
-       if constexpr (is_pointer_v<_Out>
-                     // Note that __is_byte already implies !is_volatile.
-                     && __is_byte<remove_pointer_t<_Out>>::__value
-                     && integral<_Tp>)
+#ifdef __cpp_lib_is_constant_evaluated
+       if (!std::is_constant_evaluated())
+#endif
          {
-           __builtin_memset(__first, static_cast<unsigned char>(__value),
__n);
-           return __first + __n;
+           // TODO: Generalize this optimization to contiguous iterators.
+           if constexpr (is_pointer_v<_Out>
+                   // Note that __is_byte already implies !is_volatile.
+                   && __is_byte<remove_pointer_t<_Out>>::__value
+                   && integral<_Tp>)
+             {
+               __builtin_memset(__first, static_cast<unsigned char>(__value),
__n);
+               return __first + __n;
+             }
          }
-       else if constexpr (is_scalar_v<_Tp>)
+       
+       if constexpr (is_scalar_v<_Tp>)
          {
            const auto __tmp = __value;
            for (; __n > 0; --__n, (void)++__first)

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
  2021-08-02 17:14 ` [Bug libstdc++/101608] " hewillk at gmail dot com
@ 2021-11-23 16:55 ` redi at gcc dot gnu.org
  2021-11-25 20:03 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-23 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-23
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
  2021-08-02 17:14 ` [Bug libstdc++/101608] " hewillk at gmail dot com
  2021-11-23 16:55 ` redi at gcc dot gnu.org
@ 2021-11-25 20:03 ` cvs-commit at gcc dot gnu.org
  2021-11-25 23:07 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-25 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:82c3657dd74896b39937bb0a2aaeba9b8ca105fd

commit r12-5530-g82c3657dd74896b39937bb0a2aaeba9b8ca105fd
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Nov 24 13:17:54 2021 +0000

    libstdc++: Do not use memset in constexpr calls to ranges::fill_n
[PR101608]

    libstdc++-v3/ChangeLog:

            PR libstdc++/101608
            * include/bits/ranges_algobase.h (__fill_n_fn): Check for
            constant evaluation before using memset.
            * testsuite/25_algorithms/fill_n/constrained.cc: Check
            byte-sized values as well.

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2021-11-25 20:03 ` cvs-commit at gcc dot gnu.org
@ 2021-11-25 23:07 ` cvs-commit at gcc dot gnu.org
  2021-11-26 12:52 ` cvs-commit at gcc dot gnu.org
  2021-11-26 14:28 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-25 23:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:7ae6e4e3831429d20eea1be285dbc6a4a005930f

commit r11-9314-g7ae6e4e3831429d20eea1be285dbc6a4a005930f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Nov 24 13:17:54 2021 +0000

    libstdc++: Do not use memset in constexpr calls to ranges::fill_n
[PR101608]

    libstdc++-v3/ChangeLog:

            PR libstdc++/101608
            * include/bits/ranges_algobase.h (__fill_n_fn): Check for
            constant evaluation before using memset.
            * testsuite/25_algorithms/fill_n/constrained.cc: Check
            byte-sized values as well.

    (cherry picked from commit 82c3657dd74896b39937bb0a2aaeba9b8ca105fd)

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2021-11-25 23:07 ` cvs-commit at gcc dot gnu.org
@ 2021-11-26 12:52 ` cvs-commit at gcc dot gnu.org
  2021-11-26 14:28 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-26 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r10-10296-gd0ac292c6083fab4bad79a08d23533f537a885d4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Nov 24 13:17:54 2021 +0000

    libstdc++: Do not use memset in constexpr calls to ranges::fill_n
[PR101608]

    libstdc++-v3/ChangeLog:

            PR libstdc++/101608
            * include/bits/ranges_algobase.h (__fill_n_fn): Check for
            constant evaluation before using memset.
            * testsuite/25_algorithms/fill_n/constrained.cc: Check
            byte-sized values as well.

    (cherry picked from commit 82c3657dd74896b39937bb0a2aaeba9b8ca105fd)

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

* [Bug libstdc++/101608] ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset
  2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2021-11-26 12:52 ` cvs-commit at gcc dot gnu.org
@ 2021-11-26 14:28 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-26 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |10.4
         Resolution|---                         |FIXED

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 10.4 and 11.3

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

end of thread, other threads:[~2021-11-26 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-24  4:00 [Bug libstdc++/101608] New: ranges::fill/fill_n missing std::is_constant_evaluated() condition for __builtin_memset hewillk at gmail dot com
2021-08-02 17:14 ` [Bug libstdc++/101608] " hewillk at gmail dot com
2021-11-23 16:55 ` redi at gcc dot gnu.org
2021-11-25 20:03 ` cvs-commit at gcc dot gnu.org
2021-11-25 23:07 ` cvs-commit at gcc dot gnu.org
2021-11-26 12:52 ` cvs-commit at gcc dot gnu.org
2021-11-26 14:28 ` redi 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).