public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
@ 2024-01-22 16:53 hp at gcc dot gnu.org
  2024-01-22 17:21 ` [Bug c++/113545] " hp at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: hp at gcc dot gnu.org @ 2024-01-22 16:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113545
           Summary: ICE in label_matches with constexpr function with
                    switch-statement and converted (nonconstant, cast
                    address) input
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hp at gcc dot gnu.org
  Target Milestone: ---

For the following test-case, g++ ICEs from at least gcc-10 and forward (i.e.
apparently not a regression):
```
char foo;

constexpr unsigned char bar(__UINTPTR_TYPE__ baz)
{
  switch (baz)
    {
    case 13:
      return 11;
    case 14:
      return 78;
    case 2048:
      return 13;
    default:
      return 42;
    }
}

__attribute__ ((__noipa__))
void xyzzy(int x)
{
  if (x != 42)
    __builtin_abort ();
}

int main()
{
  unsigned const char c = bar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
  xyzzy(c);
}
'''

Example backtrace with -std=c++20 -O3:

../n.cc: In function 'int main()':
../n.cc:27:30:   in 'constexpr' expansion of 'bar(((long unsigned int)(&
foo)))'
../n.cc:5:3: internal compiler error: in label_matches, at cp/constexpr.cc:6925
    5 |   switch (baz)
      |   ^~~~~~
0x63894c label_matches
        /gcctop/gcc/cp/constexpr.cc:6925
0xa0bb3d cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:7319
0xa0d2b2 cxx_eval_statement_list
        /gcctop/gcc/cp/constexpr.cc:6969
0xa0d2b2 cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:8316
0xa1e782 cxx_eval_switch_expr
        /gcctop/gcc/cp/constexpr.cc:7115
0xa0cb6b cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:8412
0xa0aae6 cxx_eval_call_expression
        /gcctop/gcc/cp/constexpr.cc:3288
0xa0c2ef cxx_eval_constant_expression
        /gcctop/gcc/cp/constexpr.cc:7524
0xa17d9a cxx_eval_outermost_constant_expr
        /gcctop/gcc/cp/constexpr.cc:8822
0xa1d28f maybe_constant_value(tree_node*, tree_node*, mce_value)
        /gcctop/gcc/cp/constexpr.cc:9110
0xa49e40 cp_fully_fold
        /gcctop/gcc/cp/cp-gimplify.cc:2831
0xa49ed9 cp_fully_fold
        /gcctop/gcc/cp/cp-gimplify.cc:2825
0xa49ed9 cp_fully_fold_init(tree_node*)
        /gcctop/gcc/cp/cp-gimplify.cc:2861
0xc7a204 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        /gcctop/gcc/cp/typeck2.cc:926
0xa6ca32 check_initializer
        /gcctop/gcc/cp/decl.cc:7810
0xa941be cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        /gcctop/gcc/cp/decl.cc:8842
0xb95477 cp_parser_init_declarator
        /gcctop/gcc/cp/parser.cc:23618
0xb6ac98 cp_parser_simple_declaration
        /gcctop/gcc/cp/parser.cc:15890
0xb8f830 cp_parser_declaration_statement
        /gcctop/gcc/cp/parser.cc:14926
0xb97215 cp_parser_statement
        /gcctop/gcc/cp/parser.cc:12882
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] 10+ messages in thread

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
@ 2024-01-22 17:21 ` hp at gcc dot gnu.org
  2024-02-07  0:31 ` hp at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hp at gcc dot gnu.org @ 2024-01-22 17:21 UTC (permalink / raw)
  To: gcc-bugs

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

Hans-Peter Nilsson <hp at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2024-01-22
     Ever confirmed|0                           |1

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
  2024-01-22 17:21 ` [Bug c++/113545] " hp at gcc dot gnu.org
@ 2024-02-07  0:31 ` hp at gcc dot gnu.org
  2024-02-07  0:32 ` hp at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hp at gcc dot gnu.org @ 2024-02-07  0:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hans-Peter Nilsson <hp at gcc dot gnu.org> ---
There's a test-suite patch at
https://gcc.gnu.org/pipermail/gcc-patches/2024-January/643667.html which is
currently in review-ping limbo.
I'm unassigning myself from this PR.  I won't work on the actual problem,
although I'll keep pinging the testsuite patch - which has merits on its own as
a guard if this PR is accidentally fixed, which is actually expected given the
nature of the underlying bug.

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
  2024-01-22 17:21 ` [Bug c++/113545] " hp at gcc dot gnu.org
  2024-02-07  0:31 ` hp at gcc dot gnu.org
@ 2024-02-07  0:32 ` hp at gcc dot gnu.org
  2024-02-10  3:41 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hp at gcc dot gnu.org @ 2024-02-07  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

Hans-Peter Nilsson <hp at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-02-07  0:32 ` hp at gcc dot gnu.org
@ 2024-02-10  3:41 ` cvs-commit at gcc dot gnu.org
  2024-02-12 19:56 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-10  3:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hans-Peter Nilsson <hp@gcc.gnu.org>:

https://gcc.gnu.org/g:48207a5f00d6ae7cb11038e7c17f6858de4a884e

commit r14-8907-g48207a5f00d6ae7cb11038e7c17f6858de4a884e
Author: Hans-Peter Nilsson <hp@axis.com>
Date:   Mon Jan 22 01:09:03 2024 +0100

    c++: testcases for PR113545 (constexpr with switch and passing
non-constexpr parameter)

    Test-cases, with constexpr-reinterpret3.C dg-ice:ing the PR c++/113545 bug.

    Regarding the request in the comment, A dg-do run when there's an ICE
    will cause some CI's to signal an error for the run being "UNRESOLVED"
    (compilation failed to produce executable).  Note that dejagnu (1.6.3)
    itself doesn't consider this an error.

    gcc/testsuite:
            PR c++/113545
            * g++.dg/cpp1y/constexpr-reinterpret3.C,
            g++.dg/cpp1y/constexpr-reinterpret4.C: New tests.

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-02-10  3:41 ` cvs-commit at gcc dot gnu.org
@ 2024-02-12 19:56 ` cvs-commit at gcc dot gnu.org
  2024-02-12 20:02 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-12 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:39d989022dd0eacf1a7b95b7b20621acbe717d70

commit r14-8942-g39d989022dd0eacf1a7b95b7b20621acbe717d70
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Feb 12 14:53:24 2024 -0500

    c++: ICE with reinterpret_cast and switch [PR113545]

    Jason, this is the patch you proposed for PR113545.  It looks very safe
    so I'm posting it here so that it's not forgotten.

            PR c++/113545

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_switch_expr): If the condition doesn't
reduce
            to an INTEGER_CST, consider it non-constant.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/constexpr-reinterpret3.C: Remove dg-ice.

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-02-12 19:56 ` cvs-commit at gcc dot gnu.org
@ 2024-02-12 20:02 ` mpolacek at gcc dot gnu.org
  2024-02-14  1:17 ` hp at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-12 20:02 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk, will backport to 13.

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-02-12 20:02 ` mpolacek at gcc dot gnu.org
@ 2024-02-14  1:17 ` hp at gcc dot gnu.org
  2024-02-16 17:30 ` cvs-commit at gcc dot gnu.org
  2024-02-16 17:30 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: hp at gcc dot gnu.org @ 2024-02-14  1:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Hans-Peter Nilsson <hp at gcc dot gnu.org> ---
Thank you!

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2024-02-14  1:17 ` hp at gcc dot gnu.org
@ 2024-02-16 17:30 ` cvs-commit at gcc dot gnu.org
  2024-02-16 17:30 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-16 17:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

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

commit r13-8336-ge501a279fb4298c9b23637d573287e059b3b06c8
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Feb 16 12:25:26 2024 -0500

    c++: ICE with reinterpret_cast and switch [PR113545]

    Jason, this is the patch you proposed for PR113545.  It looks very safe
    so I'm posting it here so that it's not forgotten.

            PR c++/113545

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_switch_expr): If the condition doesn't
reduce
            to an INTEGER_CST, consider it non-constant.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/constexpr-reinterpret3.C: New test.
            * g++.dg/cpp1y/constexpr-reinterpret4.C: New test.

    (cherry picked from commit 39d989022dd0eacf1a7b95b7b20621acbe717d70)

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

* [Bug c++/113545] ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input
  2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2024-02-16 17:30 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 17:30 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-16 17:30 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in 13+.

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

end of thread, other threads:[~2024-02-16 17:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22 16:53 [Bug c++/113545] New: ICE in label_matches with constexpr function with switch-statement and converted (nonconstant, cast address) input hp at gcc dot gnu.org
2024-01-22 17:21 ` [Bug c++/113545] " hp at gcc dot gnu.org
2024-02-07  0:31 ` hp at gcc dot gnu.org
2024-02-07  0:32 ` hp at gcc dot gnu.org
2024-02-10  3:41 ` cvs-commit at gcc dot gnu.org
2024-02-12 19:56 ` cvs-commit at gcc dot gnu.org
2024-02-12 20:02 ` mpolacek at gcc dot gnu.org
2024-02-14  1:17 ` hp at gcc dot gnu.org
2024-02-16 17:30 ` cvs-commit at gcc dot gnu.org
2024-02-16 17:30 ` mpolacek 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).