public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch
@ 2022-02-05 21:40 franwade33 at googlemail dot com
  2022-02-05 22:58 ` [Bug c++/104403] [12 Regression] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: franwade33 at googlemail dot com @ 2022-02-05 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104403
           Summary: ICE while optimizing lambda that returns address of a
                    static variable hidden in a switch
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franwade33 at googlemail dot com
  Target Milestone: ---

On gcc 12.0.1, the following gives an internal compiler error:

    // g++-12 -std=c++17 -O1
    // g++-12 -std=c++20 -O1
    int main() {
        []{
            switch (0) {
            case 0:
                static int value;
                return &value;
            }
        };
    }

Reproduced here: https://godbolt.org/z/5PKGjGo33

This is the compiler output:

        <source>: In static member function 'static constexpr int*
main()::<lambda()>::_FUN()':
        <source>:8:5:   in 'constexpr' expansion of '0->main()::<lambda()>()'
        <source>:8:5: internal compiler error: in cxx_eval_constant_expression,
at cp/constexpr.cc:6652
            8 |     };
              |     ^
        0x2169b09 internal_error(char const*, ...)
                ???:0
        0x73cd21 fancy_abort(char const*, int, char const*)
                ???:0
        0x7bc242 maybe_constant_value(tree_node*, tree_node*, bool)
        ???:0
        0x87d5db fold_for_warn(tree_node*)
                ???:0
        0xa9048e check_return_expr(tree_node*, bool*)
                ???:0
        0xa19a9e finish_return_stmt(tree_node*)
                ???:0
        0x8997f3 maybe_add_lambda_conv_op(tree_node*)
                ???:0
        0x97f7ed c_parse_file()
                ???:0
        0xb0f1c2 c_common_parse_file()
                ???:0

It compiles fine on gcc 11.2.0, and it also compiles fine with -std=c++2b (and
-std=c++14, where a closure type's operator() can't be implicitly constexpr).

Probably has something to do with C++2b P2242R3 allowing static variables in
constexpr functions.

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

* [Bug c++/104403] [12 Regression] ICE while optimizing lambda that returns address of a static variable hidden in a switch
  2022-02-05 21:40 [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch franwade33 at googlemail dot com
@ 2022-02-05 22:58 ` jakub at gcc dot gnu.org
  2022-02-07 10:44 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-05 22:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-02-05
   Target Milestone|---                         |12.0
           Priority|P3                          |P1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |jakub at gcc dot gnu.org
            Summary|ICE while optimizing lambda |[12 Regression] ICE while
                   |that returns address of a   |optimizing lambda that
                   |static variable hidden in a |returns address of a static
                   |switch                      |variable hidden in a switch
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r12-4206-g8892d532d66910e518bc135a851a104322385ca2

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

* [Bug c++/104403] [12 Regression] ICE while optimizing lambda that returns address of a static variable hidden in a switch
  2022-02-05 21:40 [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch franwade33 at googlemail dot com
  2022-02-05 22:58 ` [Bug c++/104403] [12 Regression] " jakub at gcc dot gnu.org
@ 2022-02-07 10:44 ` jakub at gcc dot gnu.org
  2022-02-08 19:16 ` cvs-commit at gcc dot gnu.org
  2022-02-08 19:17 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-07 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52363
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52363&action=edit
gcc12-pr104403.patch

Untested fix.

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

* [Bug c++/104403] [12 Regression] ICE while optimizing lambda that returns address of a static variable hidden in a switch
  2022-02-05 21:40 [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch franwade33 at googlemail dot com
  2022-02-05 22:58 ` [Bug c++/104403] [12 Regression] " jakub at gcc dot gnu.org
  2022-02-07 10:44 ` jakub at gcc dot gnu.org
@ 2022-02-08 19:16 ` cvs-commit at gcc dot gnu.org
  2022-02-08 19:17 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-08 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 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:1755141a9ea0dddabb52776cddc4c9325eed27c6

commit r12-7112-g1755141a9ea0dddabb52776cddc4c9325eed27c6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Feb 8 20:15:42 2022 +0100

    c++: Remove superflous assert [PR104403]

    I've added the assert because start_decl diagnoses such vars for C++20 and
    earlier:
      if (current_function_decl && VAR_P (decl)
          && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
          && cxx_dialect < cxx23)
    but as can be seen, we cam trigger the assert in older standards e.g.
during
    non-manifestly constant evaluation.  Rather than refining the assert that
    DECL_EXPRs for such vars don't appear for C++20 and older if they are
inside
    of functions declared constexpr this patch just removes the assert, the
    code rejects encountering those vars in constant expressions anyway.

    2022-02-08  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104403
            * constexpr.cc (cxx_eval_constant_expression): Don't assert
DECL_EXPRs
            of TREE_STATIC vars may only appear in -std=c++23.

            * g++.dg/cpp0x/lambda/lambda-104403.C: New test.

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

* [Bug c++/104403] [12 Regression] ICE while optimizing lambda that returns address of a static variable hidden in a switch
  2022-02-05 21:40 [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch franwade33 at googlemail dot com
                   ` (2 preceding siblings ...)
  2022-02-08 19:16 ` cvs-commit at gcc dot gnu.org
@ 2022-02-08 19:17 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-08 19:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-02-08 19:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 21:40 [Bug c++/104403] New: ICE while optimizing lambda that returns address of a static variable hidden in a switch franwade33 at googlemail dot com
2022-02-05 22:58 ` [Bug c++/104403] [12 Regression] " jakub at gcc dot gnu.org
2022-02-07 10:44 ` jakub at gcc dot gnu.org
2022-02-08 19:16 ` cvs-commit at gcc dot gnu.org
2022-02-08 19:17 ` 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).