public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101566] New: gcc miscompiles lambda used as tuple-like object applied to function for call
@ 2021-07-21 18:07 weilercdale at gmail dot com
  2021-07-21 18:18 ` [Bug c++/101566] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: weilercdale at gmail dot com @ 2021-07-21 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101566
           Summary: gcc miscompiles lambda used as tuple-like object
                    applied to function for call
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: weilercdale at gmail dot com
  Target Milestone: ---

Created attachment 51191
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51191&action=edit
minimized test case

The following code uses a compiler generated structure via a lambda and `[=]`
capture-list to create a "tuple"-like object, `get<N>` is implemented in terms
of the gcc provided intrinsic `__integer_pack(N)` to emulate
`std::index_sequence` for peeling off the value from the "tuple"-like object.
`apply` calls any callable by applying `get<>` to each value in the
"tuple"-like object. `PackCount` exposes the parameter pack count of the
"tuple"-like object created with `make`, A `decltype` of the lambda is used to
create a new struct `Lambda` that inherits both, making
`PackCount<Ts...>::ELEMENTS` available as a compile-time constant to each
created "tuple"-like object. A `Tuple` type is provided by taking the
`decltype` of `make` synthesizing values for the call with `declval`. The code
compiles in gcc, msvc, and clang but only works in the latter two compilers,
gcc appears to miscompile the code under -O3. When compiling in gcc with
-fsanitize=undefined, the code isn't miscompiled, and it runs fine. Under other
optimization levels the code isn't miscompiled either. This appears to affect
multiple versions of gcc including 10.1, 10.2, 10.3, 11.1.0, 11.1.1, and
current trunk as can be verified on compiler explorer here
https://godbolt.org/z/3sYnrj6nW

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

end of thread, other threads:[~2021-07-21 19:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 18:07 [Bug c++/101566] New: gcc miscompiles lambda used as tuple-like object applied to function for call weilercdale at gmail dot com
2021-07-21 18:18 ` [Bug c++/101566] " pinskia at gcc dot gnu.org
2021-07-21 18:24 ` weilercdale at gmail dot com
2021-07-21 18:34 ` pinskia at gcc dot gnu.org
2021-07-21 18:42 ` weilercdale at gmail dot com
2021-07-21 18:51 ` weilercdale at gmail dot com
2021-07-21 19:22 ` weilercdale at gmail dot com
2021-07-21 19:23 ` weilercdale at gmail dot com
2021-07-21 19:56 ` 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).