public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461
@ 2024-02-08 16:46 ivan.lazaric.gcc at gmail dot com
  2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: ivan.lazaric.gcc at gmail dot com @ 2024-02-08 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113834
           Summary: internal compiler error: in tree_to_shwi, at
                    tree.cc:6461
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.lazaric.gcc at gmail dot com
  Target Milestone: ---

Version of g++ is 14.0.1, built of commit
3979171d8ea149912d99bdca6aeb3e7276842f02

Complete backtrace:
```
/home/ilazaric/installs/gcc-latest/include/c++/14.0.1/bits/utility.h:231:13:
internal compiler error: in tree_to_shwi, at tree.cc:6461
  231 |     { using type = __type_pack_element<_Np, _Types...>; };
      |             ^~~~
0x99d54d tree_to_shwi(tree_node const*)
        ../../gcc/gcc/tree.cc:6461
0x99d54d tree_to_shwi(tree_node const*)
        ../../gcc/gcc/tree.cc:6459
0xd07a45 finish_type_pack_element
        ../../gcc/gcc/cp/semantics.cc:4653
0xd07a45 finish_trait_type(cp_trait_kind, tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/semantics.cc:12783
0xcc8fc7 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:16920
0xcbb9ae tsubst_decl
        ../../gcc/gcc/cp/pt.cc:15518
0xce3350 instantiate_class_template(tree_node*)
        ../../gcc/gcc/cp/pt.cc:12494
0xd37570 complete_type(tree_node*)
        ../../gcc/gcc/cp/typeck.cc:138
0xd3769d complete_type_or_maybe_complain(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/typeck.cc:151
0xcc9c76 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:16795
0xcbb9ae tsubst_decl
        ../../gcc/gcc/cp/pt.cc:15518
0xce3350 instantiate_class_template(tree_node*)
        ../../gcc/gcc/cp/pt.cc:12494
0xd37570 complete_type(tree_node*)
        ../../gcc/gcc/cp/typeck.cc:138
0xd3769d complete_type_or_maybe_complain(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/typeck.cc:151
0xcc9c76 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:16795
0xcbb9ae tsubst_decl
        ../../gcc/gcc/cp/pt.cc:15518
0xcad863 instantiate_template(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/pt.cc:22089
0xcc9adb instantiate_alias_template
        ../../gcc/gcc/cp/pt.cc:22180
0xcc9adb tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:16180
0xcc8652 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.cc:16226
```

Attached is the preprocessed file generated by `-freport-bug`

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

* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
@ 2024-02-08 16:48 ` ivan.lazaric.gcc at gmail dot com
  2024-02-09  0:15 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ivan.lazaric.gcc at gmail dot com @ 2024-02-08 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Ivan Lazaric <ivan.lazaric.gcc at gmail dot com> ---
Created attachment 57362
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57362&action=edit
Preprocessed file generated by `-freport-bug`

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

* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
  2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
@ 2024-02-09  0:15 ` pinskia at gcc dot gnu.org
  2024-02-09  2:49 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reducing, this looks like an ICE after an error ...

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

* [Bug c++/113834] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
  2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
  2024-02-09  0:15 ` pinskia at gcc dot gnu.org
@ 2024-02-09  2:49 ` pinskia at gcc dot gnu.org
  2024-02-09  7:02 ` [Bug c++/113834] [14 Regression] " pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09  2:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
template <typename... _Elements> class tuple{};
template <unsigned long __i, typename... _Elements>
__type_pack_element<__i, _Elements...> &get(tuple<_Elements...> &__t) noexcept;
tuple<int,int> data;
template <unsigned long Level>
unsigned take_impl(unsigned idx) {
  if constexpr (Level != -1){
    return take_impl<Level - 1>(get<Level - 1>(data));
  }
  return 0;
}
int main() {
  take_impl<2>(0);
}
```

Note I think this is invalid code ...

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (2 preceding siblings ...)
  2024-02-09  2:49 ` pinskia at gcc dot gnu.org
@ 2024-02-09  7:02 ` pinskia at gcc dot gnu.org
  2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-09  7:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-02-09
            Summary|internal compiler error: in |[14 Regression] internal
                   |tree_to_shwi, at            |compiler error: in
                   |tree.cc:6461                |tree_to_shwi, at
                   |                            |tree.cc:6461
                 CC|                            |ppalka at gcc dot gnu.org
   Target Milestone|---                         |14.0
           Keywords|needs-bisection             |

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
__type_pack_element support was introduced in r14-92-g58b7dbf865b146 .

So yes this is visual regression in that using the libstdc++ headers in GCC 13
will not ICE but using them in GCC 14+, there will be an ICE.

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (3 preceding siblings ...)
  2024-02-09  7:02 ` [Bug c++/113834] [14 Regression] " pinskia at gcc dot gnu.org
@ 2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
  2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
To fix the ICE we could do:

--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4644,7 +4644,9 @@ static tree
 finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
 {
   idx = maybe_constant_value (idx);
-  if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
+  if (TREE_CODE (idx) != INTEGER_CST
+      || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
+      || !tree_fits_shwi_p (idx))
     {
       if (complain & tf_error)
    error ("%<__type_pack_element%> index is not an integral constant");

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (4 preceding siblings ...)
  2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
  2024-02-09 13:37 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (5 preceding siblings ...)
  2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:37 ` jakub at gcc dot gnu.org
  2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-09 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #5)
> To fix the ICE we could do:
> 
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -4644,7 +4644,9 @@ static tree
>  finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
>  {
>    idx = maybe_constant_value (idx);
> -  if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
> +  if (TREE_CODE (idx) != INTEGER_CST
> +      || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
> +      || !tree_fits_shwi_p (idx))
>      {
>        if (complain & tf_error)
>     error ("%<__type_pack_element%> index is not an integral constant");

But then the diagnostics is confusing.

Perhaps use tree_int_cst_sgn (idx) < 0 instead of tree_to_shwi + val < 0,
wi::to_widest (idx) >= TREE_VEC_LENGTH (types) for out of range and
only use tree_to_shwi after those checks?

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (6 preceding siblings ...)
  2024-02-09 13:37 ` jakub at gcc dot gnu.org
@ 2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
  2024-02-09 13:53 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #6)
> (In reply to Marek Polacek from comment #5)
> > To fix the ICE we could do:
> > 
> > --- a/gcc/cp/semantics.cc
> > +++ b/gcc/cp/semantics.cc
> > @@ -4644,7 +4644,9 @@ static tree
> >  finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
> >  {
> >    idx = maybe_constant_value (idx);
> > -  if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
> > +  if (TREE_CODE (idx) != INTEGER_CST
> > +      || !INTEGRAL_TYPE_P (TREE_TYPE (idx))
> > +      || !tree_fits_shwi_p (idx))
> >      {
> >        if (complain & tf_error)
> >     error ("%<__type_pack_element%> index is not an integral constant");
> 
> But then the diagnostics is confusing.

There's a lot of places where we do exactly that:
handle_assume_aligned_attribute, ...

> Perhaps use tree_int_cst_sgn (idx) < 0 instead of tree_to_shwi + val < 0,
> wi::to_widest (idx) >= TREE_VEC_LENGTH (types) for out of range and
> only use tree_to_shwi after those checks?

That sounds good too though, I can do that instead.

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (7 preceding siblings ...)
  2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
@ 2024-02-09 13:53 ` jakub at gcc dot gnu.org
  2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
  2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-09 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #7)
> > But then the diagnostics is confusing.
> 
> There's a lot of places where we do exactly that:
> handle_assume_aligned_attribute, ...

Sure, I know.  In some cases it is from assumption that one uses reasonable
types and values for say alignments or sizes etc., in other cases laziness,
diagnose something and if it in the corner cases diagnoses something slightly
different, user can figure it out.

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (8 preceding siblings ...)
  2024-02-09 13:53 ` jakub at gcc dot gnu.org
@ 2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
  2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-09 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 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:f29f7f86935e29786bf9f976ec99d7639b381b14

commit r14-8904-gf29f7f86935e29786bf9f976ec99d7639b381b14
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Feb 9 12:03:50 2024 -0500

    c++: fix ICE with __type_pack_element [PR113834]

    Here we crash on this invalid code because we seem to infinitely recurse
    and end up with __type_pack_element with index that doesn't
tree_fits_shwi_p
    which then crashes on tree_to_shwi.

    Thanks to Jakub for suggesting a nicer fix than my original one.

            PR c++/113834

    gcc/cp/ChangeLog:

            * semantics.cc (finish_type_pack_element): Perform range checking
            before tree_to_shwi.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/type_pack_element4.C: New test.

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

* [Bug c++/113834] [14 Regression] internal compiler error: in tree_to_shwi, at tree.cc:6461
  2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
                   ` (9 preceding siblings ...)
  2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
@ 2024-02-09 21:42 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 14.

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

end of thread, other threads:[~2024-02-09 21:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 16:46 [Bug c++/113834] New: internal compiler error: in tree_to_shwi, at tree.cc:6461 ivan.lazaric.gcc at gmail dot com
2024-02-08 16:48 ` [Bug c++/113834] " ivan.lazaric.gcc at gmail dot com
2024-02-09  0:15 ` pinskia at gcc dot gnu.org
2024-02-09  2:49 ` pinskia at gcc dot gnu.org
2024-02-09  7:02 ` [Bug c++/113834] [14 Regression] " pinskia at gcc dot gnu.org
2024-02-09 13:28 ` mpolacek at gcc dot gnu.org
2024-02-09 13:34 ` mpolacek at gcc dot gnu.org
2024-02-09 13:37 ` jakub at gcc dot gnu.org
2024-02-09 13:48 ` mpolacek at gcc dot gnu.org
2024-02-09 13:53 ` jakub at gcc dot gnu.org
2024-02-09 21:41 ` cvs-commit at gcc dot gnu.org
2024-02-09 21:42 ` 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).