public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
@ 2023-01-23 17:49 gscfq@t-online.de
  2023-01-24  0:48 ` [Bug c++/108503] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gscfq@t-online.de @ 2023-01-23 17:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108503
           Summary: [13 Regression] ICE in get_array_or_vector_nelts, at
                    cp/constexpr.cc:4119
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Started between 20221127 and 20221204 :


$ cat z1.cc
namespace std {
  template<typename T> struct tuple_size;
  template<int, typename> struct tuple_element;
}
struct A {
  template <int I> int& get() { return 1; }
};
template<> struct std::tuple_size<A> { static const int value = 3; };
template<int I> struct std::tuple_element<I,A> { using type = int; };
struct B {
  A *begin();
  A *end();
};
void f (B a)
{
  #pragma omp for collapse(2)
  for (auto [i, j, k] : a)
    for (int l = i; l < j; l += k)
      ;
}


$ g++-13-20230122 -c z1.cc -fopenmp -Wall
z1.cc: In member function 'int& A::get()':
z1.cc:6:40: error: cannot bind non-const lvalue reference of type 'int&' to an
rvalue of type 'int'
    6 |   template <int I> int& get() { return 1; }
      |                                        ^
z1.cc: In function 'void f(B)':
z1.cc:18:25: internal compiler error: in get_array_or_vector_nelts, at
cp/constexpr.cc:4119
   18 |     for (int l = i; l < j; l += k)
      |                         ^
0x88770e get_array_or_vector_nelts
        ../../gcc/cp/constexpr.cc:4119
0x887804 eval_and_check_array_index
        ../../gcc/cp/constexpr.cc:4171
0x88b5e9 cxx_eval_array_reference
        ../../gcc/cp/constexpr.cc:4208
0x8826ed cxx_eval_constant_expression
        ../../gcc/cp/constexpr.cc:7516
0x880e9a cxx_eval_constant_expression
        ../../gcc/cp/constexpr.cc:7042
0x8837ac cxx_eval_indirect_ref
        ../../gcc/cp/constexpr.cc:5642
0x8837ac cxx_eval_constant_expression
        ../../gcc/cp/constexpr.cc:7358
0x88d3ba cxx_eval_outermost_constant_expr
        ../../gcc/cp/constexpr.cc:8252
0x892882 maybe_constant_value(tree_node*, tree_node*, bool)
        ../../gcc/cp/constexpr.cc:8527
0x956053 fold_for_warn(tree_node*)
        ../../gcc/cp/expr.cc:421
0xc1d801 warn_tautological_cmp(op_location_t const&, tree_code, tree_node*,
tree_node*)
        ../../gcc/c-family/c-warn.cc:485
0x84369b build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
        ../../gcc/cp/call.cc:7354
0xb485cd build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
        ../../gcc/cp/typeck.cc:4722
0xa1c40f cp_parser_omp_for_cond
        ../../gcc/cp/parser.cc:42701
0xa1c40f cp_parser_omp_for_loop
        ../../gcc/cp/parser.cc:43652
0xa410f6 cp_parser_omp_for
        ../../gcc/cp/parser.cc:44005
0xa56f14 cp_parser_omp_construct
        ../../gcc/cp/parser.cc:48527
0xa20a7f cp_parser_pragma
        ../../gcc/cp/parser.cc:49207
0xa2740c cp_parser_statement
        ../../gcc/cp/parser.cc:12434
0xa28884 cp_parser_statement_seq_opt
        ../../gcc/cp/parser.cc:12909

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
@ 2023-01-24  0:48 ` pinskia at gcc dot gnu.org
  2023-01-24  9:08 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-24  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Target Milestone|---                         |13.0
   Last reconfirmed|                            |2023-01-24
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, here is a testcase that does not error out before the ICE:
```
namespace std {
  template<typename T> struct tuple_size;
  template<int, typename> struct tuple_element;
}
struct A {
  template <int I> int get() { return 1; }
};
template<> struct std::tuple_size<A> { static const int value = 3; };
template<int I> struct std::tuple_element<I,A> { using type = int; };
struct B {
  A *begin();
  A *end();
};
void f (B a)
{
  #pragma omp for collapse(2)
  for (auto [i, j, k] : a)
    for (int l = i; l < j; l += k)
      ;
}
```
Note -fopenmp -Wall is needed to get the ICE.

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
  2023-01-24  0:48 ` [Bug c++/108503] " pinskia at gcc dot gnu.org
@ 2023-01-24  9:08 ` rguenth at gcc dot gnu.org
  2023-01-24 16:24 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-24  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
  2023-01-24  0:48 ` [Bug c++/108503] " pinskia at gcc dot gnu.org
  2023-01-24  9:08 ` rguenth at gcc dot gnu.org
@ 2023-01-24 16:24 ` jason at gcc dot gnu.org
  2023-01-24 16:30 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-01-24 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Broken by r13-4461-gf13305518558f20ef2d460a74eb29dad5fce1350

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2023-01-24 16:24 ` jason at gcc dot gnu.org
@ 2023-01-24 16:30 ` jakub at gcc dot gnu.org
  2023-01-25 13:45 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-24 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2023-01-24 16:30 ` jakub at gcc dot gnu.org
@ 2023-01-25 13:45 ` jakub at gcc dot gnu.org
  2023-01-26  9:48 ` cvs-commit at gcc dot gnu.org
  2023-01-26 10:25 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-25 13:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

This hack works around it, by pretending the VAR_DECLs don't have
DECL_VALUE_EXPR between the deduction of the type and actually finalizing their
DECL_VALUE_EXPR (for !processing_template_decl only where we do the deduction
with temporarily incremented processing_template_decl).

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2023-01-25 13:45 ` jakub at gcc dot gnu.org
@ 2023-01-26  9:48 ` cvs-commit at gcc dot gnu.org
  2023-01-26 10:25 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-26  9:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:d427407a199a0c276cb02d6bbb64e6ecc02e590d

commit r13-5379-gd427407a199a0c276cb02d6bbb64e6ecc02e590d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jan 26 10:41:10 2023 +0100

    openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops
[PR108503]

    My recent change to deduce structured binding vars earlier caused the
following
    invalid testcase to ICE.  The problem is that because at
cp_convert_omp_range_for
    when !processing_template_decl we aren't yet ready to finalize the
structured bindings
    (e.g. can't emit there associated code) but need to deduce types of the
vars so that
    we don't get errors if we parse invalid uses of those vars in inner loops
of the
    collapsed construct.  This is done by temporarily bumping
processing_template_decl
    around the call to cp_finish_decomp.  Unfortunately, as we can't finalize
it yet,
    the types of the vars will be deduced, but their DECL_VALUE_EXPR is not
finalized
    yet and if say fold_for_warn tries to constant expression evaluate them, it
    recurses on DECL_VALUE_EXPR and ICEs because it sees e.g. ARRAY_REF (with
NULL type)
    on a VAR_DECL with class type.

    The following patch works around that by temporarily hiding the
DECL_VALUE_EXPRs
    by clearing DECL_HAS_VALUE_EXPR_P in that case during
cp_convert_omp_range_for
    and arranging for cp_finish_omp_range_for to set it back before doing the
    final cp_finish_decomp.

    2023-01-25  Jakub Jelinek  <jakub@redhat.com>

            PR c++/108503
            * parser.cc (cp_convert_omp_range_for): If cp_finish_decomp has
been
            called in !processing_template_decl with processing_template_decl
            temporarily set, clear DECL_HAS_VALUE_EXPR_P on the vars
temporarily.
            (cp_finish_omp_range_for): And set it back again here.

            * g++.dg/gomp/pr108503.C: New test.

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

* [Bug c++/108503] [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119
  2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2023-01-26  9:48 ` cvs-commit at gcc dot gnu.org
@ 2023-01-26 10:25 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-26 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2023-01-26 10:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-23 17:49 [Bug c++/108503] New: [13 Regression] ICE in get_array_or_vector_nelts, at cp/constexpr.cc:4119 gscfq@t-online.de
2023-01-24  0:48 ` [Bug c++/108503] " pinskia at gcc dot gnu.org
2023-01-24  9:08 ` rguenth at gcc dot gnu.org
2023-01-24 16:24 ` jason at gcc dot gnu.org
2023-01-24 16:30 ` jakub at gcc dot gnu.org
2023-01-25 13:45 ` jakub at gcc dot gnu.org
2023-01-26  9:48 ` cvs-commit at gcc dot gnu.org
2023-01-26 10:25 ` 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).